3

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

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

    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

谢谢。

4

2 回答 2

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);
于 2013-05-25T20:58:04.520 回答
0

规范格式是非交错的,所以每个缓冲区只有一个通道,所以.mBytesPerPacket应该.mBytesPerFramesizeof(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));
}
于 2013-02-25T21:18:13.033 回答