1

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)

lostInTransit
  • 70,519
  • 61
  • 198
  • 274
  • @lostInTransit, this is out-of-context: you might want to associate your SO account with SU, SF and maybe Meta through the `accounts` tab at far-right on your user page. Your latest question was moved to SU. – nik Aug 08 '09 at 09:15
  • nik, I don't understand how this belongs to SU. This is related to the properties we need to set for AVAudioRecorder when recording sound through the SDK. Thanks a lot for moving the last question to SU. – lostInTransit Aug 08 '09 at 14:28
  • Uh. I am sorry, by out-of-context, i meant your last question about get-my-id-address. it was moved to SU. – nik Aug 08 '09 at 16:02

2 Answers2

9

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.

Ian1971
  • 3,666
  • 7
  • 33
  • 61
grassyburrito
  • 1,213
  • 22
  • 32
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.

Massimo Cafaro
  • 25,429
  • 15
  • 79
  • 93
  • 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 Jul 18 '09 at 06:46
  • 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! – Massimo Cafaro Jul 18 '09 at 08:40
  • 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 Jul 18 '09 at 15:19