Dithering and silence

Discussions on sound production outside the synthesizer such as mixing, processing, recording, editing and mastering.

Dithering and silence

Postby joeboy » Sat Oct 21, 2017 7:16 am

So I'm on/off writing an audio program in C, just for learning's sake. All internal sound values are 32 bit floats, but they are converted to 16 bit integers before being written to the sound card. I've been told that I need to dither so that I may avoid distortion caused by rounding errors. I've used this algorithm to do so.

My untrained ears can't really hear a difference for the most part, but during moments of complete silence (that is, when the program should normally be writing nothing but zero value integers to the sound card) I can hear the dithering noise. I'd like to get rid of it. This is easy; I just need to tell the function that takes a float and returns a dithered int to return a flat 0 when the input is 0.0.

But I'm not sure about the theory behind this. My main question is: Is dithering only effective when applied constantly across the entire signal, or can it skip over silent values without consequence? Will distortion still be removed?

The fact that I cannot hear the distortion that dithering is meant to combat makes it difficult for me to judge for myself.
User avatar
joeboy
Junior Member
Junior Member
 
Posts: 100
Joined: Tue Jul 17, 2012 1:22 am
Location: 熊本
Gear: ax-80, jx-8p, v-synth, monotribe, ПИФ, tx81z, sy35, tg77

Re: Dithering and silence

Postby madtheory » Sat Oct 21, 2017 2:23 pm

O cool, I am about to try this too. Reading the Pirkle book. Hurts my head lol.

To answer your question- yes you could turn dither off when your algorithm is not producing any sound. But it's odd that it is audible, by itself. System noise would usually be the same, or higher. The analogue circuits. Unless you've really high end stuff?

Dither gives a measurable improvement in accuracy when converting sample values from higher to lower. You'll hear a difference in the sense of space and imaging, because the accuracy only comes into play at the low end of the "level" scale. You'll see that in the code there, operating on the 2 LSBs. So it affects reverb tails primarily. Pro tip- it's not really audible in mono, mainly in stereo! Because mono doesn't really encode "space".

16 bit dither is down around -90dB below full scale. So if you're hearing it, all the time, there is something wrong. Probably with the math. With my poor math, that algorithm seems OK to me. It says it's noise shaped, so that should make the perceived noise even lower than -90dB. But hey, I've dyscalculia. I'd question what the DC offset thing is for?

Maybe try without the noise shaping? Or try 24 bit? That puts the dithered noise floor down to around -140dB below full scale. Maybe your soundcard driver doesn't deal with 16 bit properly?

Or maybe do a blind AB test first! It could be you're hearing it because you know it's there. Your soundcard must be pretty expensive if its self noise is less than the dither noise...
User avatar
madtheory
Supporting Member!
Supporting Member!
 
Posts: 4971
Joined: Mon May 01, 2006 12:45 pm
Location: Cork, Ireland
Real name: Tomas Mulcahy
Gear: Pro Tools, Komplete, MIDIQuest, Novation KSR, Casio FZ1+SK5, Korg Legacy, Theremin, Digi Vocalist, Quadravrb+, Kaoss Pads1+2, SPD11, OB Cyclone.
Band: Minim

Re: Dithering and silence

Postby meatballfulton » Sat Oct 21, 2017 4:19 pm

From Wikipedia, for what it's worth

If the signal being dithered is to undergo further processing, then it should be processed with a triangular-type dither that has an amplitude of two quantisation steps; for example, so that the dither values computed range from, say, −1 to +1, or 0 to 2.[12] This is the "lowest power ideal" dither, in that it does not introduce noise modulation (which would manifest as a constant noise floor), and completely eliminates the harmonic distortion from quantisation. If a colored dither is used instead at these intermediate processing stages, then frequency content may "bleed" into other frequency ranges that are more noticeable, which could become distractingly audible.

If the signal being dithered is to undergo no further processing — if it is being dithered to its final result for distribution — then a "colored" dither or noise shaping is appropriate. This can effectively lower the audible noise level, by putting most of that noise in a frequency range where it is less critical.

I listened to Hatfield and the North at Rainbow. They were very wonderful and they made my heart a prisoner.
User avatar
meatballfulton
Moderator
Moderator
 
