本文介绍了音频单元代码中的错误-iPhone的remoteIO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此代码,以便读取缓冲区样本,但出现奇怪的mach-o链接器错误,无法加载音频单元的框架,因此我在阅读时放了audioTollBox和coreAudio.我的代码是:

i have this code, in order to read buffer samples , but i get a strange mach-o linker error ,Framework of audio unit couldnt loaded so i put the audioTollBox and coreAudio as i read.my code is :

#define kOutputBus 0
#define kInputBus 1
AudioComponentInstance audioUnit;



@implementation remoteIO


//callback function :

    static OSStatus recordingCallback(void *inRefCon,
                                      AudioUnitRenderActionFlags *ioActionFlags,
                                      const AudioTimeStamp *inTimeStamp,
                                      UInt32 inBusNumber,
                                      UInt32 inNumberFrames,
                                      AudioBufferList *ioData)
    {
        AudioBuffer buffer;

        buffer.mNumberChannels = 1;
        buffer.mDataByteSize = inNumberFrames * 2;
        NSLog(@"%ld",inNumberFrames);
        buffer.mData = malloc( inNumberFrames * 2 );


        AudioBufferList bufferList;
        bufferList.mNumberBuffers = 1;
        bufferList.mBuffers[0] = buffer;



        OSStatus status;
        status = AudioUnitRender(audioUnit,
                                 ioActionFlags,
                                 inTimeStamp,
                                 inBusNumber,
                                 inNumberFrames,
                                 &bufferList);
        checkStatus(status);                       //here is the warnning+error
        double *q = (double *)(&bufferList)->mBuffers[0].mData;
        for(int i=0; i < strlen((const char *)(&bufferList)->mBuffers[0].mData); i++)
        {

            NSLog(@"%f",q[i]);
        }
    }

和阅读方法:

-(void)startListeningWithFrequency:(float)freq;
{
    OSStatus status;

    AudioComponentDescription desc;
    desc.componentType = kAudioUnitType_Output;
    desc.componentSubType = kAudioUnitSubType_RemoteIO;
    desc.componentFlags = 0;
    desc.componentFlagsMask = 0;
    desc.componentManufacturer = kAudioUnitManufacturer_Apple;

    AudioComponent inputComponent = AudioComponentFindNext(NULL, &desc);
    status = AudioComponentInstanceNew( inputComponent, &audioUnit);
    checkStatus(status);

    UInt32 flag = 1;
    status = AudioUnitSetProperty(audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input,kInputBus, &flag, sizeof(flag));
    checkStatus(status);

    AudioStreamBasicDescription audioFormat;
    audioFormat.mSampleRate         = 44100.00;//44100.00;
    audioFormat.mFormatID           = kAudioFormatLinearPCM;
    audioFormat.mFormatFlags        = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
    audioFormat.mFramesPerPacket    = 1;
    audioFormat.mChannelsPerFrame   = 1;
    audioFormat.mBitsPerChannel     = 16;
    audioFormat.mBytesPerPacket     = 2;
    audioFormat.mBytesPerFrame      = 2;

    status = AudioUnitSetProperty(audioUnit,
                                  kAudioUnitProperty_StreamFormat,
                                  kAudioUnitScope_Output,
                                  kInputBus,
                                  &audioFormat,
                                  sizeof(audioFormat));
    checkStatus(status);

    checkStatus(status);
    AURenderCallbackStruct callbackStruct;
    callbackStruct.inputProc = recordingCallback;
    callbackStruct.inputProcRefCon = self;
    status = AudioUnitSetProperty(audioUnit,
                                  kAudioOutputUnitProperty_SetInputCallback,
                                  kAudioUnitScope_Global,
                                  kInputBus, &callbackStruct, sizeof(callbackStruct));
    checkStatus(status);

    status = AudioOutputUnitStart(audioUnit);

}

,我得到的是此错误并发出警告:

Undefined symbols for architecture i386:
  "_checkStatus", referenced from:
      _recordingCallback in remoteIO.o
      -[remoteIO startListeningWithFrequency:] in remoteIO.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status

这是怎么了?谢谢.

推荐答案

您必须编写自己的checkStatus()函数,以及它的功能(例如,它如何报告错误:对话框,控制台输出,分析日志记录,崩溃转储等),或者除了从音频代码返回以外,是否仅针对每个应用进行

You have to write your own checkStatus() function, as what it does (e.g. how it reports an error: dialog box, console output, analytics logging, crash dump, etc.), or whether is does anything at all other than return from the audio code, is specific to each app.

这篇关于音频单元代码中的错误-iPhone的remoteIO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 17:09