[Speex-dev] problem with compression and decompression

Syed Mohammad Irteza smirteza at gmail.com
Fri Sep 8 04:30:28 PDT 2006


Hi,

I am facing a problem with my Voice Communication application. I am using
the Speex API, and have based my application on the given example files
sampleenc.c and sampledec.c. I'm using the OpenAL SDK for voice capture. I
have provided below the two main functions within which the problem exists.
"Compress()" and "Decompress()". Below the code for these functions, I have
written the while loop in main.cpp. When I comment out the calls to Compress
and Decompress, I am able to instantly hear the playback of my own recorded
voice. However, when I uncomment the calls, I am unable to hear my voice,
and instead I get some other garbage noise.

The basic dynamics of the program are slightly different from normal such
applications, in that instead of reading a file at once, I am attempting to
read a frame, and compress, then uncompress, and then playback that frame
before I move on to the next frame.

While initializing the device for reading the sound information, I give it
the following parameters:

22050 (which is the frequency with which to take sound samples)
AL_FORMAT_MONO16 (which is the OpenAL format in use)
BUFFERSIZE (which is 1024, the size of the frames which I read)

As for the arguments for "Compress()", pData is the ALchar pointer which
contains the data. iFrameSize is the integer which will store the number of
bytes actually written to the compressed frame. cComeFrame is the character
array which eventually stores the compressed voice data.

As for the arguments for "Decompress()", pDecomData is the ALchar pointer
which will store the decompressed voice data. iFrameSize is the integer
which provides the actual number of bytes written to the compressed frame.
cComeFrame is the character array which provides the compressed voice data
as input for this function.


void OALCapture::Compress(ALchar* pData, int *iFrameSize, char* cComFrame)

{

       speex_bits_init(&m_oBits);



       int i;



       /*Flush all the bits in the struct so we can encode a new frame*/

       speex_bits_reset(&m_oBits);

       /* Copy the data from ALchar array to a float array */

       for(i = 0; i < BUFFERSIZE; ++i)

              input[i] = pData[i];



       /*Encode the frame*/

       speex_encode(m_poSpeexCompressState, input, &m_oBits);

       /*Copy the bits to an array of char that can be written*/

       nbBytes = speex_bits_write(&m_oBits, cbits, BUFFERSIZE);

       strcpy(cComFrame, cbits);



}
void OALCapture::Decompress(ALchar* pDecomData, int iFrameSize, char*
cComFrame)

{

      speex_bits_init(&m_oDecompressBits);

       int i;

       ///*Copy the data into the bit-stream struct*/

       speex_bits_read_from(&m_oDecompressBits, cComFrame, iFrameSize);

       /*Decode the data*/

       speex_decode(m_poSpeexDecompressState, &m_oDecompressBits, output);

       /*Copy from float to short (16 bits) for output*/

       for (i = 0; i < BUFFERSIZE; i++)

              out[i] = output[i];


       strcpy(pDecomData, out);

}


main.cpp



while (!_kbhit() )

{
       if ( g_oCapture.CaptureSamples(g_ArrBuffer, (BUFFERSIZE /
g_sWaveHeader.wfex.nBlockAlign)
) )

       {

              int iFrameSize = 0;

              char cComFrame[200];

              ALchar ArrTemp[BUFFERSIZE];



              g_oCapture.Compress(g_ArrBuffer, &iFrameSize, cComFrame
);


              g_oCapture.Decompress(ArrTemp, iFrameSize, cComFrame);



              g_oCapture.ProcessBuffers(g_uiSourceID);

              g_oCapture.QueueBuffer(g_uiSourceID, ArrTemp, BUFFERSIZE );

              g_oCapture.PlayStream(g_uiSourceID);


       }

}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.xiph.org/pipermail/speex-dev/attachments/20060908/eb712a38/attachment.htm


More information about the Speex-dev mailing list