[Speex-dev] About "Convert 8->16 bits"

Jean-Marc Valin jean-marc.valin at usherbrooke.ca
Fri Dec 15 13:46:12 PST 2006


Note that most 8-bit formats are not "linear", but use a logarithmic
scale like u-law or A-law. In that case, the conversion is more tricky,
but I'm sure there's code somewhere to do it.

	Jean-Marc

yaseminyilmaz a écrit :
>  
> 
> Hi everybody,
> 
>  
> 
> I have been using speex-1.2beta1 and my input data is 8-bit unsigned so I
> know that I should convert from 8 to 16 bits. I've done the convertion as
> following.
> 
>  
> 
> for(int i=0; i<160; ++i)
> 
> {
> 
>             input_frame[i] = (short)( (data[2*i] << 8) | data[2*i+1]);
> 
>       }
> 
>  
> 
> When my codec application didn't work right, I think that the reason is an
> error at this convertion. For this aim, I looked at read_samples function in
> speexenc project and I can't understand why the convertion is done in this
> way:
> 
>  
> 
>       for(i=frame_size*channels-1;i>=0;i--)
> 
>       {
> 
>          s[i]=(in[i]<<8)^0x8000;
> 
>       }
> 
>  
> 
> (in my application, channels is 1 and frame_size=160)
> 
>  
> 
> I can understand why shift left 8, but can't why we should do XOR operation
> with 1000 0000 0000 0000. Should I do the convertion operation so and why?
> Please can you clarify? Thanks a lot for your helps.
> 
>  
> 
> Sincerely
> 
> Yasemin
> 
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> 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