[Speex-dev] Newbie - Encoding PCM

Jean-Marc Valin Jean-Marc.Valin at USherbrooke.ca
Wed Jun 22 16:07:44 PDT 2005


Please read the manual. Then you can start with the sampleenc/sampledec
examples in appendix and (optionally) the speexenc/speexdec programs in
the src/ directory.

	Jean-Marc

Le mercredi 22 juin 2005 à 12:31 +0200, Michele "O-Zone" Pinassi a
écrit :
> Hi all,
> i've to encode voice from a voicemodem. I choose speex 1.0.5 for its quality 
> in voice encoding. I've tried to implement an encoder but unsuccesfully. 
> Here's my code:
> 
> /* ============ SPEEX stream ENCODER 
> ============================================ */
> int SPEEX_EncodePCM(struct _IDA_ClientSocket *IDA,char *buffer,unsigned char 
> *PCM,int num_samples) {
> /* buffer point to the output buffer 
> PCM point to the numsamples bytes 8bit - 8Khz PCM from the modem 
> num_samples is, commonly, 16000
> */
>     int ret,c,d;
>     short int PCM_F[160];
>     for(c=0;c<num_samples;c++) {
> 	/* tempbuf 0<-127->256 */
> 	/* pcmbuff -32786 <- 0 -> +32786 */
> 	PCM_F[d] = (PCM[c] << 8)^0x8000;
> 	d++;
> 	if(d > 160) {
> 	    speex_bits_reset(&IDA->speex_bits);
> 	    speex_encode_int(IDA->speex_state,PCM_F,&IDA->speex_bits);
> 	    speex_bits_insert_terminator(&IDA->speex_bits);
> 	    d = speex_bits_write(&IDA->speex_bits, buffer, 200);
> 	    *buffer += d;
> 	    ret += d;
> 	    d = 0;
> 	}
>     }
>     return ret;
> }
> 
> int SPEEX_Init(struct _IDA_ClientSocket *IDA) {
>     /* speex_init_header(&IDA->speex_header,8000,1,IDA->speex_mode); */
>     IDA->speex_mode = speex_lib_get_mode(SPEEX_MODEID_NB);
>     speex_bits_init(&IDA->speex_bits);
>     IDA->speex_state = speex_encoder_init(IDA->speex_mode);
> }	
> 
> int SPEEX_Close(struct _IDA_ClientSocket *IDA) {
>     speex_bits_destroy(&IDA->speex_bits);
>     speex_encoder_destroy(IDA->speex_state);
> }
> 
> "IDA" struct containts:
> 
> struct _IDA_ClientSocket {
> [...]
>      void *speex_state;
>      SpeexHeader speex_header;
>      SpeexBits speex_bits;
>      SpeexMode *speex_mode;
> };
> 
> so i call SPEEX_Init before start encoding and SPEEX_Encode on every 16000 
> Bits of the PCM stream from the modem.
> 
> The result is a strange file that contains a lot of zeros and no audio 
> data :-(
> 
> Someon can help me pointing to the right direction ? Thanks !
> 
> _______________________________________________
> Speex-dev mailing list
> Speex-dev at xiph.org
> http://lists.xiph.org/mailman/listinfo/speex-dev



More information about the Speex-dev mailing list