osx音频单元多通道输出

时间:2013-02-25 20:48:14

标签: macos core-audio openframeworks

我已经在网上搜索了几个月没有运气的答案。

我有一个maudio profire 610多声道音频接口。 如何正确设置AudioStreamBasicDescription以使用所有8个输出通道? 目前它只适用于前两个频道。

    UInt32 busCount = 3; //numberOfOutputBusses;
AudioStreamBasicDescription outputASBD2 = {
    .mSampleRate       = 44100,
    .mFormatID         = kAudioFormatLinearPCM,
    .mFormatFlags      = kAudioFormatFlagsAudioUnitCanonical, 
    .mChannelsPerFrame = busCount,
    .mFramesPerPacket  = 1,
    .mBitsPerChannel   = sizeof(Float32) * 8,
    .mBytesPerPacket   = sizeof(Float32) * busCount,
    .mBytesPerFrame    = sizeof(Float32) * busCount
};

AudioUnitSetProperty(*_unit,
                                    kAudioUnitProperty_StreamFormat,
                                    kAudioUnitScope_Output,
                                    1,
                                    &outputASBD2,
                                    sizeof(AudioStreamBasicDescription);

我正在为openframeworks开发ofxaudiounit插件: https://github.com/antimodular/ofxAudioUnit

感谢。

2 个答案:

答案 0 :(得分:1)

     UInt32 propertySize;
  Boolean writable = false;
  OSStatus status = AudioUnitGetPropertyInfo(*_unit,
                                             kAudioOutputUnitProperty_ChannelMap,
                                             kAudioUnitScope_Output,
                                             0,
                                             &propertySize, &writable);
  //SignalIf_(writable == false);
  cout<<"writable "<<&writable<<endl;

  long nChannels = propertySize / sizeof(SInt32);
  long* channelMapPtr = (long*)malloc(propertySize);

  cout<<"nChannels "<<nChannels<<endl;

  UInt32 scratch = propertySize;
  status = AudioUnitGetProperty(*_unit,
                                  kAudioOutputUnitProperty_ChannelMap,
                                  kAudioUnitScope_Output,
                                  0,
                                  channelMapPtr,
                                  &scratch);

  //  channelMapPtr[0] = 0;
  for (long i = 0; i < nChannels; i++)
  {
      channelMapPtr[i] = -1;
  }

 channelMapPtr[3] = 0;
 channelMapPtr[5] = 1;

  OFXAU_RET_BOOL(AudioUnitSetProperty(*_unit,
                                        kAudioOutputUnitProperty_ChannelMap,
                                        kAudioUnitScope_Output,
                                        0,
                                        channelMapPtr,
                                        scratch),"setting output unit's device ID");

  free((void *)channelMapPtr);

答案 1 :(得分:0)

规范格式是非交织的,因此每个缓冲区只有一个频道,因此.mBytesPerPacket.mBytesPerFrame应为sizeof(Float32)。然后,您需要创建多个(busCount)缓冲区以通过类似

的方式传递到AudioUnit
AudioBufferList *bufferList = (AudioBufferList*)malloc(sizeof(AudioBufferList) + (sizeof(AudioBuffer) * (busCount - 1)));
bufferList->mNumberBuffers = busCount;
for ( int i=0; i < bufferList->mNumberBuffers; i++ ) {
    bufferList->mBuffers[i].mNumberChannels = 1;
    bufferList->mBuffers[i].mDataByteSize = BUFFER_SIZE * sizeof(float);
    bufferList->mBuffers[i].mData = malloc(BUFFER_SIZE * sizeof(float));
}