Tuesday, May 8, 2012

take the Sound File and create a new sentence from those words.

//Sound File preamble.wav and create a new sentence from those words.
 //The sentence you are to create is:
//We order the common people to perfect liberty.
 //The entire text of the Preamble is:
 //We the People of the United States, in Order to form a more perfect Union, establish Justice, insure
//domestic Tranquility, provide for the common defence, promote the general Welfare, and secure the
//Blessings of Liberty to ourselves and our Posterity, do ordain and establish this Constitution for the United
 //States of America.
http://www.cs.uic.edu/~i101/SoundFiles/preamble.wav




public class Lab14Babuze2
{

public static void main (String args[])
{
System.out.println("Begin Java Execution");
System.out.println("");


// put your Java Program here
String filename = FileChooser.pickAFile();
Sound s1 = new Sound (filename);

Sound s2 = crop (s1, 0, 15730);
Sound s3 = crop (s1, 55845, 65043);
Sound s4 = crop (s1, 15730, 17407);
Sound s5 = crop (s1, 189873, 193815);
Sound s6 = crop (s1, 17407, 26726);
Sound s7 = crop (s1, 63729, 66357);
Sound s8 = crop (s1, 77526, 85410);
Sound s9 = crop (s1, 270027,276597);


// crop the sounds
Sound s10 = join (s2, s3);
Sound s11 = join (s10, s4);
Sound s12 = join (s11, s5);
Sound s13 = join (s12, s6);
Sound s14 = join (s13, s7);
Sound s15 = join (s14, s8);
Sound s16 = join (s15, s9);



// Play the sounds using the "play command"
//s.play();

//esplore the sound in order to get the values
s16.explore();

System.out.println("");
System.out.println("End Java Execution");
}

// Start a method
public static Sound crop (Sound s1, int startIndex, int endIndex)
{
SoundSample[] ssarr1 = s1.getSamples();

// set length3 to the length of the shorter sound
int length3 = endIndex - startIndex ;
Sound s3 = new Sound (length3);
SoundSample[] ssarr3 = s3.getSamples();

int pos;

// copy over s1 into the beginning of s3
for ( pos = startIndex ; pos < endIndex ; pos++ )
{
int amplitude1 = ssarr1[pos].getValue();

// store the new amplitude value into sounnd s3
ssarr3[ pos - startIndex ].setValue (amplitude1);
}

return s3;
}


public static Sound join (Sound s1, Sound s2)
{
SoundSample[] ssarr1 = s1.getSamples();
SoundSample[] ssarr2 = s2.getSamples();

// set length3 to the length of the shorter sound
int length3 = ssarr1.length + ssarr2.length ;
Sound s3 = new Sound (length3);
SoundSample[] ssarr3 = s3.getSamples();

int pos;

// copy over s1 into the beginning of s3
for ( pos = 0 ; pos < ssarr1.length ; pos++ )
{
int amplitude1 = ssarr1[pos].getValue();

// store the new amplitude value into sounnd s3
ssarr3[pos].setValue (amplitude1);
}

// copy over s2 into the end of s3
for ( pos = 0 ; pos < ssarr2.length ; pos++ )
{
int amplitude2 = ssarr2[pos].getValue();

// store the new amplitude value into sounnd s3
ssarr3[ ssarr1.length + pos ].setValue (amplitude2);
}

return s3;
}

} // end of Template class

No comments:

Post a Comment