Rockbox Technical Forums

Support and General Use => Audio Playback, Database and Playlists => Topic started by: mlind on October 29, 2006, 04:05:39 AM

Title: Dithering & noise shaping - When/where/how?
Post by: mlind on October 29, 2006, 04:05:39 AM
CVS log 27 Oct 20:41 by Thom Johansen:
Quote
Re-enable the currently unused and broken dithering and noise shaping code already in Rockbox.
...
...feedback is welcome.

Is this used only for playback of files needing resampling, or what?

Where should I expect to notice differences?

(yes, I know what it does generally)
Title: Re: Dithering & noise shaping - When/where/how?
Post by: bk on October 29, 2006, 10:22:23 AM
From my quick scanning of the code it looks like dithering from 24/32 bit samples down to the 16 bits supported by the hardware. I don't know what noise shaping refers to.
Title: Re: Dithering & noise shaping - When/where/how?
Post by: perfectdrug on October 29, 2006, 10:28:43 AM
there was discussion and explanation about this yesterday (?) in IRC
you may look there for additional info
Title: Re: Dithering & noise shaping - When/where/how?
Post by: preglow on October 29, 2006, 01:39:03 PM
Dithering has nothing to do with resampling, it has to do with converting from one bit depth to another. Most of our lossy codecs decode to a bit depth that's significantly higher than the 16 bits that are used for output. For example, MP3 is decoded to 29 bits and Ogg Vorbis to 25 bits. When converting this to 16 bits for output, one can just throw away the lower bits, which is default behaviour, or dither. Just throwing away the samples will yield quantisation noise, which is perceived as distortion that changes character with the sound, and can be quite annoying. With dithering enabled, this noise will take the form of uniform background noise, comparable to noise heard in good old-fashioned analogue recordings. Most people will find this noise much more comfortable.

Noise shaping is just shaping the dithering noise to the parts of the spectrum where humans can not hear it so easily. Rockbox uses a simple third order noise shaper which pushes some of the noise up to above 10kHz.
I have prepared a simple but exaggerated example of how this works. The example works with 8 bit output quality, but the principle is the same with 16 bits, just way less pronounced. The file is at:
http://www.pvv.org/~thomj/rockbox/8bitdither.flac
The first segment is default behaviour, the second segment is dithering/noise shaping, and the last is just dithering.

Now, how necessary it is to apply dithering to 16 bit signals is debatable. I myself have no chance in hell to hear the difference. I did a small test, and concluded that I could hear the difference at 13 bits, but no more. However, my hearing probably isn't the finest seen this side of the moon either, so I thought I'd commit to see what people think. I'd be more than happy to remove the entire option and reclaim the code space taken.

BTW: Applying dithering for lossless codecs don't necessarily make sense unless the files have more bits per sample than 16. However, the moment you apply any effects like crossfeed and EQ, dithering will make sense even for files at 16 bits, since these effects operate at a higher precision.
Title: Re: Dithering & noise shaping - When/where/how?
Post by: ryran on October 29, 2006, 02:37:15 PM
Whoa. Thanks for the uber-detailed explanation Thom.
Title: Re: Dithering & noise shaping - When/where/how?
Post by: mlind on October 30, 2006, 04:34:09 AM
Most of our lossy codecs decode to a bit depth that's significantly higher than the 16 bits that are used for output. For example, MP3 is decoded to 29 bits and Ogg Vorbis to 25 bits.

Aha! This I didn't know!
What are the options right now? Can I test with/without myself?
I guess this is used also for the optical output, as it should be limited to 16 bits.
Would you consider this power consuming (thinking battery life) - e.g. compared to using the software eq?

Without testing in THIS context I know I am generally PRO-dither.

