[Speex-dev] Constant noise in the background in realtime data

Jim Crichton jim.crichton at comcast.net
Fri Sep 15 10:13:37 PDT 2006


Since your interface is using 16-bit samples, you will be better off using speex_encode_int and speex_decode_int.  Speex uses 16-bit fixed values internally, speex_encode and speex_decode just convert between float and fixed.  What you have implemented has extra conversions, but that will not break anything.

You should try swapping your byte order.  I seem to remember others reporting your symptom, and the problem was that the samples were byte swapped.

- Jim
  ----- Original Message ----- 
  From: Ali Khan 
  To: speex-dev at xiph.org 
  Sent: Friday, September 15, 2006 10:07 AM
  Subject: [Speex-dev] Constant noise in the background in realtime data


  Hi everyone,

  Our team is working on a realtime voice communication application. We are using openAL 1.1 to capture the samples and then encode them using speex. On the remote machine we decode the samples and play them using openAL again. Capture and play formats for the samples is AL_FORMAT_MONO16 and frequency is 22050. we are using wide band encoding/decoding. 

  The encoding sample frame buffer size is returned by speex as 320, on both ends ( speex_encoder_ctl(m_poSpeexState, SPEEX_GET_FRAME_SIZE, &nFrameSize) ).

  Coming to the problem, when I play the sound I get a high picthed noise in the background. I do hear my voice with a decreased quality but the noise keeps running in the background whether I talk or not.


  Here are the two main encoding/decoding function I am using

  //------------------------------------------------------------------------------------------

  void OALCapture::Compress(ALchar* pData, int *iFrameSize, char* cComFrame)
  {
  // Reset speex bits before frame encode
  speex_bits_reset(&m_oBits);

  int nFrameSize = 0;
  speex_encoder_ctl(m_poSpeexCompressState, SPEEX_GET_FRAME_SIZE, &nFrameSize);

  // Our samples are 2 bytes each so number of samples is actually
  // have the buffer size
  int nBuffSize = BUFFERSIZE / 2; 

  // Now copy the samples into the float array that we will encode
  for(int i = 0; i < nBuffSize; i++)
  input[i] = ( (pData[(i*2) + 1] << 8) | (pData[(i*2)] & 0xff) ) / 32768.0f;

  // Provide speex with the float array pointer to compress
  speex_encode(m_poSpeexCompressState, input, &m_oBits);

  // Write the encoded bytes into our array
  speex_bits_insert_terminator(&m_oBits);
  nbBytes = speex_bits_write(&m_oBits, cbits, BUFFERSIZE);

  // Set the number of bytes of encoded message
  *iFrameSize = nbBytes;

  // Copy encoded bytes into return array
  memcpy(cComFrame, cbits, nbBytes);
  }

  //------------------------------------------------------------------------------------------

  int OALCapture::Decompress(ALchar* pDecomData, int iFrameSize, char* cComFrame)
  {
  // Set the decompress bits
  speex_bits_read_from(&m_oDecompressBits, cComFrame, iFrameSize);

  // Decode the bits into an output float array
  speex_decode(m_poSpeexDecompressState, &m_oDecompressBits, output);

  // Get the number of samples returned by the decoder
  int nSamplesDecoded = 0;
  speex_decoder_ctl(m_poSpeexDecompressState, SPEEX_GET_FRAME_SIZE, &nSamplesDecoded);

  //nSamplesDecoded /= 2;
  // Now we have to convert the floats back into our AL sample format
  // which takes 2 bytes integer value for each sample
  short* pALBuffer = (short*) pDecomData;
  for(int i = 0; i < nSamplesDecoded; i++)
  {
  pALBuffer[i] = output[i] * 32768.0f;
  }

  nSamplesDecoded *= 2;
  return nSamplesDecoded;
  }

  //------------------------------------------------------------------------------------------
  Here are the issues I can think of

  1.
  My buffer size is 640 bytes as each sample is of 2 bytes and the frame buffer size if 320 samples as required by speex. I have tried changing this buffer size and the result is a different type of noise, much worse then what I currently get. 


  Speex returns the same frame size for non-compressed and decompressed data although the quality of decompressed data has reduced.

  2. 
  Should we get a smaller frame size for low quality decoded data ?

  3. 
  Is the sound format the same (AL_FORMAT_MONO16, 22050) for both data ?

  We are in a critical development period, so any quick response will be really helpful to me. 

  Thanks,

  Ali Khan.





------------------------------------------------------------------------------
  Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ countries) for 2¢/min or less.


------------------------------------------------------------------------------


  _______________________________________________
  Speex-dev mailing list
  Speex-dev at xiph.org
  http://lists.xiph.org/mailman/listinfo/speex-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.xiph.org/pipermail/speex-dev/attachments/20060915/d4fb1d78/attachment.html


More information about the Speex-dev mailing list