Skip to main content
April 27, 2014
Question

Dynamic Sound on iOS

  • April 27, 2014
  • 2 replies
  • 491 views

I'm trying to record a sound using the Microphone API and store the mono stream of samples to a file.

Later I'll open the file and play it using dynamic sound API but creating Sound object and regster to SampleEvent and filling the buffer from the recorded samples.

As far as I know the microphone give me mono samples and the output expect stereo so I write each sample twice.

The problem is that on the AIR simulator and Android devices everything works great but on iOS device the sound plays twice as fast.

This is the onSample function:



private function onSampleData(event : SampleDataEvent):void


{




// the following lines of code are modifying the sound object and creates a "pitch" effect



var sample:Number;




var outputLength:int = 0;



while (outputLength < 2048) {




// until we have filled up enough output buffer




if (_micSamplesStream.bytesAvailable < 4)




{





break;




}





// read out the left and right channels at this position




sample = _micSamplesStream.readFloat();





// write the samples to our output buffer




event.data.writeFloat(sample);




event.data.writeFloat(sample);





outputLength++;



}


}
This topic has been closed for replies.

2 replies

Colin Holgate
Inspiring
April 27, 2014

One thing, you don’t need to write the data twice. Write it once, then on playback use a single readfloat to write both the left and right channels of the playback sound.

April 27, 2014

Sure, that code I did past here, I read one value from the microphone persisted stream and write it twice to the output buffer.

Participant
August 6, 2014

If this is still a problem, be sure to make sure that you've granted the app microphone permissions, which started being required in iOS 7. Otherwise, recorded audio will sound like a "chipmunk" voice when played back.

Colin Holgate
Inspiring
April 27, 2014

Check what the default microphone rate is on iOS. You could set it to 44, and that might help.

April 27, 2014

Hi,

Thanks for the advice.

I'm setting it to 44 already.

Ido.