Mashal al-shboul
2012-Mar-09 16:36 UTC
[Speex-dev] using unsigned short instead of short for input frame
Thanks for your appreciated help. i found casting fromunsigned short to short gives different value: unsigned short FFFF=65535 where short FFFF= -1. however, can i configure speex codec (specifically speex_encode_int function) to take input of type unsigned short instead of short so that i avoid casting errors ? Regards, Mashal ________________________________ From: Yanick Bourbeau <ybourbeau at mrgtech.ca> To: Mashal al-shboul <shboul8989 at yahoo.com> Sent: Friday, March 9, 2012 4:29 PM Subject: Re: [Speex-dev] using unsigned short instead of short for input frame uint16_t is usually a typedef of an unsigned short or int depending of the platform. It is supposed to work. About unsigned short to short conversion it is normal since unsigned short starts at 0 and short starts at -((2^16)/2)-1 [-32767]. If you really want to keep the same numeric value you could cast the short to unsigned int (32bytes) and add 32767 to the value. On 12-03-09 02:59 AM, Mashal al-shboul wrote: Hi Speex Experts,Thanks for this great mailing list.> > >???? i want to compress a frame of(uint16_t) audio samples, i found that speex codec assumes input frame of type short. fortunately,both data types are of? 2-bytes , so my questions : >- can i cast data types for input to speex?, if so,can i cast uint16_t to unsigned short and still be accepted by speex ? , >because i found converting from uint16_t to short does completely change the values of the samples(unsigned to signed !). > > >Any help or suggestion is appreciated. Thanks in advance. > > >Regards, >Mash'al > > > > >_______________________________________________Speex-dev mailing list Speex-dev at xiph.org http://lists.xiph.org/mailman/listinfo/speex-dev e -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.xiph.org/pipermail/speex-dev/attachments/20120309/fb4e5810/attachment.htm
Hello! I would like to ask if somebody has managed to use/build Speex in VC2010 and if yes, how we managed to do that. Thank you very much. Hermann
Steve Checkoway
2012-Mar-10 20:06 UTC
[Speex-dev] using unsigned short instead of short for input frame
On Mar 9, 2012, at 8:36 AM, Mashal al-shboul wrote:> i found casting from unsigned short to short gives different value: unsigned short FFFF=65535 where short FFFF= -1.Right.> however, can i configure speex codec (specifically speex_encode_int function) to take input of type unsigned short instead of short so that i avoid casting errors ?I don't know about that, but it should be easy to convert your samples. You want to convert from the range [0, 2^16 - 1] to [-2^15, 2^15 - 1]. Thus, all you have to do is subtract 2^15 = 0x8000 from each of them: steve$ cat a.c #include <stdio.h> #include <inttypes.h> #define convert(x) (int16_t)((x) - 0x8000) int main() { uint16_t max = 0xffff; uint16_t mid = 0x8000; uint16_t min = 0x0000; printf("%hx -> %hd\n", max, convert(max)); printf("%hx -> %hd\n", mid, convert(mid)); printf("%hx -> %hd\n", min, convert(min)); return 0; } steve$ gcc -Wall a.c steve$ ./a.out ffff -> 32767 8000 -> 0 0 -> -32768 As you can see, the maximum value 0xffff is indeed converted to 2^15 - 1, the mid point 0x8000 is converted to 0, and the minimum value 0 is converted to -2^15. -- Stephen Checkoway
Possibly Parallel Threads
- Help about error in linking to libspeex.a
- converting unsigned short sample to signed short sample
- converting unsigned short sample to signed short sample
- converting unsigned short sample to signed short sample
- converting unsigned short sample to signed short sample