0 Replies Latest reply on Apr 19, 2011 7:13 AM by Lady Lilly

    Draw an audio waveform from recorded sound

    Lady Lilly

      I have problem with draw static waveform from recorded sound. Here is an example of which I wanted to use: http://cookbooks.adobe.com/post_Draw_an_audio_waveform_from_an_MP3_file-16767.html

       

      Here is an excerpt of my code, where the recorded sound, and I play it:

       

          public function startRecording():void
                  {
                      stop.enabled=true;
                      soundClip = new ByteArray();
                      microphone = Microphone.getMicrophone();
                      microphone.rate = 44;
                      microphone.gain = 100;
                      microphone.addEventListener(SampleDataEvent.SAMPLE_DATA, microphone_sampleDataHandler);              
                  }
                 
                  public function stopRecording():void
                  {
                      play.enabled=true;
                      microphone.removeEventListener(SampleDataEvent.SAMPLE_DATA, microphone_sampleDataHandler);
                      level.width = microphone.activityLevel * 0;
                      level.height = microphone.activityLevel * 0;
                     
                  }
                 
                  protected function microphone_sampleDataHandler(event:SampleDataEvent):void
                  {
                      level.width = microphone.activityLevel * 1;
                      level.height = microphone.activityLevel * 1;
                     
                      while (event.data.bytesAvailable)
                      {
                          var sample:Number = event.data.readFloat();
                          soundClip.writeFloat(sample);
                         
                         
                      }
                  }
                  public function startPlaying(soundClip:ByteArray):void
                  {
                      this.soundClip = soundClip;
                      soundClip.position = 0;
                                      sound = new Sound();
                      sound.addEventListener(SampleDataEvent.SAMPLE_DATA, sound_sampleDataHandler);
                     
                      channel = sound.play();
                    
                  protected function sound_sampleDataHandler(event:SampleDataEvent):void
                  {
                      if (!soundClip.bytesAvailable > 0)
                      {
                          return;
                      }
                     
                      for (var i:int = 0; i < 8192; i++)
                      {
                          var sample:Number = 0;
                          if (soundClip.bytesAvailable > 0)
                          {
                              sample = soundClip.readFloat();
                             
                          }
                          event.data.writeFloat(sample);
                          event.data.writeFloat(sample); 
             
                      }
                     
                  }

       

       

      Is there any other way than to save the recorded sound as mp3 (which will also be complicated), or can I use this example given and work on ByteArray? I tried to redo it a little, I'm sitting on this already a lot of time and unfortunately to no avail. Any ideas? Tips?

       

      I would like to compare the recorded sound with the original. Draw waveform will be the first step. Maybe you also have some tips of how to compare the two sounds?

       

      I would be very grateful for every answer,


      Lilly