[speex-dev] C++ wrapper for speex

Ronald Madrid mfcguru at yahoo.com
Wed May 26 03:39:25 PDT 2004

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

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 *
        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 *
        pSpeexHdr->dwFlags = 0L; 
        pSpeexHdr->dwLoops = 0L;
        // output audio to speaker
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,

Do you Yahoo!?
Friends.  Fun.  Try the all-new Yahoo! Messenger.
--- >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