Posts: 5577
Joined: Wed Apr 13, 2005 9:29 pm
Gear: Live 9, Logic Pro X

Re: Dithering and silence

Postby joeboy » Sat Oct 21, 2017 4:24 pm

Thanks for the reply. It's good to know that my stopgap measure of returning a straight 0 is ok. But you're right; I shouldn't be able to hear the dither noise anyway. I put some printfs in the function and it looks like for inputs of 0.0, the final dithered int sometimes wraps around to the neighborhood of 65535, which explains the very audible hiss. I must have screwed something up in my implementation.

I'd say that I only understand 80% of it anyway. I'm also not sure what the DC offset is meant to do. At the moment my efforts are focused on properly reading and sequencing notes. I just threw the dither in there because everybody said you need to dither when dropping down from a float. If there is more basic and better-annotated algorithm out there, I'd like to read about it. Most of my searches only returned image dithering examples.
User avatar
joeboy
Junior Member
Junior Member
 
Posts: 100
Joined: Tue Jul 17, 2012 1:22 am
Location: 熊本
Gear: ax-80, jx-8p, v-synth, monotribe, ПИФ, tx81z, sy35, tg77

Re: Dithering and silence

Postby joeboy » Sun Oct 22, 2017 6:50 am

Well I'm a remarkably stupid person sometimes. It seems that somewhere in the header file, the buffer that writes each byte to the soundcard was inadvertently changed from type uint8_t to uint32_t. Can't believe that slipped past me. For whatever reason, storing a near-silent 1 byte amplitude value as a uint32_t has the effect of amplifying the noise greatly--but only in the left channel. The dither noise is now imperceptible over the ambient noise of my remarkably un-high-end computer.

If you look through my post history you'll see that a lot of my programming related questions end with dumb revelations like this. Thanks for the help/info in any case.
User avatar
joeboy
Junior Member
Junior Member
 
Posts: 100
Joined: Tue Jul 17, 2012 1:22 am
Location: 熊本
Gear: ax-80, jx-8p, v-synth, monotribe, ПИФ, tx81z, sy35, tg77

Re: Dithering and silence

Postby clubbedtodeath » Sun Oct 22, 2017 9:34 am

Love to see people doing hardcore stuff like this*. Good luck, Joey.

[*] Any tips needed on old-school C/C++, there's quite a few of us seriously beardy IT types about to ask.
Last edited by clubbedtodeath on Sun Oct 22, 2017 7:13 pm, edited 1 time in total.
User avatar
clubbedtodeath
Expert Member
Expert Member
 
Posts: 1011
Joined: Fri Apr 10, 2009 12:12 am
Location: Older Scotia

Re: Dithering and silence

Postby meatballfulton » Sun Oct 22, 2017 1:35 pm

Don't feel bad, the French blew up one of their early space rockets just because of a bad software conversion. Oops!

Image
I listened to Hatfield and the North at Rainbow. They were very wonderful and they made my heart a prisoner.
User avatar
meatballfulton
Moderator
Moderator
 
Posts: 5577
Joined: Wed Apr 13, 2005 9:29 pm
Gear: Live 9, Logic Pro X

Re: Dithering and silence

Postby madtheory » Mon Oct 23, 2017 12:40 pm

clubbedtodeath wrote:[*] Any tips needed on old-school C/C++, there's quite a few of us seriously beardy IT types about to ask.

Awesome. I'll be back :)
meatballfulton wrote:Don't feel bad, the French blew up one of their early space rockets just because of a bad software conversion. Oops!

Image

:love:
User avatar
madtheory
Supporting Member!
Supporting Member!
 
Posts: 4971
Joined: Mon May 01, 2006 12:45 pm
Location: Cork, Ireland
Real name: Tomas Mulcahy
Gear: Pro Tools, Komplete, MIDIQuest, Novation KSR, Casio FZ1+SK5, Korg Legacy, Theremin, Digi Vocalist, Quadravrb+, Kaoss Pads1+2, SPD11, OB Cyclone.
Band: Minim


Return to Sound Production

Who is online

Users browsing this forum: No registered users and 4 guests