【问题标题】:Does AVAudioFormat initStandardFormatWithSampleRate return incorrect stream description?AVAudioFormat initStandardFormatWithSampleRate 是否返回不正确的流描述?
【发布时间】:2014-12-18 17:54:25
【问题描述】:

尝试使用 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 字段不应该有区别吗?还是我错过了什么?

【问题讨论】:

    标签: macos core-audio osx-yosemite extaudiofile


    【解决方案1】:

    我想我发现了我的错误:

    使用ExtAudioFileCreateWithURL 编写 PCM 文件需要对kExtAudioFileProperty_FileDataFormat 进行交错。由于 AVAudioFormat 的 -initStandardFormatWithSampleRate:channelLayout: 返回 Core Audio 的标准 deinterleaved 32 位浮点格式,我收到 'fmt?' 错误。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-17
      • 2021-10-09
      • 1970-01-01
      • 2013-04-01
      • 1970-01-01
      • 2023-03-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多