- public static void main (String args[])
- {
- // Prompting the user for a sound file
- System.out.println("Please select the Preamble sound");
- String filename = FileChooser.pickAFile();
- Sound s = new Sound (filename);
- // We
- Sound s5;
- s5 = cropSound (s, 0, 15768);
- // Order
- Sound s6;
- s6 = cropSound (s, 59130, 63729);
- // The
- Sound s7;
- s7 = cropSound (s, 15730, 17407);
- // Common
- Sound s8;
- s8 = cropSound (s, 189873, 195129);
- // People
- Sound s9;
- s9 = cropSound (s, 17407, 26726);
- // to
- Sound s10;
- s10 = cropSound (s, 63729, 66357);
- // perfect
- Sound s11;
- s11 = cropSound (s, 80811, 87381);
- // liberty
- Sound s12;
- s12 = cropSound (s, 268056, 278568);
- // Using my joinSounds method to join the two initial words
- // cropped out from the file. Then, joining the new sound with
- // the next-in-line cropped out word to keep adding to the
- // sound file that the user would eventually save. This
- // results in the final sound file having all the words requested
- // by the lab assignment.
- Sound s2 = joinSounds (s5, s6);
- Sound s3 = joinSounds (s2, s7);
- Sound alpha = joinSounds (s3, s8);
- Sound beta = joinSounds (alpha, s9);
- Sound gamma = joinSounds (beta, s10);
- Sound omega = joinSounds (gamma, s11);
- Sound ultima = joinSounds (omega, s12);
- // Pardon the strange naming for the sound names.
- // Didn't want to confuse myself with random numbers.
- // Exploring ultima, since it's the last "joined" sound
- // that houses all the requested words.
- s.explore();
- }
- // Method Standard affair. Use a few arrays and variables
- // in a loop to modify a new sound of length equal to the length
- // of the two arrays. The loop "joins" the sounds that are
- // passed as arguments and returns the sound file s3 which has
- // length "length"
- public static Sound joinSounds (Sound s, Sound s2)
- {
- SoundSample[] ssarr1 = s.getSamples();
- SoundSample[] ssarr2 = s2.getSamples();
- int length = ssarr1.length + ssarr2.length;
- Sound s3 = new Sound (length);
- SoundSample[] ssarr3 = s3.getSamples();
- int pos;
- for (pos = 0; pos < ssarr1.length ; pos++)
- {
- int amplitude1 = ssarr1[pos].getValue();
- ssarr3[pos].setValue (amplitude1);
- }
- for (pos = 0; pos < ssarr2.length; pos++)
- {
- int amplitude2 = ssarr2[pos].getValue();
- ssarr3[ssarr1.length+pos].setValue(amplitude2);
- }
- return s3;
- }
- // Cropping out parts that I want by passing the sound, the
- // first index and the last index and then cutting out the
- // portion at those values.
- public static Sound cropSound (Sound s, int startIndex, int endIndex)
- {
- SoundSample[] ssarr1 = s.getSamples();
- int length2 = endIndex - startIndex;
- Sound s3 = new Sound (length2);
- SoundSample[] ssarr3 = s3.getSamples();
- int pos;
- for (pos = startIndex; pos < endIndex; pos++)
- {
- int amplitude1 = ssarr1[pos].getValue();
- ssarr3[pos - startIndex].setValue(amplitude1);
- }
- return s3;
- }
- }