Re: Calculating peak level in db
Re: Calculating peak level in db
- Subject: Re: Calculating peak level in db
- From: Herbie Robinson <email@hidden>
- Date: Mon, 14 Oct 2002 23:19:17 -0400
Unfortunately, if you put in numbers greater than 16384 through that
algorithm, it isn't bit accurate. All the numbers will be one too
low (16385 -> 16384, etc).
Well, the trick I use is to use convergent rounding when converting
from floats to shorts, and my underlying concern is with preserving
exact symmetry of the waveform - that is the case if I map floats to
+- 32767 (so that 16bit zero = true DC). A sampled sinusoid that
touched both -32768 and +32767 would have a true DC point 0.5 below
16bit zero, on rendering to analogue. So an ADC that returned such
values from an ideal input sinusoid would be doing something wrong,
in my view. A sinusoid that somehow spanned +- 32768 (which would of
course need something larger than 16bits to hold it), would likewise
have true DC at zero.
To cut a long story short (now there's a pun!), and excluding the
matter of dithering, I can read 16bit samples into floats, scaling
by 1/32768 (sadly, I don't know how to apply shift to a float yet,
in ANSI C), and convert said floats back to shorts using convergent
rounding (~not~ a 'simple' C cast - and on Intel it requires but
three _asm instructions) after scaling by 32767, and amazingly
enough, the output samples are bit for bit identical to the input
ones.
For example - 16bit input = 16384.
floatsam = 16384 / 32768 = 0.5;
0.5 * 32767 = 16383.5;
After convergent rounding, final sample = 16384.
Only if you use a truncating C cast will you end up with a different
value. If CoreAudio is not preserving exact symmetry of the waveform
through such conversions, I guess we have a small but perfectly
formed DC offset somewhere!
--
-*****************************************
**
http://www.curbside-recording.com/ **
******************************************
_______________________________________________
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.