hy,<br><br>recording and playback is working perfectly without speex.<br><br>i have try to set samplerat from 6000 to 441000 and quality from 1 to 10 sam with complexy, but the best i can get is with 16000 samplerate, 5quality and 3complexy .. but still, the voice that came out is annoying, artificial, robot ,... <br>

<br clear="all">Lp, Tim<br>+--------------------------+<br>| email: <a href="mailto:rico@gama.us">rico@gama.us</a>      |<br>| www:    <a href="http://gama.us">http://gama.us</a>   |<br>|--------------------------|<br>| tel:    00386 31 457 627 |<br>

+--------------------------+<br><br>
<br><br><div class="gmail_quote">2009/9/3  <span dir="ltr">&lt;<a href="mailto:speex-dev-request@xiph.org">speex-dev-request@xiph.org</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

Send Speex-dev mailing list submissions to<br>
        <a href="mailto:speex-dev@xiph.org">speex-dev@xiph.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
        <a href="http://lists.xiph.org/mailman/listinfo/speex-dev" target="_blank">http://lists.xiph.org/mailman/listinfo/speex-dev</a><br>
or, via email, send a message with subject or body &#39;help&#39; to<br>
        <a href="mailto:speex-dev-request@xiph.org">speex-dev-request@xiph.org</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:speex-dev-owner@xiph.org">speex-dev-owner@xiph.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than &quot;Re: Contents of Speex-dev digest...&quot;<br>
<br>
<br>
Today&#39;s Topics:<br>
<br>
   1. Re: voice sound like robot voice :) (Greger Burman)<br>
   2. Re: voice sound like robot voice :) (Tim Rijavec)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Thu, 3 Sep 2009 10:21:49 +0200<br>
From: Greger Burman &lt;<a href="mailto:greger@mobile-robotics.com">greger@mobile-robotics.com</a>&gt;<br>
Subject: Re: [Speex-dev] voice sound like robot voice :)<br>
To: <a href="mailto:speex-dev@xiph.org">speex-dev@xiph.org</a><br>
Message-ID:<br>
        &lt;<a href="mailto:18b67100909030121w2ef10d34j2c44b81f716924d6@mail.gmail.com">18b67100909030121w2ef10d34j2c44b81f716924d6@mail.gmail.com</a>&gt;<br>
