c++ - 是否有适用于 iOS 的高级音频队列记录服务库?

标签 c++ objective-c ios xcode macos

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

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

因为我不太擅长处理扩展名“.mm”,

使用开源将是更好的选择。

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

理想的方式就像委托(delegate):

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

Overvier

  1. Identify the audio component (kAudioUnitType_Output/ kAudioUnitSubType_RemoteIO/ kAudioUnitManufacturerApple)
  2. Use AudioComponentFindNext(NULL, &descriptionOfAudioComponent) to obtain the AudioComponent, which is like the factory with which you obtain the audio unit
  3. Use AudioComponentInstanceNew(ourComponent, &audioUnit) to make an instance of the audio unit
  4. Enable IO for recording and possibly playback with AudioUnitSetProperty
  5. Describe the audio format in an AudioStreamBasicDescription structure, and apply the format using AudioUnitSetProperty
  6. Provide a callback for recording, and possibly playback, again using AudioUnitSetProperty
  7. Allocate some buffers
  8. Initialise the audio unit
  9. Start the audio unit
  10. Rejoice
// 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;
}

最佳答案

这里是如何从录音中获取音频缓冲区的方法

(引用自: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;
}

关于c++ - 是否有适用于 iOS 的高级音频队列记录服务库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13428305/

相关文章:

c++ - 精神语法解析问题

ios - UITableViewController loadView 加载了 nib 但没有得到 UITableView。

ios - 为什么我们总是必须在 HitTest 中使用集合的第一个元素,而不是最后一个?

ios - 如何使用 ffmpeg 命令在视频中添加节拍和低音效果?

ios - 当用户在 UIActivityViewController 上点击 "More"时如何设置导航栏颜色?

c++ - g++ 不包括它所说的为 C++11 包含的文件?

c++ - 用于 cout 顺序的 OpenMP 并行

c++ - 在 windows 中构建 boost 的子集

ios - Core Graphics 栅格数据未从内存中释放

iphone - AVPlayerLayer 在 View 中不可见