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/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://lists.xiph.org/pipermail/speex-dev/attachments/20071104/e0d5ff78/attachment.html
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@xiph.org > http://lists.xiph.org/mailman/listinfo/speex-dev
Thank you for such a quick response.
The only reason I started with Char buffers is because WaveIn and WaveOut on
Windows XP accept/emit WAVEHDR structures, which store audio data in LPSTR,
which is Char*.
typedef struct {
LPSTR lpData;
DWORD dwBufferLength;
...
} WAVEHDR;
When I was going from Char to float and back looked very wrong to me as well,
but I was just not sure (and still am) how to translate the Char* audio stream
generated by WaveIn to a format that can be understood by Speex. Would using
speex_decode_int and speex_encode_int instead of speex_decode and speex_encode
be the answer?
Thank you,
Evgueni Tsygankov
www.sqlanswers.com
www.rusmex.com
-----Original Message-----
From: Jean-Marc Valin [mailto:jean-marc.valin@usherbrooke.ca]
Sent: Sunday, November 04, 2007 9:33 PM
To: Evgueni Tsygankov
Cc: speex-dev@xiph.org
Subject: Re: [Speex-dev] WaveIn/WaveOut and Speex
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@xiph.org
> http://lists.xiph.org/mailman/listinfo/speex-dev
Hello, I tried compiling BETA2, and got a linker error in RTL: Error 1 fatal error LNK1181: cannot open input file '.\Debug_RTL_dll\medfilter.obj' libspeex Or in regular Debug build: Error 1 fatal error C1083: Cannot open source file: '..\..\..\libspeex\medfilter.c': No such file or directory c1 Thanks in advance, Evgueni