Content-Type: text/plain; charset=&quot;iso-8859-1&quot;<br>
<br>
Hi Tim!<br>
<br>
I haven&#39;t looked at your code. I would first make sure that recording and<br>
playback of audio is working perfectly without the encoder. Bugs in the<br>
handling of recording or playback can result in strange noises.<br>
<br>
cheers<br>
Greger<br>
<br>
<br>
2009/9/2 Tim Rijavec &lt;<a href="mailto:rico@gama.us">rico@gama.us</a>&gt;<br>
<br>
&gt; hy,<br>
&gt;<br>
&gt; here is my speex encoder/decoder .. the sampleRate i use is 16000 and<br>
&gt; quality,complexity are at 5.<br>
&gt;<br>
&gt; can someone take a look in to the code and see if there is something that<br>
&gt; is making that robot voice<br>
&gt;<br>
&gt; here is a link to colored and numbered code, same as below<br>
&gt; <a href="http://barvanjekode.gama.us/temp/1257361243.html" target="_blank">http://barvanjekode.gama.us/temp/1257361243.html</a><br>
&gt;<br>
&gt; thanx.<br>
&gt;<br>
&gt; code<br>
&gt; -----------------------<br>
&gt; #include &quot;codec.h&quot;<br>
&gt;<br>
&gt; /////////////////////////////////////////////////////////////////<br>
&gt; // Constants<br>
&gt; /////////////////////////////////////////////////////////////////<br>
&gt; #define Cvoicecodecrawbuffersize       16 * Ckilobyte<br>
&gt;<br>
&gt; /////////////////////////////////////////////////////////////////<br>
&gt; //<br>
&gt; // TVoiceCodec<br>
&gt; //<br>
&gt; /////////////////////////////////////////////////////////////////<br>
&gt; TVoiceCodec::TVoiceCodec() :<br>
&gt; pMode( NULL ),<br>
&gt; pPreprocessorState( NULL ),<br>
&gt; pCodecEncoderState( NULL ),<br>
&gt; encoderQuality( 5 ),<br>
&gt; encoderComplexity( 3 ),<br>
&gt; encoderFrameSize( 0 ),<br>
&gt; encodedFrameBytes( 0 ),<br>
&gt; pCodecDecoderState( NULL ),<br>
&gt; sampleRate( VOICE_SAMPLE_RATE ),<br>
&gt; decoderFrameSize( 0 )<br>
&gt; {<br>
&gt;    /////////////////////////////////////////////////////////////////<br>
&gt;    // Prepare buffers<br>
&gt;    /////////////////////////////////////////////////////////////////<br>
&gt;    uint voicememsize = Cvoicecodecrawbuffersize + CODEC_MAX_BUFFER_SIZE;<br>
&gt;    byte *voicemem = (byte*)pMemoryMng-&gt;Alloc(voicememsize);<br>
&gt;    memset( voicemem, 0, voicememsize );<br>
&gt;<br>
&gt;    // raw voice input buffer<br>
&gt;    pCodecRawBuffer = voicemem;<br>
&gt;    pCodecRawBufferCur = pCodecRawBuffer;<br>
&gt;    //<br>
&gt;    voicemem += Cvoicecodecrawbuffersize;<br>
&gt;<br>
&gt;    // input/output voice buffer<br>
&gt;    pCodecBuffer = voicemem;<br>
&gt; }<br>
&gt;<br>
&gt;<br>
&gt; TVoiceCodec::~TVoiceCodec()<br>
&gt; {<br>
&gt;    if ( pCodecEncoderState )<br>
&gt;    {<br>
&gt;       speex_preprocess_state_destroy( pPreprocessorState );<br>
&gt;       speex_encoder_destroy( pCodecEncoderState );<br>
&gt;       speex_bits_destroy( &amp;codecBits );<br>
&gt;       pCodecEncoderState = NULL;<br>
&gt;    }<br>
&gt;<br>
&gt;    if ( pCodecDecoderState )<br>
&gt;    {<br>
&gt;       speex_decoder_destroy( pCodecDecoderState );<br>
&gt;       speex_bits_destroy( &amp;codecBits );<br>
&gt;       pCodecDecoderState = NULL;<br>
&gt;    }<br>
&gt; }<br>
&gt;<br>
&gt;<br>
&gt; void TVoiceCodec::setSampleRate( int samplerate )<br>
&gt; {<br>
&gt;    sampleRate = samplerate;<br>
&gt;<br>
&gt;    // determine the mode<br>
&gt;    int modeID = -1;<br>
&gt;<br>
&gt;    // speex has limits [6000 - 48000]<br>
&gt;    if ( sampleRate &gt; 48000 )<br>
&gt;       return;<br>
&gt;<br>
&gt;    if ( sampleRate &gt; 25000 )<br>
&gt;       modeID = SPEEX_MODEID_UWB;<br>
&gt;    else if ( sampleRate &gt; 12500 )<br>
&gt;       modeID = SPEEX_MODEID_WB;<br>
&gt;    else if ( sampleRate &gt;= 6000 )<br>
&gt;       modeID = SPEEX_MODEID_NB;<br>
&gt;    else<br>
&gt;       return;<br>
&gt;<br>
&gt;    // set up mode<br>
&gt;    pMode = speex_lib_get_mode( modeID );<br>
&gt; }<br>
&gt;<br>
&gt; void TVoiceCodec::setupEncoder( uint quality, uint complexity  )<br>
&gt; {<br>
&gt;    encoderQuality = quality;<br>
&gt;    encoderComplexity = complexity;<br>
&gt;<br>
&gt;    // catch invalid sample rates resulting in invalid mode<br>
&gt;    if ( !pMode )<br>
&gt;       return;<br>
&gt;    //<br>
&gt;    assert( ( pCodecEncoderState == NULL ) &amp;&amp; &quot;encoder already initialized&quot;<br>
&gt; );<br>
&gt;    //<br>
&gt;    int enabled   = 1;<br>
&gt;    int disabled  = 0;<br>
&gt;    //<br>
&gt;    float highpass = 80;<br>
&gt;<br>
&gt;    // setup encoder<br>
&gt;    pCodecEncoderState = speex_encoder_init( pMode );<br>
&gt;    //<br>
&gt;    speex_encoder_ctl( pCodecEncoderState, SPEEX_SET_SAMPLING_RATE,<br>
&gt; &amp;sampleRate );<br>
&gt;    speex_encoder_ctl( pCodecEncoderState, SPEEX_SET_COMPLEXITY,<br>
&gt; &amp;encoderComplexity );<br>
&gt;    speex_encoder_ctl( pCodecEncoderState, SPEEX_SET_QUALITY,<br>
&gt; &amp;encoderQuality );<br>
&gt;    speex_encoder_ctl( pCodecEncoderState, SPEEX_SET_VBR,<br>
&gt; &amp;disabled );<br>
&gt;    speex_encoder_ctl( pCodecEncoderState, SPEEX_SET_DTX,<br>
&gt; &amp;disabled );<br>
&gt;<br>
&gt;    // init encoder<br>
&gt;    speex_bits_init( &amp;codecBits );<br>
&gt;    speex_bits_reset( &amp;codecBits );<br>
&gt;<br>
&gt;    // determine encoded bytes per frame with spx_int16_t type, speex can<br>
&gt; work with float;s, but not in this engine<br>
&gt;    speex_encode_int( pCodecEncoderState, (spx_int16_t*)pCodecBuffer,<br>
&gt; &amp;codecBits );<br>
&gt;    encodedFrameBytes = (uint)speex_bits_nbytes( &amp;codecBits );<br>
&gt;<br>
&gt;    // setup preprocessor<br>
&gt;    speex_encoder_ctl( pCodecEncoderState, SPEEX_GET_FRAME_SIZE,<br>
&gt; &amp;encoderFrameSize );<br>
&gt;    //<br>
&gt;    pPreprocessorState = speex_preprocess_state_init( encoderFrameSize,<br>
&gt; sampleRate );<br>
&gt;    //<br>
&gt;    speex_preprocess_ctl( pPreprocessorState, SPEEX_PREPROCESS_SET_DENOISE,<br>
&gt; &amp;enabled );<br>
&gt;    speex_preprocess_ctl( pPreprocessorState, SPEEX_PREPROCESS_SET_VAD,<br>
&gt; &amp;disabled );<br>
&gt; }<br>
&gt;<br>
&gt; void TVoiceCodec::setupDecoder()<br>
&gt; {<br>
&gt;    // catch invalid sample rates resulting in invalid mode<br>
&gt;    if ( !pMode )<br>
&gt;       return;<br>
&gt;    //<br>
&gt;    assert( ( pCodecDecoderState == NULL ) &amp;&amp; &quot;decoder already initialized&quot;<br>
&gt; );<br>
&gt;    //<br>
&gt;    int enabled = 1;<br>
&gt;    //<br>
&gt;    pCodecDecoderState = speex_decoder_init( pMode );<br>
&gt;    speex_decoder_ctl( pCodecDecoderState, SPEEX_SET_SAMPLING_RATE,<br>
&gt; &amp;sampleRate );<br>
&gt;    speex_decoder_ctl( pCodecDecoderState, SPEEX_GET_FRAME_SIZE,<br>
&gt; &amp;decoderFrameSize );<br>
&gt;    speex_decoder_ctl( pCodecDecoderState, SPEEX_SET_ENH,<br>
&gt; &amp;enabled );<br>
&gt;    //<br>
&gt;    speex_bits_init( &amp;codecBits );<br>
&gt; }<br>
&gt;<br>
&gt; uint TVoiceCodec::encode( byte *rawsoundbuffer, uint length, char<br>
&gt; *bitbuffer, float gain )<br>
&gt; {<br>
&gt;    if( !pCodecEncoderState )<br>
&gt;       return 1;<br>
&gt;<br>
&gt;    // copy raw voice data to temporary codec raw voice data buffer<br>
&gt;    memcpy( pCodecRawBufferCur, rawsoundbuffer, length );<br>
&gt;    pCodecRawBufferCur += length;<br>
&gt;<br>
&gt;    // determine the size of data<br>
&gt;    uint buffersize = (int)( pCodecRawBufferCur - pCodecRawBuffer );<br>
&gt;<br>
&gt;    // do we have enough data for encoding?<br>
&gt;    if ( buffersize &lt; encoderFrameSize )<br>
&gt;    {<br>
&gt;       //pLog-&gt;Add(&quot;codec: encoder: return: buffersize: %d: needtoencode<br>
&gt; %d&quot;, buffersize, encoderFrameSize);<br>
&gt;       return 0;<br>
&gt;    }<br>
&gt;<br>
&gt;    int encodedbytes  = 0;<br>
&gt;    int pos = 0;<br>
&gt;    // while we have enough data<br>
&gt;    while( (uint)( pCodecRawBufferCur - pCodecRawBuffer ) &gt;=<br>
&gt; encoderFrameSize )<br>
&gt;    {<br>
&gt;       // copy data from temporary buffer to codec buffer<br>
&gt;       memcpy( pCodecBuffer, pCodecRawBuffer, encoderFrameSize );<br>
&gt;<br>
&gt;       // move memory of temporary buffer<br>
&gt;       memmove( pCodecRawBuffer, pCodecRawBuffer + encoderFrameSize,<br>
&gt; buffersize - ( pos + encoderFrameSize ) );<br>
&gt;       pCodecRawBufferCur -= encoderFrameSize;<br>
&gt;<br>
&gt;       // increase current pos<br>
&gt;       pos += encoderFrameSize;<br>
&gt;<br>
&gt;       //encode<br>
&gt;       speex_bits_reset( &amp;codecBits );<br>
&gt;       //<br>
&gt;       speex_encode_int( pCodecEncoderState, (spx_int16_t*)pCodecBuffer,<br>
&gt; &amp;codecBits );<br>
&gt;       //<br>
&gt;       int nb = speex_bits_nbytes( &amp;codecBits );<br>
&gt;       encodedbytes += speex_bits_write( &amp;codecBits,<br>
&gt; &amp;bitbuffer[encodedbytes], nb );<br>
&gt;    }<br>
&gt;<br>
&gt;    //pLog-&gt;Add(&quot;buffersize: %d: total left: %d enc buffersize: %d&quot;, length,<br>
&gt; inputBufferArray.Count(), encodedbytes );<br>
&gt;    return encodedbytes;<br>
&gt; }<br>
&gt;<br>
&gt; uint TVoiceCodec::decode( char *bitbuffer, uint length, byte *samplearray,<br>
&gt; float gain )<br>
&gt; {<br>
&gt;    // return if decoder is not initialized<br>
&gt;    if( !pCodecDecoderState )<br>
&gt;       return 0;<br>
&gt;<br>
&gt;    // return if there is not enough data to decode<br>
&gt;    if ( length &lt; encodedFrameBytes )<br>
&gt;       return 0;<br>
&gt;<br>
&gt;    int buffersize       = length;<br>
&gt;    uint decodedbytes    = 0;<br>
&gt;    int pos              = 0;<br>
&gt;    //<br>
&gt;    while( (int)buffersize - (int)encodedFrameBytes &gt;= 0 )<br>
&gt;    {<br>
&gt;       speex_bits_reset( &amp;codecBits );<br>
&gt;       speex_bits_read_from( &amp;codecBits, bitbuffer + pos, encodedFrameBytes<br>
&gt; );<br>
&gt;       //<br>
&gt;       if( speex_decode_int( pCodecDecoderState, &amp;codecBits,<br>
&gt; (spx_int16_t*)pCodecBuffer ) == 0 )<br>
&gt;       {<br>
&gt;          memcpy( &amp;samplearray[decodedbytes], pCodecBuffer, decoderFrameSize<br>
&gt; );<br>
&gt;          decodedbytes += decoderFrameSize;<br>
&gt;       }<br>
&gt;       //<br>
&gt;       pos += encodedFrameBytes;<br>
&gt;       buffersize -= encodedFrameBytes;<br>
&gt;    }<br>
&gt;<br>
&gt;    return decodedbytes;<br>
&gt; }<br>
&gt;<br>
&gt; -----------------------<br>
&gt; code<br>
&gt;<br>
&gt; Lp, Tim<br>
&gt; +--------------------------+<br>
&gt; | email: <a href="mailto:rico@gama.us">rico@gama.us</a>      |<br>
&gt; | www:    <a href="http://gama.us" target="_blank">http://gama.us</a>   |<br>
&gt; |--------------------------|<br>
&gt; | tel:    00386 31 457 627 |<br>
&gt; +--------------------------+<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Speex-dev mailing list<br>
&gt; <a href="mailto:Speex-dev@xiph.org">Speex-dev@xiph.org</a><br>
&gt; <a href="http://lists.xiph.org/mailman/listinfo/speex-dev" target="_blank">http://lists.xiph.org/mailman/listinfo/speex-dev</a><br>
&gt;<br>
&gt;<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <a href="http://lists.xiph.org/pipermail/speex-dev/attachments/20090903/86415e92/attachment-0001.htm" target="_blank">http://lists.xiph.org/pipermail/speex-dev/attachments/20090903/86415e92/attachment-0001.htm</a><br>


