1

私はオーディオを録音してGSMに圧縮するC++プログラムに取り組んでいます。音声を録音し、生データをファイルに書き込むことができます。しかし、GSM圧縮を機能させることができません。このウェブサイトftp://ftp.cs.cmu.edu/project/fgdata/speech-compression/GSM/gsm_13200bpsで見つけた圧縮用のソースコードを使用しようとしています。

私の問題はgsm_encode()関数を使用するときだと思います。このファイルを再生するときに圧縮データをエンコードしてファイルに保存した後は、聞こえなくなります。生のオーディオデータは正しいのですが、圧縮されたオーディオデータは正しくありません。

gsm_encode()は、160個の13ビットサンプルの配列(gsm_signalとして指定され、少なくとも16ビットの符号付き積分値)を33バイトのgsm_frameにエンコードします。

これが私の関数です。データをgsm_encode()に誤って送信していますか?または、私の機能に別の問題がありますか?ご協力ありがとうございました :)

int CAudioGSM::CompressAudio(unsigned char * pRawBuffer, _int32 uiRawBufferSize, unsigned char  * pCompressedBuffer, _int32 uiCompressedBufferSize)
{
// Note: uiRawBufferSize must be a multiple of 640 (AUDIO_DMA_DESCRITOR_LEN)
if(!pRawBuffer || uiRawBufferSize == 0 || !pCompressedBuffer || uiCompressedBufferSize == 0 ||  uiRawBufferSize % AUDIO_DMA_DESCRITOR_LEN != 0)
{
    return -1; //invalid parameters
}

_int32 uiBytesCompressed = 0; // Number of bytes that have been compressed. At the end of the function this should be equal to iRawBufferSize meaning we have compressed the whole raw buffer
_int32 uiCompBuffOffset = 0; // Offset into the compressed buffer

while(uiBytesCompressed < uiRawBufferSize)
{
    if(uiCompressedBufferSize - uiCompBuffOffset < GSM_OUTPUT_SIZE || uiCompBuffOffset >= uiCompressedBufferSize)
    {
       return -2; // Compressed buffer is too small
    }

    gsm_encode(&m_GSM_EncodeStruture,(long *)pRawBuffer,m_Buffer);
    //Now we need to move the data to compressed buffer
    if(m_bFirstHalfOfBlockRecord)
    {
       //Just copy the data over
       memcpy(&pCompressedBuffer[uiCompBuffOffset],m_Buffer,GSM_OUTPUT_SIZE_FIRST_HALF);
       m_bFirstHalfOfBlockRecord = false;
       uiCompBuffOffset += GSM_OUTPUT_SIZE_FIRST_HALF;
    }
    else
    {
       memcpy(&pCompressedBuffer[uiCompBuffOffset],m_Buffer,GSM_OUTPUT_SIZE);
       m_bFirstHalfOfBlockRecord = true;
       uiCompBuffOffset += GSM_OUTPUT_SIZE;
    }

    uiBytesCompressed += AUDIO_DMA_DESCRITOR_LEN;
}

return uiCompBuffOffset; // Success, we have compressed the buffer return compressed data size
}
4

1 に答える 1

0

pRawBufferが決してインクリメントされないことを理解したことを気にしないでください

gsm_encode(&m_GSM_EncodeStruture,(long *)&pRawBuffer[uiBytesCompressed],m_Buffer);
于 2012-10-26T15:00:48.697 に答える