如何在ios中使用AudioQueue编码/解码speex

Rai*_*ang 6 iphone codec speex audioqueue ios

如果有人有一些使用AudioQueue编码/解码speex音频格式的经验?

我试图通过编辑SpeakHere示例来实现它.但不成功!

从Apple API文档中,AudioQueue可以支持编解码器,但我找不到任何样本.有人能给我一些建议吗?我已经在XCode 4的项目中成功编译了speex编解码器.

cha*_*rse 0

在苹果示例代码“SpeakHere”中,您可以执行以下操作:

AudioQueueNewInput(
                                     &mRecordFormat,
                                     MyInputBufferHandler,
                                     this /* userData */,
                                     NULL /* run loop */,
                                     NULL /* run loop mode */,
                                     0 /* flags */, &mQueue)
Run Code Online (Sandbox Code Playgroud)

你可以在函数“MyInputBufferHandler”中做一些事情,比如

[self encoder:(short *)buffer->mAudioData count:buffer->mAudioDataByteSize/sizeof(short)];
Run Code Online (Sandbox Code Playgroud)

编码器功能如下:

while ( count >= samplesPerFrame )
    {
        speex_bits_reset( &bits );

        speex_encode_int( enc_state, samples, &bits ); 

        static const unsigned maxSize = 256;
        char data[maxSize];
        unsigned size = (unsigned)speex_bits_write( &bits, data, maxSize );
        /*
                    do some thing... for example :send to server
        */

        samples += samplesPerFrame;
        count -= samplesPerFrame;
    }
Run Code Online (Sandbox Code Playgroud)

这是大体的想法。当然事实是很难,但是你可以看看一些开源的VOIP,也许可以帮助你。祝你好运。