[speex-dev] C++ wrapper for speex
Tom Grandgent
tgrand at canvaslink.com
Wed May 26 06:57:41 PDT 2004
Ronald,
I suggest we take this discussion off the list after
this post.
I don't see any problems with your code. However, I
can make a few suggestions:
1) If you replace the lines:
pSpeexHdr->lpData = (char*)pSound;
pSpeexHdr->dwBufferLength = decodedSamples * sizeof(short);
with:
pSpeexHdr->lpData = lpHdr->lpData;
pSpeexHdr->dwBufferLength = lpHdr->dwBufferLength;
does it sound right? If not, your problem is not with
the encoding or decoding.
2) Try checking the error state of the classes after
each method call, and before you try to call any
methods (beyond the constructor). For example:
if (enc.err) MessageBox(NULL, enc.errText, "doh", 0);
3) Did you initialize the classes with 8000 as the
sample rate? Are you sure your input data is 8000Hz,
16-bit mono?
4) Try checking enc.getFrameSize() and make sure it's 160.
5) Make sure lpHdr->dwBufferLength is always 160 or a
multiple of 160.
6) You don't have to do the float conversion yourself -
you can pass encode() an array of short ints.
7) If you're still stuck, single step through each line
of code with a debugger, stepping into the class methods,
and make sure you understand what's going on.
8) Also, you might try to simplify your problem to get
started - for example, encode and decode data from raw
sound files in a non-realtime situation.
Good luck,
Tom
Ronald Madrid (mfcguru at yahoo.com) wrote:
>
> hi Tom,
>
> i downloaded your speex wrappers and they're really
> what i'm looking for! i really cannot worry about
> container support at the moment because i'm working
> with real-time audio, and hopefully toward VoIP when
> everything else is in order.
>
> im using waveform to capture data from the microphone.
> the raw PCM sample is stored in the WAVEHDR
> structure's member lpData, and this variable is of
> LPSTR type.
>
> if you have the time, can you please check on my test
> code below and see where i could be having problems
> with. (this is the handler that processes captured
> audio)
>
> LRESULT CRecordSound::OnSoundData(WPARAM wParam,
> LPARAM lParam)
> {
> LPWAVEHDR lpHdr = (LPWAVEHDR) lParam;
>
> int buflen = lpHdr->dwBufferLength; //160
> float * buf = toFloat(lpHdr->lpData, buflen);
>
> // Encode some audio
> int nRet = enc.encode(buf, buflen);
> unsigned char *compressed = enc.getOutput();
> int clen = enc.getOutputLength();
> int speechDetected = enc.getSpeechDetected();
>
> // delete temporary float buffer
> delete []buf;
>
> // Decode it
> int decodedSamples = dec.decode(compressed, clen);
>
> // Prepare decoded data for WAV
> BYTE pSound = new BYTE[decodedSamples *
> sizeof(short)];
> memcpy(pSound, (BYTE*)dec.getOutput(), decodedSamples
> * sizeof(short));
>
> // Create and initialise the WAVEHDR structure
> WAVEHDR* pSpeexHdr = new WAVEHDR;
> pSpeexHdr->lpData = (char*)pSound;
> pSpeexHdr->dwBufferLength = decodedSamples *
> sizeof(short);
> pSpeexHdr->dwFlags = 0L;
> pSpeexHdr->dwLoops = 0L;
>
> // output audio to speaker
> m_Player->PostThreadMessage(WM_PLAYSOUND_PLAYBLOCK,
> GetCurrentThreadId(),(LPARAM) pSpeexHdr);
>
> // clean up
> // delete pSeexHdr;
> // delete [] pSound;
>
> return 1;
> }
>
> this produces unintelligible audio. may be you can
> give me an opinion on how i can properly reconstruct
> my PCM sample ( into WAVHDR) after the decode. this
> would really mean a lot to me.
>
> many of thanks!!!
>
> best regards,
> ronald
--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'speex-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the Speex-dev
mailing list