录音iPhone-AudioStreamBasicDescription的值 [英] Audio Recording iPhone - values of AudioStreamBasicDescription

查看:85
本文介绍了录音iPhone-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?

推荐答案

我可以看到两个可能的错误.首先,正如@invalidname指出的那样,立体声录音可能无法在iPhone等单声道设备上正常工作.好吧,它可能会起作用,但是如果可以,那么无论如何您都将获得双单声道立体声流,那么为什么要打扰呢?您最好将流配置为以单声道工作并节省CPU开销.

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

此外,别忘了将mReserved标志设置为0.虽然可能会忽略该标志的值,但只是为了确保将其显式设置为0也无济于事.

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.

编辑:在iPhone上调试音频的另一个更通用的技巧-如果您收到失真,剪切或其他怪异的效果,请从手机中抓取数据负载,然后查看其中的录音波浪编辑器.能够缩小并查看单个样本将为您提供很多出问题的线索.

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.

为此,您需要打开整理器"窗口,单击手机,然后展开应用程序旁边的小箭头(在通常将其卸载的位置).现在,您将看到一个向下的箭头,如果单击它,Xcode会将数据有效负载从您的应用程序复制到硬盘驱动器上的某个位置.如果要将录音转储到磁盘,则会在此处找到提取的文件.

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.

这篇关于录音iPhone-AudioStreamBasicDescription的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