适用于iOS的高级音频队列记录服务库吗?

时间:2012-11-17 06:29:36

标签: c++ objective-c ios xcode macos

我正在尝试开发一个关于VOIP的应用程序,

是否有适用于iOS的高级音频队列服务库?

因为我不擅长处理扩展文件名" .mm",

使用开源是一个更好的选择。

或有人可以给我一些关于如何从AudioQueueBufferRef获取缓冲区的提示?

理想的方式就像代表一样:

- (void)audioRecorderDidReceivedBuffer:(Buffer) {
    do something for other operations
}

  

Overvier

     
      
  1. 识别音频组件(kAudioUnitType_Output / kAudioUnitSubType_RemoteIO / kAudioUnitManufacturerApple)
  2.   
  3. 使用AudioComponentFindNext(NULL,& descriptionOfAudioComponent)获取AudioComponent,就像您与之工厂一样   获取音频单元
  4.   
  5. 使用AudioComponentInstanceNew(ourComponent,& audioUnit)制作音频单元的实例
  6.   
  7. 启用IO进行录制,并可能使用AudioUnitSetProperty
  8. 进行播放   
  9. 描述AudioStreamBasicDescription结构中的音频格式,并使用AudioUnitSetProperty
  10. 应用格式   
  11. 使用AudioUnitSetProperty
  12. 再次提供录制和可能播放的回调   
  13. 分配一些缓冲区
  14.   
  15. 初始化音频设备
  16.   
  17. 启动音频设备
  18.   
  19. 飘柔
  20.   
// Enable IO for recording
UInt32 flag = 1;
status = AudioUnitSetProperty(audioUnit, 
                              kAudioOutputUnitProperty_EnableIO, 
                              kAudioUnitScope_Input, 
                              kInputBus,
                              &flag, 
                              sizeof(flag));



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



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

// TODO: Use inRefCon to access our interface object to do stuff
// Then, use inNumberFrames to figure out how much data is available, and make
// that much space available in buffers in an AudioBufferList.

AudioBufferList *bufferList; // <- Fill this up with buffers (you will want to malloc it, as it's a dynamic-length list)

// Then:
// Obtain recorded samples

OSStatus status;

status = AudioUnitRender([audioInterface audioUnit], 
                         ioActionFlags, 
                         inTimeStamp, 
                         inBusNumber, 
                         inNumberFrames, 
                         bufferList);
checkStatus(status);

// Now, we have the samples we just read sitting in buffers in bufferList
DoStuffWithTheRecordedAudio(bufferList);
return noErr;
}

1 个答案:

答案 0 :(得分:1)

以下是如何从录制中获取音频缓冲区的方法

(参考:http://atastypixel.com/blog/using-remoteio-audio-unit/

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

    // TODO: Use inRefCon to access our interface object to do stuff
    // Then, use inNumberFrames to figure out how much data is available, and make
    // that much space available in buffers in an AudioBufferList.

    AudioBufferList *bufferList; // <- Fill this up with buffers (you will want to malloc it, as it's a dynamic-length list)

    // Then:
    // Obtain recorded samples

    OSStatus status;

    status = AudioUnitRender([audioInterface audioUnit], 
                             ioActionFlags, 
                             inTimeStamp, 
                             inBusNumber, 
                             inNumberFrames, 
                             bufferList);
    checkStatus(status);

    // Now, we have the samples we just read sitting in buffers in bufferList
    DoStuffWithTheRecordedAudio(bufferList);
    return noErr;
}