Newer Apogee products use a 22kHz "bias" signal instead of audible noise, but that's expensive stuff.
(http://www.apogeedigital.com/products/uv22hr.php)
Title: Re: Dithering & noise shaping - When/where/how?
Post by: preglow on October 30, 2006, 06:24:55 AM
Most of our lossy codecs decode to a bit depth that's significantly higher than the 16 bits that are used for output. For example, MP3 is decoded to 29 bits and Ogg Vorbis to 25 bits.

Aha! This I didn't know!
What are the options right now? Can I test with/without myself?
I guess this is used also for the optical output, as it should be limited to 16 bits.
Would you consider this power consuming (thinking battery life) - e.g. compared to using the software eq?
Without testing in THIS context I know I am generally PRO-dither.
Compared to all the five EQ bands at once, this is cheap. It's probably the same CPU complexity as one/two EQ bands, depending on which DAP you've got.
Yes, it will affect optical out as well, and will probably even benefit more from dithering than the analogue output.
The options are dither on/off :). As for testing, just go ahead and try. The dithering will be switched on and off just by moving the cursor in the dithering selection screen, so should be easy to discover if you hear any difference or not. I'm warning you, though, you'll need a good set of ears to hear this with earphones. I'm generally pro-dithering myself, but I can't for the life of me hear any difference in this case.

Newer Apogee products use a 22kHz "bias" signal instead of audible noise, but that's expensive stuff.
(http://www.apogeedigital.com/products/uv22hr.php)
Yeah, the Apogee stuff is good, but as far as I know, their stuff is based only on designing good noise shapers. What they describe on that page can be achieved with dithering and high order noise shaping alone.
Title: Re: Dithering & noise shaping - When/where/how?
Post by: Llorean on October 30, 2006, 06:39:51 AM
Honestly, all three of the samples at their page hurt my ears quite a bit (dither, uv22hr and truncate) but the *least* painful was their Truncate sample. The audio itself was the worst sounding, but at least the noise wasn't causing me pain while listening to it.
Title: Re: Dithering & noise shaping - When/where/how?
Post by: preglow on October 30, 2006, 06:52:06 AM
Honestly, all three of the samples at their page hurt my ears quite a bit (dither, uv22hr and truncate) but the *least* painful was their Truncate sample. The audio itself was the worst sounding, but at least the noise wasn't causing me pain while listening to it.
This sounds like 3 bit audio or something. Quite useless as a test case, since the noise is so loud it'll start masking out the sound it was supposed to enhance. You'd probably find you come to other conclusions if they had put out more realistic samples.
The dithering noise sounds like it's way too loud anyway, wouldn't be surprised if these samples turn out somewhat biased...
Title: Re: Dithering & noise shaping - When/where/how?
Post by: Llorean on October 30, 2006, 07:03:22 AM
Strange bias where the one I like the least is their preferred sample. ;)

But I listened to your 8-bit dither flac as well, and honestly I like the undithered case there the most as well. The constant hiss in the other two is just not my thing.
Title: Re: Dithering & noise shaping - When/where/how?
Post by: preglow on October 30, 2006, 07:17:53 AM
Then you're the reason i wrote "most people" instead of "everyone" in my first post in this thread  ;D
Title: Re: Dithering & noise shaping - When/where/how?
Post by: Davide-NYC on October 30, 2006, 04:03:47 PM
I like the 2nd segment best. I dislike a 'moving' (sound dependant) hiss and the 'character' of the static hiss is more 'pleasant' in the 2nd segment.

Of course it all sounds horible and is just set up this way to illustrate the different effects. Thus I think that at a much lower lever the type of hiss heard in the 2nd segment would be the most 'pleasant' none-disturbing.

If the noise moves with the source it is as if it's part os the music, which it is not. Having grown up on cassettes, my brain can 'ignore' the hiss and just focus on the sound source. But if it moves around it become part of the sound source (in my mind) and thus more distracting and annoying.

My $0.28.
Title: Re: Dithering & noise shaping - When/where/how?
Post by: jlo on November 01, 2006, 05:23:24 AM
well done Preglow, dither is a nice added feature to improve playback.
I also do prefer the dither+noise shaping sequence
Sure that for most discs with an effective dynamic of only few dB's, lot of people won't really benefit of this feature.
But for those listening to their own recordings, or classical recordings or some high quality jazz/rock tracks, it's great !