<br>
------------------------------<br>
<br>
Message: 2<br>
Date: Thu, 3 Sep 2009 14:20:38 +0200<br>
From: Tim Rijavec &lt;<a href="mailto:rico@gama.us">rico@gama.us</a>&gt;<br>
Subject: Re: [Speex-dev] voice sound like robot voice :)<br>
To: <a href="mailto:speex-dev@xiph.org">speex-dev@xiph.org</a><br>
Message-ID:<br>
        &lt;<a href="mailto:55bb9c6f0909030520x6f9f500tfdc1e6211d5b8003@mail.gmail.com">55bb9c6f0909030520x6f9f500tfdc1e6211d5b8003@mail.gmail.com</a>&gt;<br>
Content-Type: text/plain; charset=&quot;iso-8859-1&quot;<br>
<br>
hy,<br>
recording and playback without speex is working perfectly<br>
<br>
<br>
Lp, Tim<br>
+--------------------------+<br>
| email: <a href="mailto:rico@gama.us">rico@gama.us</a>      |<br>
| www:    <a href="http://gama.us" target="_blank">http://gama.us</a>   |<br>
|--------------------------|<br>
| tel:    00386 31 457 627 |<br>
+--------------------------+<br>
<br>
<br>
<br>
2009/9/2 Tim Rijavec &lt;<a href="mailto:rico@gama.us">rico@gama.us</a>&gt;<br>
<br>
&gt; hy,<br>
&gt;<br>
&gt; here is my speex encoder/decoder .. the sampleRate i use is 16000 and<br>
&gt; quality,complexity are at 5.<br>
&gt;<br>
&gt; can someone take a look in to the code and see if there is something that<br>
&gt; is making that robot voice<br>
&gt;<br>
&gt; here is a link to colored and numbered code, same as below<br>
&gt; <a href="http://barvanjekode.gama.us/temp/1257361243.html" target="_blank">http://barvanjekode.gama.us/temp/1257361243.html</a><br>
&gt;<br>
&gt; thanx.<br>
&gt;<br>
&gt; code<br>
&gt; -----------------------<br>
&gt; #include &quot;codec.h&quot;<br>
&gt;<br>
&gt; /////////////////////////////////////////////////////////////////<br>
&gt; // Constants<br>
&gt; /////////////////////////////////////////////////////////////////<br>
&gt; #define Cvoicecodecrawbuffersize       16 * Ckilobyte<br>
&gt;<br>
&gt; /////////////////////////////////////////////////////////////////<br>
&gt; //<br>
&gt; // TVoiceCodec<br>
&gt; //<br>
&gt; /////////////////////////////////////////////////////////////////<br>
&gt; TVoiceCodec::TVoiceCodec() :<br>
&gt; pMode( NULL ),<br>
&gt; pPreprocessorState( NULL ),<br>
&gt; pCodecEncoderState( NULL ),<br>
&gt; encoderQuality( 5 ),<br>
&gt; encoderComplexity( 3 ),<br>
&gt; encoderFrameSize( 0 ),<br>
&gt; encodedFrameBytes( 0 ),<br>
&gt; pCodecDecoderState( NULL ),<br>
&gt; sampleRate( VOICE_SAMPLE_RATE ),<br>
&gt; decoderFrameSize( 0 )<br>
&gt; {<br>
&gt;    /////////////////////////////////////////////////////////////////<br>
&gt;    // Prepare buffers<br>
&gt;    /////////////////////////////////////////////////////////////////<br>
&gt;    uint voicememsize = Cvoicecodecrawbuffersize + CODEC_MAX_BUFFER_SIZE;<br>
&gt;    byte *voicemem = (byte*)pMemoryMng-&gt;Alloc(voicememsize);<br>
&gt;    memset( voicemem, 0, voicememsize );<br>
&gt;<br>
&gt;    // raw voice input buffer<br>
&gt;    pCodecRawBuffer = voicemem;<br>
&gt;    pCodecRawBufferCur = pCodecRawBuffer;<br>
&gt;    //<br>
&gt;    voicemem += Cvoicecodecrawbuffersize;<br>
&gt;<br>
&gt;    // input/output voice buffer<br>
&gt;    pCodecBuffer = voicemem;<br>
&gt; }<br>
&gt;<br>
&gt;<br>
&gt; TVoiceCodec::~TVoiceCodec()<br>
&gt; {<br>
&gt;    if ( pCodecEncoderState )<br>
&gt;    {<br>
&gt;       speex_preprocess_state_destroy( pPreprocessorState );<br>
&gt;       speex_encoder_destroy( pCodecEncoderState );<br>
&gt;       speex_bits_destroy( &amp;codecBits );<br>
&gt;       pCodecEncoderState = NULL;<br>
&gt;    }<br>
&gt;<br>
&gt;    if ( pCodecDecoderState )<br>
&gt;    {<br>
&gt;       speex_decoder_destroy( pCodecDecoderState );<br>
&gt;       speex_bits_destroy( &amp;codecBits );<br>
&gt;       pCodecDecoderState = NULL;<br>
&gt;    }<br>
&gt; }<br>
&gt;<br>
&gt;<br>
&gt; void TVoiceCodec::setSampleRate( int samplerate )<br>
&gt; {<br>
&gt;    sampleRate = samplerate;<br>
&gt;<br>
&gt;    // determine the mode<br>
&gt;    int modeID = -1;<br>
&gt;<br>
&gt;    // speex has limits [6000 - 48000]<br>
&gt;    if ( sampleRate &gt; 48000 )<br>
&gt;       return;<br>
&gt;<br>
&gt;    if ( sampleRate &gt; 25000 )<br>
&gt;       modeID = SPEEX_MODEID_UWB;<br>
&gt;    else if ( sampleRate &gt; 12500 )<br>
&gt;       modeID = SPEEX_MODEID_WB;<br>
&gt;    else if ( sampleRate &gt;= 6000 )<br>
&gt;       modeID = SPEEX_MODEID_NB;<br>
&gt;    else<br>
&gt;       return;<br>
&gt;<br>
&gt;    // set up mode<br>
&gt;    pMode = speex_lib_get_mode( modeID );<br>
&gt; }<br>
&gt;<br>
&gt; void TVoiceCodec::setupEncoder( uint quality, uint complexity  )<br>
&gt; {<br>
&gt;    encoderQuality = quality;<br>
&gt;    encoderComplexity = complexity;<br>
&gt;<br>
&gt;    // catch invalid sample rates resulting in invalid mode<br>
&gt;    if ( !pMode )<br>
&gt;       return;<br>
&gt;    //<br>
&gt;    assert( ( pCodecEncoderState == NULL ) &amp;&amp; &quot;encoder already initialized&quot;<br>
&gt; );<br>
&gt;    //<br>
&gt;    int enabled   = 1;<br>
&gt;    int disabled  = 0;<br>
&gt;    //<br>
&gt;    float highpass = 80;<br>
&gt;<br>
&gt;    // setup encoder<br>
&gt;    pCodecEncoderState = speex_encoder_init( pMode );<br>
&gt;    //<br>
&gt;    speex_encoder_ctl( pCodecEncoderState, SPEEX_SET_SAMPLING_RATE,<br>
&gt; &amp;sampleRate );<br>
&gt;    speex_encoder_ctl( pCodecEncoderState, SPEEX_SET_COMPLEXITY,<br>
&gt; &amp;encoderComplexity );<br>
&gt;    speex_encoder_ctl( pCodecEncoderState, SPEEX_SET_QUALITY,<br>
&gt; &amp;encoderQuality );<br>
&gt;    speex_encoder_ctl( pCodecEncoderState, SPEEX_SET_VBR,<br>
&gt; &amp;disabled );<br>
&gt;    speex_encoder_ctl( pCodecEncoderState, SPEEX_SET_DTX,<br>
&gt; &amp;disabled );<br>
&gt;<br>
&gt;    // init encoder<br>
&gt;    speex_bits_init( &amp;codecBits );<br>
&gt;    speex_bits_reset( &amp;codecBits );<br>
&gt;<br>
&gt;    // determine encoded bytes per frame with spx_int16_t type, speex can<br>
&gt; work with float;s, but not in this engine<br>
&gt;    speex_encode_int( pCodecEncoderState, (spx_int16_t*)pCodecBuffer,<br>
&gt; &amp;codecBits );<br>
&gt;    encodedFrameBytes = (uint)speex_bits_nbytes( &amp;codecBits );<br>
&gt;<br>
&gt;    // setup preprocessor<br>
&gt;    speex_encoder_ctl( pCodecEncoderState, SPEEX_GET_FRAME_SIZE,<br>
&gt; &amp;encoderFrameSize );<br>
&gt;    //<br>
&gt;    pPreprocessorState = speex_preprocess_state_init( encoderFrameSize,<br>
&gt; sampleRate );<br>
&gt;    //<br>
&gt;    speex_preprocess_ctl( pPreprocessorState, SPEEX_PREPROCESS_SET_DENOISE,<br>
&gt; &amp;enabled );<br>
&gt;    speex_preprocess_ctl( pPreprocessorState, SPEEX_PREPROCESS_SET_VAD,<br>
&gt; &amp;disabled );<br>
&gt; }<br>
&gt;<br>
&gt; void TVoiceCodec::setupDecoder()<br>
&gt; {<br>
&gt;    // catch invalid sample rates resulting in invalid mode<br>
&gt;    if ( !pMode )<br>
&gt;       return;<br>
&gt;    //<br>
&gt;    assert( ( pCodecDecoderState == NULL ) &amp;&amp; &quot;decoder already initialized&quot;<br>
&gt; );<br>
&gt;    //<br>
&gt;    int enabled = 1;<br>
&gt;    //<br>
&gt;    pCodecDecoderState = speex_decoder_init( pMode );<br>
&gt;    speex_decoder_ctl( pCodecDecoderState, SPEEX_SET_SAMPLING_RATE,<br>
&gt; &amp;sampleRate );<br>
&gt;    speex_decoder_ctl( pCodecDecoderState, SPEEX_GET_FRAME_SIZE,<br>
&gt; &amp;decoderFrameSize );<br>
&gt;    speex_decoder_ctl( pCodecDecoderState, SPEEX_SET_ENH,<br>
&gt; &amp;enabled );<br>
&gt;    //<br>
&gt;    speex_bits_init( &amp;codecBits );<br>
&gt; }<br>
&gt;<br>
&gt; uint TVoiceCodec::encode( byte *rawsoundbuffer, uint length, char<br>
&gt; *bitbuffer, float gain )<br>
&gt; {<br>
&gt;    if( !pCodecEncoderState )<br>
&gt;       return 1;<br>
&gt;<br>
&gt;    // copy raw voice data to temporary codec raw voice data buffer<br>
&gt;    memcpy( pCodecRawBufferCur, rawsoundbuffer, length );<br>
&gt;    pCodecRawBufferCur += length;<br>
&gt;<br>
&gt;    // determine the size of data<br>
&gt;    uint buffersize = (int)( pCodecRawBufferCur - pCodecRawBuffer );<br>
&gt;<br>
&gt;    // do we have enough data for encoding?<br>
&gt;    if ( buffersize &lt; encoderFrameSize )<br>
&gt;    {<br>
&gt;       //pLog-&gt;Add(&quot;codec: encoder: return: buffersize: %d: needtoencode<br>
&gt; %d&quot;, buffersize, encoderFrameSize);<br>
&gt;       return 0;<br>
&gt;    }<br>
&gt;<br>
&gt;    int encodedbytes  = 0;<br>
&gt;    int pos = 0;<br>
&gt;    // while we have enough data<br>
&gt;    while( (uint)( pCodecRawBufferCur - pCodecRawBuffer ) &gt;=<br>
&gt; encoderFrameSize )<br>
&gt;    {<br>
&gt;       // copy data from temporary buffer to codec buffer<br>
&gt;       memcpy( pCodecBuffer, pCodecRawBuffer, encoderFrameSize );<br>
&gt;<br>
&gt;       // move memory of temporary buffer<br>
&gt;       memmove( pCodecRawBuffer, pCodecRawBuffer + encoderFrameSize,<br>
&gt; buffersize - ( pos + encoderFrameSize ) );<br>
&gt;       pCodecRawBufferCur -= encoderFrameSize;<br>
&gt;<br>
&gt;       // increase current pos<br>
&gt;       pos += encoderFrameSize;<br>
&gt;<br>
&gt;       //encode<br>
&gt;       speex_bits_reset( &amp;codecBits );<br>
&gt;       //<br>
&gt;       speex_encode_int( pCodecEncoderState, (spx_int16_t*)pCodecBuffer,<br>
&gt; &amp;codecBits );<br>
&gt;       //<br>
&gt;       int nb = speex_bits_nbytes( &amp;codecBits );<br>
&gt;       encodedbytes += speex_bits_write( &amp;codecBits,<br>
&gt; &amp;bitbuffer[encodedbytes], nb );<br>
&gt;    }<br>
&gt;<br>
&gt;    //pLog-&gt;Add(&quot;buffersize: %d: total left: %d enc buffersize: %d&quot;, length,<br>
&gt; inputBufferArray.Count(), encodedbytes );<br>
&gt;    return encodedbytes;<br>
&gt; }<br>
&gt;<br>
&gt; uint TVoiceCodec::decode( char *bitbuffer, uint length, byte *samplearray,<br>
&gt; float gain )<br>
&gt; {<br>
&gt;    // return if decoder is not initialized<br>
&gt;    if( !pCodecDecoderState )<br>
&gt;       return 0;<br>
&gt;<br>
&gt;    // return if there is not enough data to decode<br>
&gt;    if ( length &lt; encodedFrameBytes )<br>
&gt;       return 0;<br>
&gt;<br>
&gt;    int buffersize       = length;<br>
&gt;    uint decodedbytes    = 0;<br>
&gt;    int pos              = 0;<br>
&gt;    //<br>
&gt;    while( (int)buffersize - (int)encodedFrameBytes &gt;= 0 )<br>
&gt;    {<br>
&gt;       speex_bits_reset( &amp;codecBits );<br>
&gt;       speex_bits_read_from( &amp;codecBits, bitbuffer + pos, encodedFrameBytes<br>
&gt; );<br>
&gt;       //<br>
&gt;       if( speex_decode_int( pCodecDecoderState, &amp;codecBits,<br>
&gt; (spx_int16_t*)pCodecBuffer ) == 0 )<br>
&gt;       {<br>
&gt;          memcpy( &amp;samplearray[decodedbytes], pCodecBuffer, decoderFrameSize<br>
&gt; );<br>
&gt;          decodedbytes += decoderFrameSize;<br>
&gt;       }<br>
&gt;       //<br>
&gt;       pos += encodedFrameBytes;<br>
&gt;       buffersize -= encodedFrameBytes;<br>
&gt;    }<br>
&gt;<br>
&gt;    return decodedbytes;<br>
&gt; }<br>
&gt;<br>
&gt; -----------------------<br>
&gt; code<br>
&gt;<br>
&gt; Lp, Tim<br>
&gt; +--------------------------+<br>
&gt; | email: <a href="mailto:rico@gama.us">rico@gama.us</a>      |<br>
&gt; | www:    <a href="http://gama.us" target="_blank">http://gama.us</a>   |<br>
&gt; |--------------------------|<br>
&gt; | tel:    00386 31 457 627 |<br>
&gt; +--------------------------+<br>
&gt;<br>
&gt;<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <a href="http://lists.xiph.org/pipermail/speex-dev/attachments/20090903/5a8cf708/attachment.htm" target="_blank">http://lists.xiph.org/pipermail/speex-dev/attachments/20090903/5a8cf708/attachment.htm</a><br>
<br>
------------------------------<br>
<br>
_______________________________________________<br>
Speex-dev mailing list<br>
<a href="mailto:Speex-dev@xiph.org">Speex-dev@xiph.org</a><br>
<a href="http://lists.xiph.org/mailman/listinfo/speex-dev" target="_blank">http://lists.xiph.org/mailman/listinfo/speex-dev</a><br>
<br>
<br>
End of Speex-dev Digest, Vol 64, Issue 2<br>
****************************************<br>
</blockquote></div><br>