error in audio Unit code -remoteIO for iphone

核能气质少年 提交于 2019-12-18 09:48:01

问题


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]); 
        }
    }

and the reading method :

-(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);

}

and what i get is this error and warnning :

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

whats wrong here, ? thanks.


回答1:


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.



来源:https://stackoverflow.com/questions/8699895/error-in-audio-unit-code-remoteio-for-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!