gpt4 book ai didi

c++ - 核心音频指定要解码的音轨

转载 作者:行者123 更新时间:2023-12-03 02:28:21 25 4
gpt4 key购买 nike

我能够使用Core Audio API成功获取音频文件的解码PCM数据。下面是简化后的代码,显示了如何执行此操作:

CFStringRef urlStr = CFStringCreateWithCString(kCFAllocatorDefault, "file.m4a", kCFStringEncodingUTF8);
CFURLRef urlRef = CFURLCreateWithFileSystemPath(NULL, urlStr, kCFURLPOSIXPathStyle, false);

ExtAudioFileOpenURL(urlRef, &m_audioFile);

bzero(&m_outputFormat, sizeof(AudioStreamBasicDescription));
m_outputFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked;
m_outputFormat.mSampleRate = m_inputFormat.mSampleRate;
m_outputFormat.mFormatID = kAudioFormatLinearPCM;
m_outputFormat.mChannelsPerFrame = m_inputFormat.mChannelsPerFrame;
m_outputFormat.mBytesPerFrame = sizeof(short) * m_outputFormat.mChannelsPerFrame;
m_outputFormat.mBitsPerChannel = sizeof(short) * 8;
m_outputFormat.mFramesPerPacket = 1;
m_outputFormat.mBytesPerPacket = m_outputFormat.mBytesPerFrame * m_outputFormat.mFramesPerPacket;


ExtAudioFileSetProperty(m_audioFile, kExtAudioFileProperty_ClientDataFormat, sizeof(m_outputFormat), &m_outputFormat)

short* transformData = new short[sampleCount];

AudioBufferList fillBufList;
fillBufList.mNumberBuffers = 1;
fillBufList.mBuffers[0].mNumberChannels = channels;
fillBufList.mBuffers[0].mDataByteSize = m_sampleCount * sizeof(short);
fillBufList.mBuffers[0].mData = (void*)(&transformData[0]);

ExtAudioFileRead(m_audioFile, &m_frameCount, &fillBufList);

我对 感兴趣,如何指定我要解码的音轨(假设媒体文件包含多个)?

最佳答案

一种方法是解码所有轨道,然后将所需的轨道数据(隔行立体声的每个其他样本等)提取(复制)到另一个缓冲区,阵列或文件中。与解码时间相比,额外的复制时间微不足道。

关于c++ - 核心音频指定要解码的音轨,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47717072/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com