Re: Calculating peak level in db
Re: Calculating peak level in db
- Subject: Re: Calculating peak level in db
- From: Kurt Bigler <email@hidden>
- Date: Mon, 14 Oct 2002 16:57:28 -0700
on 10/14/02 4:17 PM, Richard Dobson <email@hidden> wrote:
>
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.
But such a sinusoid would never exist unless one really contrived to create
it. It would require not just scalling but explicitly adding a DC offset in
order to acheive that - unless you are talking about an A/D that perversely
"centered" its analog zero point between the two extremes of its digital
output range.
I think what was being talked about here is scaling by 32768 but not adding
any offset. This results in a positive clip that does not match the
negative clip. So there is slightly less headroom on the + side than on the
- side, by about 0.0003 db (20 log 32767/32768). This is not a loss of
headroom that anyone is likely to worry about. So yes, if you clip a sine
wave significantly in this situation, then you will end up with a DC offset
accompanying the clip. But even if you sent a full 1.0 float amplitude sine
wave to an output with asymmetrical clipping involved along the way, you
would get almost no DC offset, and in fact almost no distortion to speak of.
(The same kind of issue applies on A/D input, but it would be impossibly
difficult to arrange for the exact amplitude that would clip on the + side
but not on the - side.) If you are worried about that amount of distortion,
don't push the headroom to its limit. If you back off even one thousandth
of a db you won't run into the problem. If you need to do signal testing
with near-full amplitude sine waves then you can go to the extra trouble to
back off that much.
>
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!
_______________________________________________
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.