• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Dynamic Sound on iOS

Guest
Apr 27, 2014 Apr 27, 2014

Copy link to clipboard

Copied

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



}


}
TOPICS
Development

Views

454

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 27, 2014 Apr 27, 2014

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 27, 2014 Apr 27, 2014

Copy link to clipboard

Copied

Hi,

Thanks for the advice.

I'm setting it to 44 already.

Ido.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 27, 2014 Apr 27, 2014

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 27, 2014 Apr 27, 2014

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 06, 2014 Aug 06, 2014

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines