Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 25th, 2012  |  syntax: None  |  size: 3.35 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public static void main (String args[])
  2.         {
  3.                 // Prompting the user for a sound file
  4.                                
  5.                                 System.out.println("Please select the Preamble sound");
  6.                                
  7.                                 String filename = FileChooser.pickAFile();
  8.                                 Sound s = new Sound (filename);
  9.                                
  10.                                 // We
  11.                                
  12.                                 Sound s5;
  13.                                 s5 = cropSound (s, 0, 15768);
  14.                                
  15.                                 // Order
  16.                                
  17.                                 Sound s6;
  18.                                 s6 = cropSound (s, 59130, 63729);
  19.                                
  20.                                 // The
  21.                                
  22.                                 Sound s7;
  23.                                 s7 = cropSound (s, 15730, 17407);
  24.                                
  25.                                 // Common
  26.                                
  27.                                 Sound s8;
  28.                                 s8 = cropSound (s, 189873, 195129);
  29.                                
  30.                                 // People
  31.                                
  32.                                 Sound s9;
  33.                                 s9 = cropSound (s, 17407, 26726);
  34.                                
  35.                                 // to
  36.                                
  37.                                 Sound s10;
  38.                             s10 = cropSound (s, 63729, 66357);
  39.                            
  40.                             // perfect
  41.                            
  42.                             Sound s11;
  43.                             s11 = cropSound (s, 80811, 87381);
  44.                            
  45.                             // liberty
  46.                            
  47.                             Sound s12;
  48.                             s12 = cropSound (s, 268056, 278568);
  49.                            
  50.                             // Using my joinSounds method to join the two initial words
  51.                             // cropped out from the file. Then, joining the new sound with
  52.                             // the next-in-line cropped out word to keep adding to the
  53.                             // sound file that the user would eventually save. This
  54.                             // results in the final sound file having all the words requested
  55.                             // by the lab assignment.
  56.                            
  57.                             Sound s2 = joinSounds (s5, s6);
  58.                             Sound s3 = joinSounds (s2, s7);
  59.                             Sound alpha = joinSounds (s3, s8);
  60.                             Sound beta = joinSounds (alpha, s9);
  61.                             Sound gamma = joinSounds (beta, s10);
  62.                             Sound omega = joinSounds (gamma, s11);
  63.                             Sound ultima = joinSounds (omega, s12);
  64.                                
  65.                             // Pardon the strange naming for the sound names.
  66.                             // Didn't want to confuse myself with random numbers.
  67.                             // Exploring ultima, since it's the last "joined" sound
  68.                             // that houses all the requested words.
  69.                            
  70.                                 s.explore();
  71.                                
  72.         }                      
  73.                                
  74.        
  75.         // Method Standard affair. Use a few arrays and variables
  76.         // in a loop to modify a new sound of length equal to the length
  77.         // of the two arrays. The loop "joins" the sounds that are
  78.         // passed as arguments and returns the sound file s3 which has
  79.         // length "length"
  80.        
  81.         public static Sound joinSounds (Sound s, Sound s2)
  82.         {
  83.                 SoundSample[] ssarr1 = s.getSamples();
  84.                 SoundSample[] ssarr2 = s2.getSamples();
  85.                
  86.                 int length = ssarr1.length + ssarr2.length;
  87.                
  88.                 Sound s3 = new Sound (length);
  89.                
  90.                 SoundSample[] ssarr3 = s3.getSamples();
  91.                
  92.                 int pos;
  93.                
  94.                 for (pos = 0; pos < ssarr1.length ; pos++)
  95.                 {
  96.                         int amplitude1 = ssarr1[pos].getValue();
  97.                        
  98.                 ssarr3[pos].setValue (amplitude1);
  99.                 }
  100.                
  101.                 for (pos = 0; pos < ssarr2.length; pos++)
  102.                 {
  103.                         int amplitude2 = ssarr2[pos].getValue();
  104.                        
  105.                         ssarr3[ssarr1.length+pos].setValue(amplitude2);
  106.                 }
  107.                
  108.                 return s3;
  109.         }
  110.        
  111.  
  112.         // Cropping out parts that I want by passing the sound, the
  113.         // first index and the last index and then cutting out the
  114.         // portion at those values.
  115.        
  116.         public static Sound cropSound (Sound s, int startIndex, int endIndex)
  117.         {
  118.                 SoundSample[] ssarr1 = s.getSamples();
  119.                
  120.                 int length2 = endIndex - startIndex;
  121.                 Sound s3 = new Sound (length2);
  122.                 SoundSample[] ssarr3 = s3.getSamples();
  123.                
  124.                 int pos;
  125.                
  126.                 for (pos = startIndex; pos < endIndex; pos++)
  127.                 {
  128.                         int amplitude1 = ssarr1[pos].getValue();
  129.                        
  130.                         ssarr3[pos - startIndex].setValue(amplitude1);
  131.                 }
  132.                
  133.                 return s3;
  134.         }
  135.        
  136.        
  137. }