2011-08-02 23 views
6

誰かがAudioQueueでspeexオーディオフォーマットをエンコード/デコードする経験がある方は?AudioQueue with iosでエンコード/デコードする方法

SpeakHereサンプルを編集して実装しようとしました。しかし、成功はありません!

AudioQueueはApple APIドキュメントからコーデックをサポートできますが、サンプルが見つかりません。誰も私にいくつかの提案を与えることができますか?私はすでにあなたがこのようないくつかのことを行うことができますリンゴのサンプル・コード「SpeakHere」にはXCode 4で私のプロジェクトで成功し

答えて

0

をSpeexコーデックをコンパイル:

AudioQueueNewInput(
            &mRecordFormat, 
            MyInputBufferHandler, 
            this /* userData */, 
            NULL /* run loop */, 
            NULL /* run loop mode */, 
            0 /* flags */, &mQueue) 

あなたが関数内でいくつかのことを行うことができます「MyInputBufferHandlerを」以下のような

[self encoder:(short *)buffer->mAudioData count:buffer->mAudioDataByteSize/sizeof(short)]; 

のようなエンコーダ機能:

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; 
    } 

これは一般的なアイデアです。もちろん、事実は難しいですが、あなたはVOIPのオープンソースを見ることができます。おそらくあなたを助けることができます。 幸運。

0

FFMPEGですべてのことを達成し、それをAudioQueueでPCMとして再生できます。 FFMPEGライブラリの 建物はそれほど無痛ではなく、全体のデコード/エンコード処理は難しいことではありません:)

FFMPEG official site SPEEX official site

あなたはLIBSをダウンロードし、それらを自分で構築する必要がありますし、その後必要になりますそれらをFFMPEGに組み込んでビルドする必要があります。

+0

あなたが与えたこと。私はspeex用にFFMPEGをコンパイルしました。このリンクhttp://stackoverflow.com/questions/22935787/compiling-ffmpeg-to-support-speex-decodingを参照してください。 – user2955351

0

以下はspeex を使用してオーディオキューとエンコード(ワイドバンド)を使用してオーディオをキャプチャするコードです。オーディオの品質を向上させるために、別のスレッドでデータをエンコードすることができます。私はすべての提案を試してみました

オーディオフォーマット

mSampleRate = 16000; 
    mFormatID = kAudioFormatLinearPCM; 
    mFramesPerPacket = 1; 
    mChannelsPerFrame = 1; 
    mBytesPerFrame = 2; 
    mBytesPerPacket = 2; 
    mBitsPerChannel = 16; 
    mReserved = 0; 
    mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked; 

キャプチャコールバック

void CAudioCapturer::AudioInputCallback(void *inUserData, 
          AudioQueueRef inAQ, 
          AudioQueueBufferRef inBuffer, 
          const AudioTimeStamp *inStartTime, 
          UInt32 inNumberPacketDescriptions, 
          const AudioStreamPacketDescription *inPacketDescs) 
    { 
    CAudioCapturer *This = (CMacAudioCapturer *)inUserData; 

int len = 640; 
char data[640]; 
char *pSrc = (char *)inBuffer->mAudioData; 

while (len <= inBuffer->mAudioDataByteSize) 
{ 
    memcpy(data,pSrc,640); 
    int enclen = encode(buffer,encBuffer); 
    len=len+640; 

    pSrc+=640; // 640 is the frame size for WB in speex (320 short) 
} 

AudioQueueEnqueueBuffer(This->m_audioQueue, inBuffer, 0, NULL); 
    } 

のSpeexエンコーダ

int encode(char *buffer,char *pDest) 
    { 
int nbBytes=0; 
speex_bits_reset(&encbits); 

speex_encode_int(encstate, (short*)(buffer) , &encbits); 

nbBytes = speex_bits_write(&encbits, pDest ,640/(sizeof(short))); 

return nbBytes; 
    } 
+0

情報ありがとうございます。あなたは、640がSpeex(320 short)のフレームサイズであると言います。 "320 short"はどういう意味ですか? shortは2バイト長ですから、320ペアのバイトがありますか? – csotiriou

関連する問題