[Speex-dev] Integrating speex with VideoNet application: Constant
background noise
Carine Liang
carineliang at yahoo.com.sg
Mon Oct 30 21:05:49 PST 2006
Hi,
I am developing a peer-to-peer video conference application which uses speex as a codec for the voice.
I am new to speex, so please bear with me if I asked the obvious. After I added the encode and decode function to my MFC app, I heard a constant background noise, even when no one is speaking into the microphone.
#define FRAME_SIZE 160
The application is coded in MFC C++. The record buffer is set to be the same as the FRAME_SIZE such that my callback function is called everytime 160 bytes of data is recorded.
Here's what I did in the initialisation (called only once).
m_waveFormatEx.wFormatTag =WAVE_FORMAT_PCM;
m_waveFormatEx.nChannels =1;
m_waveFormatEx.wBitsPerSample =8;
m_waveFormatEx.cbSize =0;
m_waveFormatEx.nSamplesPerSec = 8000;
m_waveFormatEx.nBlockAlign =1;
m_waveFormatEx.nAvgBytesPerSec = 8000;
int quality =8;
speex_bits_init(&bits);
enc_state = speex_encoder_init(&speex_nb_mode);
speex_encoder_ctl(enc_state, SPEEX_SET_QUALITY, &quality);
In my recording callback function
LRESULT RecordSound::OnSoundData(WPARAM wParam, LPARAM lParam)
{
....
dataPtr = (char *)lpHdr ->lpData;
dataSize = (int)lpHdr ->dwBytesRecorded;
for(int k=0;k<FRAME_SIZE;k++)
input[k] = dataPtr[k]; //input is float[FRAME_SIZE]
speex_bits_reset(&bits);
speex_encode(enc_state, input, &bits);
encByte = speex_bits_write(&bits, cbits, 200);
//send cbits to peer computer via sockets
}
In the receiver's initialization function, I've initialized the speex_decoder.
speex_bits_init(&bits);
dec_state = speex_decoder_init(&speex_nb_mode);
In the receiver's socket function, it reads from socket and store the data in cbits (char array).
{
speex_bits_read_from(&bits, cbits, retvalue); //retvalue is 38
speex_decode(dec_state, &bits, output); //where output is float array
for(int k=0;k<FRAME_SIZE;k++)
out[k] = output[k]; //out is a char array
PostThreadMessage( WM_PLAYSOUND_PLAYBLOCK, FRAME_SIZE, (LPARAM)out );
}
__________________________________
What will the world find in 2020?
Leave a part of your 2006 in the Yahoo! Time Capsule. Contribute now!
http://timecapsule.yahoo.com/capsule.php?intl=sg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.xiph.org/pipermail/speex-dev/attachments/20061030/08ce83ea/attachment.htm
More information about the Speex-dev
mailing list