| Matt Barber wrote:
> I'm trying to find out how csound goes about converting from integers
> to floats and floats to integers -- for instance if I read a 16-bit
> sound file in with diskin, does it just divide by 32768 to convert to
> float?
I'm pretty sure the conversion from integer to float when reading
sound files is actually handled by libsndfile:
http://www.mega-nerd.com/libsndfile/
and if that is correct, then yes, for 16 bit sound files it just
divides by 32768.
> Also, when csound writes a 16-bit integer, how is the conversion from
> float back to int handled? It doesn't seem to be a simple
> multiplication by 32767 or 32768 since -1.0 to +1.0 w/ 0dbfs=1.0 seems
> to map back to the asymmetrical -32768 to +32767.
If libsndfile is being used for this, then it is actually just a multiply
by 32768. This is explained more fully here:
http://www.mega-nerd.com/libsndfile/FAQ.html#Q010
> I suppose it could
> just be a multiply by 32768 with the positive value just clipped to
> +32767?
libsndfile does have a mode where values that would exceed the range
allowed by the output file are clipped instead of being allowed to
wrap around. I'm not sure if Csound uses this mode or not.
> Are the values rounded to the nearest integer, or truncated,
> or floored?
Round to nearest integer.
> And, will the same reasoning apply to 24-bit samples in/out?
Yes, but with different divisors and multipliers.
HTH,
Erik |