0

尝试使用 ExtAudioFileCreateWithURL 编写 PCM 音频文件时,我得到一个“fmt?” 使用 2 声道音频格式时出错(Mac OS X,SDK 10.10)

我创建音频格式

[[AVAudioFormat alloc] initStandardFormatWithSampleRate:sampleRate channels:channelCount]

并在我的应用程序中将其用作 AUGraph 的音频格式。

AUGraph 适用于 1ch 和 2ch 格式,但是当尝试使用 ExtAudioFileCreateWithURL 编写音频文件时,它只适用于 1ch,2ch 结果为“fmt?” 错误。

运行以下测试时...

AVAudioFormat* ch1 = [[AVAudioFormat alloc] initStandardFormatWithSampleRate:44100. channels:1];
AVAudioFormat* ch2 = [[AVAudioFormat alloc] initStandardFormatWithSampleRate:44100. channels:2];
NSLog(@"ch1: %@", [ch1 description]);
NSLog(@"ch1 mBitsPerChannel: %d", ch1.streamDescription->mBitsPerChannel);
NSLog(@"ch1 mChannelsPerFrame: %d", ch1.streamDescription->mChannelsPerFrame);
NSLog(@"ch1 mBytesPerFrame: %d", ch1.streamDescription->mBytesPerFrame);
NSLog(@"ch1 mBytesPerPacket: %d", ch1.streamDescription->mBytesPerPacket);
NSLog(@"ch1 mFramesPerPacket: %d", ch1.streamDescription->mFramesPerPacket);
NSLog(@"ch2: %@", [ch2 description]);
NSLog(@"ch2 mBitsPerChannel: %d", ch2.streamDescription->mBitsPerChannel);
NSLog(@"ch2 mChannelsPerFrame: %d", ch2.streamDescription->mChannelsPerFrame);
NSLog(@"ch2 mBytesPerFrame: %d", ch2.streamDescription->mBytesPerFrame);
NSLog(@"ch2 mBytesPerPacket: %d", ch2.streamDescription->mBytesPerPacket);
NSLog(@"ch2 mFramesPerPacket: %d", ch2.streamDescription->mFramesPerPacket);

...这是控制台中的输出:

ch1: <AVAudioFormat 0x600000084560:  1 ch,  44100 Hz, Float32>
ch1 mBitsPerChannel: 32
ch1 mChannelsPerFrame: 1
ch1 mBytesPerFrame: 4
ch1 mBytesPerPacket: 4
ch1 mFramesPerPacket: 1
ch2: <AVAudioFormat 0x6000000845b0:  2 ch,  44100 Hz, Float32, non-inter>
ch2 mBitsPerChannel: 32
ch2 mChannelsPerFrame: 2
ch2 mBytesPerFrame: 4
ch2 mBytesPerPacket: 4
ch2 mFramesPerPacket: 1

mBytesPerFrame 和 mBytesPerPacket 字段不应该有区别吗?还是我在这里错过了什么?

4

1 回答 1

0

我想我发现了我的错误:

写入 PCM 文件ExtAudioFileCreateWithURL需要kExtAudioFileProperty_FileDataFormat交错。由于 AVAudioFormat -initStandardFormatWithSampleRate:channelLayout:返回 Core Audio 的标准去交错32 位浮点格式,我得到了 'fmt?' 错误。

顺便说一句,将标准格式更改为交错,结果 mBytesPerFrame 和 mBytesPerPacket 的值为 8,当然......

于 2014-12-19T00:12:13.170 回答