Re: Convert to float and more
Re: Convert to float and more
- Subject: Re: Convert to float and more
- From: Darrin Cardani <email@hidden>
- Date: Wed, 4 Jun 2003 11:21:35 -0500
At 10:46 AM +0200 6/4/03, Mark's Studio wrote:
All my drawing and DSP code use floats, so if the original sound format
is 16bit i do a lot of sample/32768.
I was thinking of converting the samples to float when importing the
file, but that will double the data size, so i still need to decide
what's best.
I tried to search the archives for the fastest way to convert from int
to float and back. but did not find much,
someone mentioned there might be a altivec snippet for converting?
Converting from int to float can be done with a table. If you're
using 16-bit values, and you want to convert to floats between -1 and
1, just make a 64k table of floats where each value is the index
(cast to a 16-bit signed int) divided by 32k. But I would profile
what the compiler does to make sure that's really where your slowdown
is. Often, with anything bigger than an 8-bit lookup table, just
doing the work is likely to be as fast as or faster than a lookup.
Converting back I would let the compiler do it if you aren't using
AltiVec. But there may be faster ways.
As for AltiVec, there are 2 instructions - one for converting from
fixed to float and the other for converting back. They are vec_ctf ()
to convert from fixed (where you specify where the decimal is), and
vec_cts () to convert from float to signed int. You'll have to do a
vec_perm () to pull out the upper 4 values and put them into a long
vector before converting them, and then again for the lower 4. So
basically, converting 8 16-bit signed ints to 8 floats would take
about 4 instructions (vec_perm, vec_ctf, vec_perm, vec_ctf). You can
do the opposite to convert back.
I highly recommend joining the AltiVec list at
<
http://www.simdtech.org/> for help with AltiVec code.
I also want to import/export MP3 and other compressed formats what is
the best way to do that?
QuickTime.
Darrin
--
Darrin Cardani - email@hidden
President, Buena Software, Inc.
<
http://www.buena.com/>
Video, Image and Audio Processing Development
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.