-->

iphone - AVAudioRecorder gives mono playback (soun

2019-06-05 06:13发布

问题:

I am using AVAudioRecorder to record audio and save to a wav file (using SDK 3.0) The settings dictionary contains the following values

    NSMutableDictionary *recordSetting = [[NSMutableDictionary alloc] init];

    [recordSetting setValue :[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];
    [recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; 
    [recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];

    [recordSetting setValue :[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
    [recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
    [recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];

Even after specifying the number of channels as 2, the playback is mono (i.e. playing in only 1 ear jack instead of both the channels).

Has anyone else faced this issue? Is there anything wrong with the recordSetting dictionary values?

Thanks

Can anyone please help me with this... If I specify the number of channels as 2, why would the playback be in just one jack? (I am using headphones for testing - the ones which came with my iPhone)

回答1:

No, nothing is wrong in your settings. If you try your app on the simulator it will record and play on two channels. However, iPhone 3G and 3GS only record audio using one channel. This apply also to the audio of movies shot on 3GS.

Therefore, it is not a bug.



回答2:

Just comment out the following line

[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];

The default setting should work.

The reason this works is that you will now be recording a mono file and when this is played back the audio will be played in each speaker as is the normal behaviour for a mono file. If you include this line you end up recording a stereo file with one channel completely silent so that when you play it back you only get audio in one ear.