枚举AudioBuffer的样本?

时间:2014-04-24 22:33:33

标签: ios audio signal-processing audiotoolbox

我有一个来自AudioBuffer AVCaptureSession的{​​{1}},例如:

CMSampleBuffer

如何正确投射/枚举样本? (做一些处理) 我应该使用上述配置投射Sample Rate: 44100 Format ID: lpcm Format Flags: C Bytes per Packet: 2 Frames per Packet: 1 Bytes per Frame: 2 Channels per Frame: 1 Bits per Channel: 16 kAudioFormatFlagIsSignedInteger kAudioFormatFlagIsPacked kLinearPCMFormatFlagIsSignedInteger kLinearPCMFormatFlagIsPacked kLinearPCMFormatFlagsSampleFractionShift kAppleLosslessFormatFlag_32BitSourceData 哪种类型?

我是否正确解析格式标记?上面的输出是https://gist.github.com/eppz/11272305

1 个答案:

答案 0 :(得分:0)

一旦我解析了上面的标志,kAudioFormatFlagIsSignedInteger似乎就是答案,每个通道有16位。

到目前为止,它就像:

// Enumerate audio buffers (probably faceing a sole buffer handling mono PCM anyway).
for (int audioBufferIndex = 0; audioBufferIndex <= audioBufferList.mNumberBuffers; audioBufferIndex++)
{
    AudioBuffer eachAudioBuffer = audioBufferList.mBuffers[audioBufferIndex];

    // Enumerate samples.
    SInt16 *samples;
    samples = (SInt16*)eachAudioBuffer.mData;
    for (int sampleIndex = 0; sampleIndex <= sampleCount; sampleIndex++)
    {
        SInt16 eachSample = samples[sampleIndex];
        printf("%i \n", eachSample);
    }
}