[speex-dev] About reducing noise..

Jean-Marc Valin Jean-Marc.Valin at USherbrooke.ca
Mon Feb 23 21:36:20 PST 2004


Hi,

It's hard to say what the problem is. Common problems are sample
encoding mismatch (16-bit vs. float vs. ulaw, ...) or problems handling
the bits. One other thing is the sampling rate. Speex is optimized for
8, 16 and 32 kHz. Also, are you feeding it a mono stream?

        Jean-Marc

Le mar 24/02/2004 à 00:42, Ali Naqi a écrit :
> Hello, 
> 
>  
> 
> When I decode a recoded sound encoded by speex, it has too much noise.
> The noise is “slightly” reduced if I set the quality to 10. How do I
> get rid of this noise? The code is as follows…
> 
>  
> 
>  
> 
> For encoding …
> 
>  
> 
> state = speex_encoder_init ( &speex_nb_mode );
> 
>  
> 
> tmp = 7;
> 
> speex_encoder_ctl ( state, SPEEX_SET_MODE, &tmp);
> 
>  
> 
> // set quality
> 
> tmp = 10;
> 
> speex_encoder_ctl ( state, SPEEX_SET_QUALITY, &tmp);
> 
>  
> 
> // initialize bits
> 
> speex_bits_init(&bits);
> 
>  
> 
>  
> 
> while( 1 )
> 
> {
> 
>       // read FRAME_SIZE bytes from buffer
> 
>       // convert to short
> 
>       for ( int i = 0; i < FRAME_SIZE; i++)
> 
>             in[i] = out_buffer[i];
> 
>  
> 
>       speex_bits_reset(&bits);
> 
>  
> 
>       // encode
> 
>       speex_encode ( state, in, &bits);
> 
>  
> 
>       // copy bits to an array of chars 
> 
>       nbBytes = speex_bits_write ( &bits, cbits, 200);
> 
>  
> 
>       // copy these cbits into a buffer
> 
>       CopyBuffer(pBuffer + dwLength, cbits, nbBytes);
> 
>       dwLength += nbBytes;
> 
> }
> 
>  
> 
> // uninitialize
> 
>  
> 
> For decoding …
> 
>  
> 
> SpeexBits bits;
> 
> int i, tmp;
> 
>  
> 
> state = speex_decoder_init(&speex_nb_mode);
> 
> tmp =1;
> 
> speex_decoder_ctl(state, SPEEX_SET_ENH, &tmp);
> 
>  
> 
> speex_bits_init(&bits);
> 
> char temp[10];
> 
> long sizeToRead = 4;
> 
> while(1)
> 
> {
> 
>       int ret = ReadFile(file,temp, sizeToRead , &bytesRead,NULL);
> 
>       if( bytesRead == 0 )
> 
> {
> 
>             break;
> 
>       }
> 
>       nbBytes = atoi(temp);
> 
>       totalBytesRead += bytesRead;
> 
>  
> 
>       ret = ReadFile(file, cbits, nbBytes, &bytesRead, NULL);
> 
>       totalBytesRead += bytesRead;
> 
>       speex_bits_read_from(&bits, cbits, nbBytes);
> 
>       speex_decode(state, &bits, out);
> 
>       for( i=0; i <FRAME_SIZE; i++)
> 
>             buf[i] = (char)out[i];
> 
>       // write to file
> 
> WriteFile(file2, buf, FRAME_SIZE, &bytesWritten, NULL);
> 
>       totalBytesWritten+= bytesWritten;
> 
> }
> 
>  
> 
> I am using wave api for capturing and playing back sound. 
> 
>  
> 
> Please guide me in this problem.
> 
>  
> 
> Regards,
> 
> Ali Naqi Shaheen, 
> 
>  

-- 
Jean-Marc Valin, M.Sc.A., ing. jr.
LABORIUS (http://www.gel.usherb.ca/laborius)
Université de Sherbrooke, Québec, Canada


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: Ceci est une partie de message numériquement signée.
Url : http://lists.xiph.org/pipermail/speex-dev/attachments/20040224/741306d7/signature-0001.pgp


More information about the Speex-dev mailing list