当前位置:  开发笔记 > IOS > 正文

单击应用程序间音频录制期间

如何解决《单击应用程序间音频录制期间》经验,为你挑选了1个好方法。

我一直试图在iOS 9上的应用程序间音频会话期间录制我的输入.扬声器输出听起来很好,但录制的文件有节奏的咔嗒声.波形如下所示......

在此输入图像描述

我已经调整了我能想到的每个设置和参数,似乎没有任何工作.

以下是格式设置(流设置相同)...

    AudioStreamBasicDescription fileFormat;
fileFormat.mSampleRate          = kSessionSampleRate;
fileFormat.mFormatID            = kAudioFormatLinearPCM;
fileFormat.mFormatFlags         = kAudioFormatFlagsNativeFloatPacked;
fileFormat.mFramesPerPacket     = 1;
fileFormat.mChannelsPerFrame    = 1;
fileFormat.mBitsPerChannel      = 32;       //tone is correct but there is still pops
fileFormat.mBytesPerPacket      = sizeof(Float32);
fileFormat.mBytesPerFrame       = sizeof(Float32);

这是流设置......

        //connect instrument to output
AudioComponentDescription componentDescription = unit.componentDescription;
AudioComponent inputComponent = AudioComponentFindNext(NULL, &componentDescription);
OSStatus status = AudioComponentInstanceNew(inputComponent, &_instrumentUnit);
NSLog(@"%d",status);
AudioUnitElement instrumentOutputBus = 0;
AudioUnitElement ioUnitInputElement = 0;

    //connect instrument unit to remoteIO output's input bus
AudioUnitConnection connection;
connection.sourceAudioUnit = _instrumentUnit;
connection.sourceOutputNumber = instrumentOutputBus;
connection.destInputNumber = ioUnitInputElement;
status = AudioUnitSetProperty(_ioUnit,
                              kAudioUnitProperty_MakeConnection,
                              kAudioUnitScope_Output,
                              ioUnitInputElement,
                              &connection,
                              sizeof(connection));
NSLog(@"%d",status);
UInt32 maxFrames = 1024; //I tried setting this to 4096 but it did not help
status = AudioUnitSetProperty(_instrumentUnit,
                                kAudioUnitProperty_MaximumFramesPerSlice,
                                kAudioUnitScope_Output,
                                0,
                                &maxFrames,
                                sizeof(maxFrames));
NSLog(@"%d",status);



_connectedInstrument = YES;
_instrumentIconImageView.image = unit.icon;
NSLog(@"Remote Instrument connected");
status = AudioUnitInitialize(_ioUnit);
NSLog(@"%d",status);
status = AudioOutputUnitStart(_ioUnit);
NSLog(@"%d",status);
status = AudioUnitInitialize(_instrumentUnit);
NSLog(@"%d",status);
[self setupFile];

这是我的回调......

static OSStatus recordingCallback(void                              *inRefCon,
                                 AudioUnitRenderActionFlags         *ioActionFlags,
                                 const AudioTimeStamp               *inTimeStamp,
                                 UInt32                             inBusNumber,
                                 UInt32                             inNumberFrames,
                                 AudioBufferList                    *ioData)
{
    ViewController* This = This = (__bridge ViewController *)inRefCon;
    if (inBusNumber == 0 && !(*ioActionFlags & kAudioUnitRenderAction_PostRenderError))
    {
            ExtAudioFileWriteAsync(This->fileRef, inNumberFrames, ioData);
    }

    return noErr;
}

这里是全视图控制器代码

谢谢你的帮助.



1> dave234..:

您正在写入文件前后渲染.在渲染回调中,将if语句更改为仅在后渲染上写入.

if (inBusNumber == 0 && *ioActionFlags == kAudioUnitRenderAction_PostRender){
    ExtAudioFileWriteAsync(This->fileRef, inNumberFrames, ioData);
} 

ExtAudioFileWriteAsync执行一些内部复制和缓冲,因此只要在第一次写入之前填充它就可以在渲染回调中使用它.

推荐阅读
mobiledu2402851377
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有