Skip to main content
Apr 27, 2014 3:22 PM UTC
Question

Dynamic Sound on iOS

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 is closed to new replies. Start a new post to keep the conversation going.

5 replies

Colin Holgate
Inspiring
Apr 27, 2014 6:07 PM UTC

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.

Translate
Apr 27, 2014 6:09 PM UTC

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

Translate
Participant
Aug 6, 2014 6:49 PM UTC

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.

Translate
Colin Holgate
Inspiring
Apr 27, 2014 5:42 PM UTC

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

Translate
Apr 27, 2014 6:04 PM UTC

Hi,

Thanks for the advice.

I'm setting it to 44 already.

Ido.

Translate