简体   繁体   中英

Audio Recording iPhone - values of AudioStreamBasicDescription

These are the values I pass in, it's the only combination of values I have got working.

dataFormat.mSampleRate = 44100;    
dataFormat.mFormatID = kAudioFormatLinearPCM;
dataFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsBigEndian;
dataFormat.mBytesPerPacket = 4;
dataFormat.mFramesPerPacket = 1;
dataFormat.mBytesPerFrame = 4;
dataFormat.mChannelsPerFrame = 2;
dataFormat.mBitsPerChannel = 16;

status = AudioQueueNewInput(  &dataFormat, AudioInputCallback, self, NULL, NULL,  0,  
                   &queue);

status = AudioFileCreateWithURL(fileUrl, kAudioFileCAFType, &dataformat, kAudioFileFlags_EraseFile, &audioFile

The recording works, but it is a lot of noise during the recording, and on the playback. Can it have anything to do with this code?

I can see two possible errors. First, as @invalidname pointed out, recording in stereo probably isn't going to work on a mono device such as the iPhone. Well, it might work, but if it does, you're just going to get back dual-mono stereo streams anyways, so why bother? You might as well configure your stream to work in mono and spare yourself the CPU overhead.

The second problem is probably the source of your sound distortion. Your stream description format flags should be:

kAudioFormatFlagIsSignedInteger |
kAudioFormatFlagsNativeEndian |
kAudioFormatFlagIsPacked

Also, don't forget to set the mReserved flag to 0. While the value of this flag is probably being ignored, it doesn't hurt to explicitly set it to 0 just to make sure.

Edit : Another more general tip for debugging audio on the iPhone -- if you are getting distortion, clipping, or other weird effects, grab the data payload from your phone and look at the recording in a wave editor. Being able to zoom down and look at the individual samples will give you a lot of clues about what's going wrong.

To do this, you need to open up the "Organizer" window, click on your phone, and then expand the little arrow next to your application (in the same place where you would normally uninstall it). Now you will see a little downward pointing arrow, and if you click it, Xcode will copy the data payload from your app to somewhere on your hard drive. If you are dumping your recordings to disk, you'll find the files extracted here.

What's your input device? The mic on the provided earbuds or the phone's built-in mic or what? Or are you recording into the Simulator?

Aside from the noise, does everything else sound right: speed, pitch, etc.?

It probably isn't causing any problems, but you're specifying two-channel input, while your input device is probably mono.

One last thought: is this a first generation iPhone? I think there's a weird issue with that model where 8 KHz input gets upconverted to 44.1.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM