QUOTE(aristotel @ Jan 6 2004, 06:04 PM)
Hello 2bDecided..your post is helpful and thank you lots for your it. I have the following questions so i can finnaly get my head around this.
For two bits of triangular probability noise i could use:
(rand() % 3) + (rand() % 3) - 2;
This will give me a range of -2 to 2. The possible values are -2,-1,0,1,2. THat is five of them with 0 being the absolute centre. Does this not result in a dither without DC bias?
On your example, you generate a true 2 bit noise range of 4 values. There is no clear MIDDLE value. It this the case where the use of +0.5 or -0.5 is necessary?
Also, I assume that in order to add or subtract the 0.5, i need to be processing the samples in 32 bit float precision, so hopefully i can find some information on how to do that if my earlier guess in this post is wrong.
You're getting confused between the value before and after truncation. It's helpful if you think in binary about what you're doing before truncation. It's also convention to quote values in decimal relative to the last remaining bit being 1 after truncation.
So, thinking in binary, (rand() %3) apparently gives you 0, 1, or 2 i.e. 00, 01, or 10. What happened to 11?! So that's the wrong amplitude to start with.
If the last remaining bit after truncation has a value of 1, then the bit that was to its right before truncation has a relative value of 0.5. So, just like you, I was simply subtracting 2 before truncation - no floating point necessary.
QUOTE
U mentioned the addition of 2 bits worth of noise in the example of going from 16 to 14 bit. Does this mean you believe that the amount of bit of noise to add is equal to the amount of bits you are about to loose by truncating?
An easy rule is that the rectangular dither should exactly fill the bits you remove (no more, no less), and that triangular dither can be created by adding two independent rectangular dither sources. This makes things very easy.
so 16 to 8 bits conversion is
xxxxxxxxyyyyyyyy > xxxxxxxx
you need two rectangular dither generators (i.e. two pseudo random number generators) ranging from 00000000 to 11111111 i.e. 0 to 255. You don't want 256 (100000000) because that gives you an amplitude of 1 too many.
(Think about it with a decimal example: it's just like 0,1,2,3,4,5,6,7,8,9 gives you ten possible values, but 0,1,2,3,4,5,6,7,8,9,10 gives you eleven. So unless you want a range of eleven, then if you include the number 0, you don't include the number 10. It's the same here, but in binary)
Finally, digital audio isn't DC biased one way or the other - it's just that it can go one more value negative than positive. When CDs were introduced, "good" converters had DC offsets of, say, 40 or 50 (measured in units of 1 LSB at 16-bit) so it was probably never even considered.
Hope this helps. I think the contributors to this thread deserve a credit and/or reference in your project, and a drink!
Cheers,
David.