提问人:Kakhi Kiknadze 提问时间:6/12/2023 更新时间:6/12/2023 访问量:25
创建支持多声道的 AUv3 音频单元
Create AUv3 audio unit supporting multiple channels
问:
假设我有 N 个通道(在当前示例中是 4 个),我想将其连接到我的自定义 AUv3 音频单元,在那里我可以操作它们,我该如何实现?AVAudioInputNode
我试过了
例如,在我的 AUv3 扩展中硬编码通道格式,以采用 4 个通道,从而在实例化单元时导致错误。4097
- (void)setupAudioBuses {
// Create the output bus first
AVAudioFormat *format = [[AVAudioFormat alloc] initStandardFormatWithSampleRate:44100 channels:4];
_outputBus = [[AUAudioUnitBus alloc] initWithFormat:format error:nil];
_outputBus.maximumChannelCount = UINT_MAX;
// Create the input and output busses.
_inputBus.init(format, UINT_MAX);
// Create the input and output bus arrays.
_inputBusArray = [[AUAudioUnitBusArray alloc] initWithAudioUnit:self
busType:AUAudioUnitBusTypeInput
busses: @[_inputBus.bus]];
// then an array with it
_outputBusArray = [[AUAudioUnitBusArray alloc] initWithAudioUnit:self
busType:AUAudioUnitBusTypeOutput
busses: @[_outputBus]];
}
我也尝试过这样设置格式,但遇到了同样的错误。
AudioStreamBasicDescription asbd;
memset(&asbd, 0, sizeof(asbd));
asbd.mSampleRate = 44100.0; // Sample rate
asbd.mFormatID = kAudioFormatLinearPCM; // Linear PCM format
asbd.mFormatFlags = kAudioFormatFlagsNativeFloatPacked; // Canonical format flags
asbd.mChannelsPerFrame = 4; // Number of channels
asbd.mBitsPerChannel = 32; // Number of bits per channel
asbd.mBytesPerFrame = (asbd.mBitsPerChannel / 8) * asbd.mChannelsPerFrame;
asbd.mFramesPerPacket = 1;
asbd.mBytesPerPacket = asbd.mBytesPerFrame * asbd.mFramesPerPacket;
// Create an AVAudioFormat using the ASBD
AVAudioFormat *format = [[AVAudioFormat alloc] initWithStreamDescription:&asbd];
如果我将它保留为 2 通道格式并像这样连接到它,它会抛出 .inputNode
error -10875
failed call": "err = AUGraphParser::InitializeActiveNodesInInputChain(ThisGraph, *GetInputNode())
engine.connect(inputNode, to: myAU, fromBus: 0, format: inputNode.outputFormat(forBus: 0))
engine.connect(myAU, to: mixerNode, format: myAU.outputFormat(forBus: 0)
如果我这样做,它不会抛出错误,但在这种情况下,它只将前 2 个通道连接到我的 AU
engine.connect(inputNode, to: myAU, fromBus: 0, format: myAY.inputFormat(forBus: 0))
engine.connect(myAU, to: mixerNode, format: myAU.outputFormat(forBus: 0)
另外,还有一点需要注意的是,如果我将输入节点与(4 通道)连接到它不会崩溃inputNode.outputFormat(forBus: 0
mainMixer
engine.start()
我真的需要能够在我的音频单元中接收任意数量的通道:(甚至可能吗?
答: 暂无答案
评论