[Speex-dev] WaveIn/WaveOut and Speex

Jean-Marc Valin jean-marc.valin at usherbrooke.ca
Sun Nov 4 19:32:46 PST 2007


I'm not sure what input/output format you're trying to use, but it looks
wrong. You're using the float functions that take +-32767 values and
you're feeding (or converting) chars. Unless your machine has very
special chars (which I doubt), a +-32767 value just isn't going to fit
in. This has nothing to do with Speex BTW, it's just handling the audio
data properly.

	Jean-Marc


Evgueni Tsygankov wrote:
> Hello,
> 
>  
> 
> I know my question has been asked before because I spent the last week
> searching the web for how to use Speex in combination with
> WaveIn/WaveOut and I ran into a few posts, but none of them answer the
> question. There is still a lot of confusion how to use WaveIn/WaveOut
> and Speex by junior developers such as myself. Even after examining code
> for SpeexDec and SpeexEnc, I cannot get clear sound when I try to
> 
>  
> 
> Get PCM Char buffer from the microphone
> 
> Encode Char buffer using Speex
> 
> Decode Speex Char buffer into PCM char buffer
> 
> Play PCM char buffer using WaveOut
> 
>  
> 
> The end-result is very distorted sound.
> 
>  
> 
>  
> 
> I use the following PCM format:
> 
>  
> 
> waveFormat.nChannels = 1;
> 
> waveFormat.nSamplesPerSec = 8000;
> 
> waveFormat.wBitsPerSample = 8;
> 
>  
> 
> Once sound is aquired by the mic, I send it to Speex in a Char buffer.
> It looks something like this:
> 
>  
> 
> Encode(char* inBuffer, DWORD bufferLength)
> 
> ...
> 
> float* input = new float[frameSize];
> 
> ZeroMemory(input, frameSize);
> 
> ...
> 
> for(    )
> 
> {
> 
> input[..] = inBuffer[..];
> 
> }
> 
> ...
> 
> speex_encode(enc_state, input, &bits);
> 
> int bytesWritten = speex_bits_nbytes(&bits);
> 
> speex_bits_write(&bits, encBuffer, bytesWritten);
> 
>  
> 
>  
> 
>  
> 
> Then, my decoding routine accepts the char buffer that was encoded with
> Speex:
> 
>  
> 
> Decode(char* encBuffer, DWORD bufferLength)
> 
> ...
> 
> float* output = new float[frameSize];
> 
> ...
> 
> speex_bits_read_from(&bits, encBuffer + offset, bytesToRead);
> 
> speex_decode(dec_state, &bits, output);
> 
>  
> 
> char* outBuffer=...
> 
> for(UINT i = 0; i < frameSize; i++)
> 
> {
> 
> outBuffer[retValIndex] = output[i];
> 
> retValIndex++;
> 
> }
> 
>  
> 
> When I try to play outBuffer with waveOut, I can hear the voice
> “somewhere far”, but there is a lot of distortion noise. Any help would
> be greatly appreciated!!!
> 
>  
> 
> Thank you,
> 
>  
> 
> Evgueni Tsygankov
> 
> www.sqlanswers.com <http://www.sqlanswers.com/>
> 
>  
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Speex-dev mailing list
> Speex-dev at xiph.org
> http://lists.xiph.org/mailman/listinfo/speex-dev


More information about the Speex-dev mailing list