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++; | ||||
} | ||||
} |