Re: Convert to float and more
Re: Convert to float and more
- Subject: Re: Convert to float and more
- From: Bill Stewart <email@hidden>
- Date: Wed, 4 Jun 2003 10:31:42 -0700
The absolutely best way to do this is to use the AudioConverter
It will do the conversions for you and we continue to work on this to
make this as fast and efficient as possible. If you can write your own
fast blitters for these conversions...well, good luck to you!:-)
Seriously though - you should use the AudioConverter and not roll your
own. Because you are just doing int->float->int (and no sample rates or
deinterleaving, etc) then you can use the AudioConverterConvertBuffer
call - so its pretty easy... To set up the converter you provide
descriptions - in PublicUtility in the SDK there's a very helpful class
to do exactly this called CAStreamBasicDescription... saves you the
potential knarliness of negotiating the format flags, etc...
Bill
On Wednesday, June 4, 2003, at 09:21 AM, Darrin Cardani wrote:
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.
--
mailto:email@hidden
tel: +1 408 974 4056
________________________________________________________________________
__
"Much human ingenuity has gone into finding the ultimate Before.
The current state of knowledge can be summarized thus:
In the beginning, there was nothing, which exploded" - Terry Pratchett
________________________________________________________________________
__
_______________________________________________
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.