views:

1339

answers:

6

Hi

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  A: 

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.

unforgiven
Recording on one channel is ok. but when playing back, shouldn't it be played back on 2 channels? Even voice memo plays back audio in 2 channels.
lostInTransit
You will want to distinguish between sound played through the iPhone's bottom loudspeakers and through the headphones. On both the 3G and 3GS model, sound is played on only one channel through the loudspeakers (both for voice memo and iPod apps). You can try covering with your fingers the left loudspeaker: you will see that no sound is played through the right one. However, when you connect the headphones, you will listen the voice memos and the audio you recorded through both the left and right channels, even though it's not a real stereo sound, it's the same channel on the headphones!
unforgiven
I'm not so sure. I tried what you're saying but I can still hear the audio from just one jack for my recorded sound. For the voice memo, I can hear it from both the headphone jacks
lostInTransit
A: 

I am also having the same problem. Recording in stereo, but playback in mono.

BUT voice memos playback in stereo. Any ideas how to record/playback in stereo ?

+3  A: 

Just comment out the following line

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

The default setting should work.

Prabhu Beeman
Director - Projects
Broov Information Services Pvt Ltd

Prabhu Beeman
A: 

Did anyone find a solution to this? I understand that the iPhone can only record in money but would it not makes sense that it splits the mono to both channels on playback? Is there anyway to force mono recordings to both channels? My app sounds fine when using the built-in speaker but sounds broken when using headphones, all the rest of the non-recorded audio plays back fine.

( i pretty well have the same code as above, i have tried commenting out the line suggested but it does not make any difference )

StuBCN75
You will either have to play back the file using AVAudioPlayer (correctly renders the audio in stereo) or write a single channel's data to both channels programatically. There's no other alternative. Since I wanted to write data to a file, ended up doing the latter.
lostInTransit
A: 

The solution that Prabhu Beeman posted works. I was having the same problem, and simply omitting setting the number of channels solves the troubles :) Thanks!

A: 

The solution offered by Prabhu works well. I was confused on this problem. Now i can hear stereo playback of the recorded audio in ipad 3.2 . Thanks a lot buddy. :)

apostleofzion