Syed Mohammad Irteza
2006-Sep-08 04:30 UTC
[Speex-dev] problem with compression and decompression
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
Jean-Marc Valin
2006-Sep-08 04:53 UTC
[Speex-dev] problem with compression and decompression
> 22050 (which is the frequency with which to take sound samples)22050 isn't recommended> AL_FORMAT_MONO16 (which is the OpenAL format in use) > BUFFERSIZE (which is 1024, the size of the frames which I read)Where did you read that you get to choose the frame size? Jean-Marc
Syed Mohammad Irteza
2006-Sep-08 05:42 UTC
[Speex-dev] problem with compression and decompression
I think I made a mistake by saying BUFFERSIZE is "size of frames which I read". It is rather the size of the frames which I capture from the MIC, which I then provide to the Compress function. Could you suggest a frequency which is more suitable? Please note, that the program gives us proper playback sounds if I don't run the compression/decompression functions. IRTEZA On 9/8/06, Jean-Marc Valin <jean-marc.valin@usherbrooke.ca> wrote:> > > 22050 (which is the frequency with which to take sound samples) > > 22050 isn't recommended > > > AL_FORMAT_MONO16 (which is the OpenAL format in use) > > BUFFERSIZE (which is 1024, the size of the frames which I read) > > Where did you read that you get to choose the frame size? > > Jean-Marc >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.xiph.org/pipermail/speex-dev/attachments/20060908/0e2a885e/attachment.htm