音频单元 RemoteIO 设置交错浮点数 kAudioUnitErr_FormatNotSupported

Audio Unit RemoteIO Setting interleaved float gives kAudioUnitErr_FormatNotSupported

我正在使用音频单元 RemoteIO 来获得低延迟音频输出。我的问题是 AFAIK 音频单元仅接受多种音频格式,具体取决于硬件。我的问题是我有一个 C++ DSP 声音引擎,它适用于浮动交错 PCM。我不想实现格式转换器,因为它会减慢远程 IO 回调的速度。我尝试获取具有以下格式的低延迟音频单元:

AudioStreamBasicDescription const audioDescription = {
            .mSampleRate        = defaultSampleRate,
            .mFormatID          = kAudioFormatLinearPCM,
            .mFormatFlags       = kAudioFormatFlagIsFloat,
            .mBytesPerPacket    = defaultSampleRate * STEREO_CHANNEL,
            .mFramesPerPacket   = 1,
            .mBytesPerFrame     = STEREO_CHANNEL * sizeof(Float32),
            .mChannelsPerFrame  = STEREO_CHANNEL,
            .mBitsPerChannel    = 8 * sizeof(Float32),
            .mReserved          = 0
        };
        
        status = AudioUnitSetProperty(audioUnit,
                                          kAudioUnitProperty_StreamFormat,
                                          kAudioUnitScope_Input,
                                          kOutputBus,
                                          &audioDescription,
                                          sizeof(audioDescription));

此操作失败,错误代码为 kAudioUnitErr_FormatNotSupported -10868。如果我尝试使用以下内容获取浮动 PCM 非交错音频流:

AudioStreamBasicDescription const audioDescription = {
            .mSampleRate        = defaultSampleRate,
            .mFormatID          = kAudioFormatLinearPCM,
            .mFormatFlags       = kAudioFormatFlagIsFloat | kAudioFormatFlagIsPacked | kAudioFormatFlagIsNonInterleaved,
            .mBytesPerPacket    = sizeof(float),
            .mFramesPerPacket   = 1,
            .mBytesPerFrame     = sizeof(float),
            .mChannelsPerFrame  = STEREO_CHANNEL,
            .mBitsPerChannel    = 8 * sizeof(float),
            .mReserved          = 0
        };
        
        status = AudioUnitSetProperty(audioUnit,
                                          kAudioUnitProperty_StreamFormat,
                                          kAudioUnitScope_Input,
                                          kOutputBus,
                                          &audioDescription,
                                          sizeof(audioDescription));

一切正常。但是,我想为我的 DSP 引擎获取一个交错的音频流,以便在不进行格式转换的情况下工作。这可能吗?

PS。等待 hotpaw2 指导我:)

您的错误可能是由于这一行:

.mBytesPerPacket    = defaultSampleRate * STEREO_CHANNEL,