3 methods needs doing;
wave1: This static method takes an AudioInputStrea m and gradually lowers and then raises the volume so that the new AudioInputStrea m appears to be constantly alerting in volume.
wave2: This static method takes an AudioInputStrea m and alters it so that it seems to move from left to right. The resultant new audio stream is then returned.
down: This static method takes a 16 bit AudioInputStrea m and returns an AudiInputStream converted to an 8 bit AudioInputStrea m.
=============== =============== ======
import javax.sound.sam pled.*;
import java.io.*;
public class AudioManipulati on {
/**
* Creating an echo.
* Out of a given AudioInputSteam a new one is created with an additional echo effect.
*
* @param ais the original sound
* @param delay the delay of the echo in mili seconds.
* @param fading the strength of the echo
*/
public static AudioInputStrea m echo(AudioInput Stream ais, int delay, double fading) {
byte[] a=null;
int[] data;
int max;
try{
delay=(int) (delay*ais.getF ormat().getFram eSize()*
ais.getFormat() .getFrameRate()/1000);
// reset the AudioInputStrea m
ais.reset();
// create a byte array of the right size
a=new byte[(int) ais.getFrameLen gth() *
ais.getFormat() .getFrameSize()];
// fill the byte array with the data of the AudioInputStrea m
ais.read(a);
// Create an integer array of the right size
data=new int[a.length/2];
// fill the integer array by combining two bytes of the
// byteArray to one integer
for (int i=0;i<data.leng th;++i) {
data[i]=a[2*i]*256+a[2*i+1];
}
// Adding a faded copy of the signal to the later measurements
for (int i=0; i<data.length-delay;++i) {
data[i+delay] += (int) (data[i]*fading);
}
// get the maxium amplitute
max=0;
for (int i=0;i<data.leng th;++i) {
max=Math.max(ma x,Math.abs(data[i]));
}
// scale the maximum amplitude down to 256*128
if (max > 256*128)
for (int i=0; i<data.length;+ +i) {
data[i] = (int) (data[i]*(256.0*256.0/2-1)/max);
}
// convert the integer array to a byte array
for (int i=0;i<data.leng th;++i) {
a[2*i]=(byte) (Math.round(dat a[i]/256.0));
a[2*i+1]=(byte) (data[i]-(a[2*i]*256));
}
} catch(Exception e){
System.out.prin tln("Something went wrong");
e.printStackTra ce();
}
// create a new AudioInputStrea m out of the the byteArray
// and return it.
return new AudioInputStrea m(new ByteArrayInputS tream(a),
ais.getFormat() ,ais.getFrameLe ngth());
}
/**
* Creates a wave pattern out of a given sound.
* A new AudioInputStrea m is created with an additional wave effect.
* In the new sound the volume goes up and down in fixes intervals.
* If i is the length of the interval, then the amplitude of a sound
* at position x will be modified by a factor
* abs( 2 * ((x % i) / i -0.5))
*
* @param ais the original sound
* @param interval the length of the interval
*/
public static AudioInputStrea m wave1(AudioInpu tStream ais, int interval) {
// add your code here and change the return statement
return ais;
}
/**
* Creates a wave pattern out of a given sound.
* A new AudioInputStrea m is created with an additional wave effect.
* In the new sound the volume of the two channels goes up and down,
* which creates the effect that sound moves from the left to right
* and back.
* If i is the length of the interval, then the amplitude for the left channel
* at position x will be modified by a factor
* abs(2*((x % i) / i-0.5))
* and for the right channel
* abs(2*(((x+i/2) % i)/ i -0.5))
*
* @param ais the original sound
* @param interval the length of the interval
*/
public static AudioInputStrea m wave2(AudioInpu tStream ais,
int interval) {
// add your code here and change the return statement
return ais;
}
/**
* Convert a given sound from 16 bit to 8bit.
* A new AudioInputStrea m is created representing the originial sound in 8 bit.
*
* @param ais the original sound
*/
public static AudioInputStrea m down(AudioInput Stream ais) {
// add your code here and change the return statement
return ais;
}
}