1 Reply Latest reply on Jul 19, 2011 5:18 AM by Rob_2006

    audio editing in air

    Rob_2006 Level 1

      Hi there,

       

      I would like to create an audio recorder app that allows the user to edit a recorded sound. I managed to record and playback audio. The thing that is missing is the functionality to playback the sound from a certain position.

      mySound.play(myPosition) does not work since I'm playing back the sound from a byte Array as shown below:

       

       

      soundOutput = new Sound();

      soundOutput.addEventListener(SampleDataEvent.SAMPLE_DATA, playSound);

      _soundChannel = soundOutput.play(0);

       

       

      private function playSound(sampleEvent:SampleDataEvent):void

      {

      if (!soundRecording.bytesAvailable > 0)

      {

      return;

      }

       

      for (var i:int = 0; i < 8192; i++)

      {

      var sample:Number = 0;

      if (soundRecording.bytesAvailable > 0)

      {

      sample = soundRecording.readFloat();

      }

       

      sampleEvent.data.writeFloat(sample);

      sampleEvent.data.writeFloat(sample);

      }

      }

       

       

      Any ides how I can playback the audio from a specific position?

       

       

      My knowledge of audio is rather limited so all help is greatly appreciated.

       

      Cheers

       

      Robin

        • 1. Re: audio editing in air
          Rob_2006 Level 1

          I figured it out myself. The trick is to set the position in the recorded byte array correctly:

          var _phase= (startTime*44100/2)/1000;

           

          _soundChannel = soundOutput.play(startTime);

           

           

          // and then in sample data event handler:

          for (var i:int = 0; i < 8192; i++)

          {

          soundRecording.position = int(_phase) * 8

           

          ...