如何简单地播放CMSampleBufferRef音频数据?

时间:2014-04-23 15:34:20

标签: ios audio avcapturesession openal objectal

我在AVCaptureSession内捕捉音频,现在我即将播放。

我真的没有进入低级音频处理,所以ObjectAL似乎是一个公平的选择,所以我尝试获取缓冲区指针,一些格式信息,然后创建一个ObjectAL缓冲区。

 -(void)captureOutput:(AVCaptureOutput*) captureOutput
didOutputSampleBuffer:(CMSampleBufferRef) sampleBuffer
       fromConnection:(AVCaptureConnection*) connection
{
    if ([captureOutput isKindOfClass:[AVCaptureAudioDataOutput class]])
    {

        // Get samples.
        CMBlockBufferRef audioBuffer = CMSampleBufferGetDataBuffer(sampleBuffer);
        size_t lengthAtOffset;
        size_t totalLength;
        char *samples;
        CMBlockBufferGetDataPointer(audioBuffer, 0, &lengthAtOffset, &totalLength, &samples);

        // Get format.
        CMAudioFormatDescriptionRef format = CMSampleBufferGetFormatDescription(sampleBuffer);
        const AudioStreamBasicDescription *description = CMAudioFormatDescriptionGetStreamBasicDescription(format);

        ALBuffer *openALbuffer = [ALBuffer bufferWithName:@"buffer just captured before"
                                                     data:sampleBuffer
                                                     size:totalLength
                                                   format:description->mFormatID
                                                frequency:description->mSampleRate];
    }
}

它说Invalid Value

OAL Error: +[ALWrapper bufferDataStatic:format:data:size:frequency:]: Invalid Value (error code 0x0000a003)

ObjectAL实际上挂钩了一些我没有进入的OpenAL内容,你可能会更好地理解它: ALBuffer.m ALWrapper.m

是否有任何格式/缓冲区对话我必须在创建此类ObjectAL(OpenAL)缓冲区之前使用它?

0 个答案:

没有答案