[speex-dev] SPEEX_SET_USER_HANDLER once again

Norman Biehl n.biehl at gmx.de
Fri Nov 7 08:17:40 PST 2003

Sorry!  Marc Gimpel. I wrote it in a false thread before. It was my
first time. :-)
I have to write a small programm which should be able to record speeches

and in addition synchronize the recorded speeches with measuring data. 
My idea is to record the speech in the normal way with speex and without

ogg. If a sync message was received, i write a custom in-band messages 
using mode 13 into the stream. Furthermore, i fill a structure with the 
sync data and write the structure into an array. To determine the
of the sync structure in the array, i have to write the array index of
sync structure into the stream. Inside the user callback i have to read 
the array index of the reached sync point from the stream and send it 
within a notification message to the application. 
The Problem is, after the decoder reached the custom in-band messages
executed the user callback, the stream is corrupted and speex_decode() 
returns -2. 
I don't know where the problem is. 
I can't find any sample code for custom in-band messages. 
Is there anyone who can help? 
Here some sample code: 
/********************************** encoder 
// read raw data from serving buffer 
void CSpeexEncoderThread::Decode(char * pcData, DWORD dwLength){ 
        speex_encode(st, s, &bits); // encode 
        if (syncmsg == TRUE && synccount < 256){ // is there a sync
                syncstruct[synccount].sync_value = syncvalue; //fill the
sync structure 
                speex_bits_pack(&bits, 13, 5); //custom in-band messages

                // write the array index of the sync structure into the
stream (max. 256 
sync points) 
                speex_bits_pack(&bits, synccount, 8); 
        nbBytes = speex_bits_write(&bits, cbits, MAX_FRAME_BYTES); 
        // write the encoded data into the end buffer 
/********************************** encoder end 
/************************************* decoder 
int CSpeexDecoderThread::SpeexUserCallback(SpeexBits *bits, void *state,

void *data){ 
        // read the array index of the corresponding sync structure 
        int index = speex_bits_unpack_unsigned(bits, 8); 
        SendNotifyMessage(l_sdthread->m_hWnd, USER_PLAYBACK_MESSAGE,
        return 0; 
inline int speex_bits_init_buffer_ex(SpeexBits *bits, void *buff, int 
        if (buff == NULL || buf_size == 0) 
                return -1; 
        memset(bits, 0, sizeof(SpeexBits)); 
        bits->bytes = (char*)buff; 
        bits->buf_size = buf_size; 
        bits->nbBits=buf_size << 3; 
        return 0; 
int CSpeexDecoderThread::DecodePlay(void* state, SpeexStereoState
        char* pcData, DWORD dwLength, int nchannels, int frame_size, int

        if (synccount > 0){ 
                callback.callback_id = 0; 
                callback.func = SpeexUserCallback; 
                callback.data = this; 
                speex_decoder_ctl(state, SPEEX_SET_USER_HANDLER,
        speex_bits_init_buffer_ex(&bits, pcData, dwLength); 
        while (1 == 1){ 
                retval = speex_decode(state, &bits, output); 
                if (retval == -1){ 
                        return -1; //return DECODE_ENDOFSTREAM; 
                } else if (retval == -2){ 
                        return -2; 
                // play the sample 
The second question, is there something wrong with the speex_uwb_mode 
since version 1.1? 
It don't work. Only speex_nb_mode and speex_wb_mode works. 
ps: sorry for my pure english. 

<p>--- >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