如何从CMAudioFormatDescription获取音频通道布局字符串?

时间:2014-06-05 20:57:41

标签: avfoundation core-audio

我需要在QT电影中获取音轨的频道布局。我已经阅读了CMAudioFormatDescription

    "<CMAudioFormatDescription 0x60800011fad0 [0x7fff77314f00]> {
mediaType:'soun'
mediaSubType:'lpcm' 
mediaSpecific: {
ASBD: {mSampleRate: 48000.000000 
mFormatID: 'lpcm' 
mFormatFlags: 0xc 
mBytesPerPacket: 6 
mFramesPerPacket: 1 
mBytesPerFrame: 6 
mChannelsPerFrame: 2 
mBitsPerChannel: 24 } 
cookie: {(null)} 
ACL: {Stereo (L R)} 
} 
extensions: {<CFBasicHash 0x608000668080 [0x7fff77314f00]>{type = immutable dict, count = 1,\nentries =>\n\t1 : <CFString 0x7fff760e2340 [0x7fff77314f00]>{contents = \"VerbatimSampleDescription\"} = <CFData 0x608000365940 [0x7fff77314f00]>{length = 114, capacity = 114, bytes = 0x00000072696e32340000000000000001 ... 0000000000000000}\n}\n}\n}"

但是我无法解决如何提取&#34; Stereo(L R)&#34;这个字符串。我看到有一个CMAudioFormatDescriptionGetChannelLayout,它包含一个AudioChannelLayoutTag,在这种情况下是kAudioChannelLayoutTag_Stereo,但是&#34; Stereo(L R)&#34;字符串来自?

不幸的是,由于某些原因我不能让它工作:

size_t layoutSize = 0;
const AudioChannelLayout *layout = CMAudioFormatDescriptionGetChannelLayout(audioTrackRef, &layoutSize);

NSString *layoutName = nil;
UInt32 layoutNameSize = sizeof(layoutName);
OSStatus err = AudioFormatGetProperty(kAudioFormatProperty_ChannelLayoutSimpleName, sizeof(layout), &layout, &layoutNameSize, &layoutName);

layoutName仍为零,即使我能看到&#34; Stereo(L R)&#34;当我打印audioTrackRef

1 个答案:

答案 0 :(得分:1)

您可以将kAudioFormatProperty_ChannelLayoutNamekAudioFormatProperty_ChannelLayoutSimpleName属性与AudioFormatGetProperty一起使用,以获取您之后的内容:

CFStringRef layoutName = nullptr;
UInt32 propertySize = sizeof(layoutName);
OSStatus result = AudioFormatGetProperty(kAudioFormatProperty_ChannelLayoutName, /* size of your channel layout */, /* your channel layout */, &propertySize, &layoutName);

// later
CFRelease(layoutName);