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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.xiph.org/pipermail/speex-dev/attachments/20061215/2e728872/attachment.html
I?d say this is out of scope for this mailing list. Any how, you can?t just shift a signed number by 8 (multiplying with 256) without handling the signedness-bit. PCM 16-bit samples are stored as signed values. Try something simpler which works first and then optimize your code afterwards. unsigned char inSamp; short s1, outSamp; s1 = (short) inSamp; s1 -= 128; s1 *= 256; outSamp = s1; It?s probably possible to reduce the complexity of this using bitshifts, unless you know what you are doing and are in a lot of need for speed I don?t see the reason. //JT //JT -----Ursprungligt meddelande----- Fr?n: speex-dev-bounces@xiph.org [mailto:speex-dev-bounces@xiph.org] F?r yaseminyilmaz Skickat: den 15 december 2006 17:46 Till: speex-dev@xiph.org ?mne: [Speex-dev] About "Convert 8->16 bits" 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.xiph.org/pipermail/speex-dev/attachments/20061215/999eb661/attachment-0001.htm
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@xiph.org > http://lists.xiph.org/mailman/listinfo/speex-dev