Help - Search - Members - Calendar
Full Version: Program for dithering audio?
Hydrogenaudio Forums > Hydrogenaudio Forum > Scientific Discussion
Firon
Is there any program to dither and noise shape audio? I need something that applies it to the file and allows for truncation to arbitrary bit depths (ie 10-bit padded to 16 with dither + strong ATH noise shaping). foobar2000 only lets me do so for playback.
Egor
Try the latest fb2k, it supports bit-depth conversion (see the Preferences -> Converter page).
Klyith
QUOTE(Firon @ Aug 21 2006, 03:22) *

Is there any program to dither and noise shape audio? I need something that applies it to the file and allows for truncation to arbitrary bit depths (ie 10-bit padded to 16 with dither + strong ATH noise shaping). foobar2000 only lets me do so for playback.

Sox may be able to do that, but I don't know if it can do arbitrary bit depths. (I don't really use it that much...) It can dither, though the option is called "mask" and it doesn't have noise shaping. That's the only free tool besides foobar that I have in my holster that might do the job... Audacity has good dither and noise shaping options, but limited bit depth options.

Note: You don't need any dither or noise shaping when converting to a greater bit depth (ie 10bit to 16bit), only when decreasing depth.
Egor
QUOTE(Klyith @ Aug 21 2006, 22:07) *
That's the only free tool besides foobar that I have in my holster that might do the job...

There is also a famous SSRC written by Naoki Shibata.
Shibatch Audio Tools
QUOTE(ssrc.txt)
<Features>
This program converts sampling rate of PCM wav file. Also, this program has
a function to apply dither to its output and extend perceived dynamic range.
Sampling rates of 44.1kHz and 48kHz are populary used, but ratio of these
two frequency is 147:160, and it's not a small numbers. Therefore, sampling
rate conversion without degradation of sound quality requires filter with very
large order, and it's difficult to achive both quality and speed. This program
achived relatively fast and high quality with two different kinds of filters
combined skillfully.

<Usage>

ssrc [<options>] <input wav file> <output wav file>

Usage of options are as follows :
--rate <sampling rate>
Specify sampling rate of output file.
--att <value(dB)>
Attenuate volume of output by specified value.
--twopass
Perform two pass processing so that clipping is avoided.
At the first pass, the program converts sampling rate of input file and
write to a temporary file in float numbers while scanning clippings. At
the second pass, the program attenuate the volume so that clipping is
prevented, and write to the output file.
--normalize
Normalize the wave file.
--dither [<type>]
Apply dithers to the output file.
type 0 : no dither
type 1 : no noise shaping
type 2 : triangular dither
type 3 : ATH based noise shaping
--bits
Specify quantization bit length. 8, 16 and 24bits are supported.
--quiet
Nothing is displayed except error.
--pdf <type> [<amp>]
Select probability distribution function and amplitude of noise.
type 0 : rectangular
type 1 : triangular
type 2 : Gaussian
--profile
Specify profile
"standard" profile : the default setting
"fast" profile : about x2 speed, not so bad quality

Only PCM coded wav files are used as input and output files.
Input and output sampling frequency must satisfy a certain condition, but
(probably) conversions between all populary used sampling frequencies are
supported.
If sampling frequencies of input and output are same, sampling rate
conversion is not performed and only conversion of quantization bit length
with optional dithering are done.

Firon
Thanks for the help.

I'll look into the latest foobar (I'm still 0.8.3), as well as SSRC.

Sox might be useful for converting to 10-bit, but I really do need the noise shaping along with dithering.
Egor
I ought to have mentioned that fb2k doesn't support conversion to arbitrary bit-depths.

Edit. Quick search revealed this software.
SebastianG
QUOTE(Firon @ Aug 23 2006, 05:51) *

(...) but I really do need the noise shaping along with dithering.

Why do you need to dither & noise-shape to 10 bit samples? ... if I may ask
Also, what sampling rates are you targeting? Only 44 kHz?

Doing 10 bits at 44 kHz will be pretty noisy I suppose -- even with dithering & noise shaping enabled.
10 bits for 88 kHz or above will be fine quality-wise (you can push most of the noise out of the audible band)

If anyone cares: I designed some neat "symmetric" (poles = -zeros) noise-shaping filters for rates around 96 kHz by hand. Here's a 6th order example with 20 dB attenuation below 0.43*nyquist_frequency:
CODE

       1 - a z^-1 + b z^-2 - c z^-3 + d z^-4 - e z^-5 + f z^-6
H(z) = -------------------------------------------------------
       1 + a z^-1 + b z^-2 + c z^-3 + d z^-4 + e z^-5 + f z^-6

with
a= 1.45619118675708
b= 2.24132454071640
c= 1.76666007562633
d= 1.14160366651250
e= 0.43188674232519
f= 0.09261200141284

(This thing at 16/96 will give you 20/44-like performance in the audible band (0-20 kHz) PLUS a flat response up to at least 40 kHz with an appropriate reconstruction filter)
SebastianG
QUOTE(Egor @ Aug 23 2006, 06:10) *

Edit. Quick search revealed this software.

...looks promising, but only supports FIR noise shaping filters (no IIR filters)
SebastianG
QUOTE(ssrc)

--dither [<type>]
dithering
type 0 : no dither
type 1 : no noise shaping
type 2 : triangular dither
type 3 : ATH based noise shaping
type 4 : less dither amplitude than type 3
--pdf <type> [<amp>]
select p.d.f. of noise
type 0 : rectangular
type 1 : triangular
type 2 : Gaussian

Oh boy! Somebody's been mixing up dithering with noise shaping. It's not really obvious what all these "types" do. Does type 0 dither (called "no dither") imply that dithering is done for type 1,2,3 ? Does type 1 dither (called "no noise shaping") imply that noise shaping is done for type 0,2,3,4 ? If so what kind of noise shaping is used for type 0,2,3,4 and what kind of dithering is used for type 1-4 ?

Also, what does "--dither 2 --pdf 0" do ? tongue.gif
Firon
I'm playing around with my Nintendo DS, and its DAC is only 10-bit (if only it was at least 12, it'd be much better!). The playback software doesn't really seem to dither much, if at all (probably due to lack of CPU power), so quiet sections don't sound very good. Non-quiet sections sound pretty decent though.
I wanted to truncate and pre-dither/noise-shape the file to see if it'd sound any better. The target sample rate is 44KHz.

As for that ssrc thing, it seems like the dither options are taken from foobar2000's playback preferences. Assuming it is, type 1 is dither without noise shaping, 2 is dithering with triangular noise shaping, and type 3 is dithering with ATH noise shaping. Type 4 is probably dither with "soft" ATH noise shaping. The --pdf things just confuse things though. I wonder which one would override the other. tongue.gif
SebastianG
10 bits at 44 kHz isn't that bad actually. 12 bits sound really good. I tested it with this java commandline tool I wrote today. It uses a 8th order IIR "ATH" noise shaping filter (for 44 kHz content) with the following response:
IPB Image

Try it for yourself. How many bits do you really need? biggrin.gif

java -jar requant.jar -d1.2 source.wav tobecomputed.wav 10

edit: current version is 0.17b

Cheers!
Firon
The hiss from the dithering is stronger than the noise from quantization error.

It may be possible to go up to 48KHz (though the source files are only 44, guess it'd need some resampling first), would that make a difference?

Edit: speak of the devil, it's nowhere near as strong when I hear it on headphones instead of my speakers.
Mike Giacomelli
QUOTE(SebastianG @ Aug 23 2006, 00:58) *

QUOTE(Egor @ Aug 23 2006, 06:10) *

Edit. Quick search revealed this software.

...looks promising, but only supports FIR noise shaping filters (no IIR filters)


Silly question: Why is that a problem?
crimsontide
I have played around with Audacity before...it used to allow two or three different algorithms for resampling the bitrate, with/without dither, and a number of different types of dither as well, it was the most flexible beast available a while back, but strangely, I downlaoded it and cant find the option anymore.....

it was there, i once set up a whole college to use audacity to upsample from 16bit to 24 bit, and vice versa.........cant for the life of me remember how i did it though....muppet.
rutra80
In v1.2.4 it's still in Preferences (Quality tab).
SebastianG
QUOTE(Firon @ Aug 26 2006, 00:53) *

The hiss from the dithering is stronger than the noise from quantization error.

Huh? What exactly did you compare?

QUOTE(Mike Giacomelli @ Aug 26 2006, 03:23) *

QUOTE(SebastianG @ Aug 23 2006, 00:58) *

...looks promising, but only supports FIR noise shaping filters (no IIR filters)

Silly question: Why is that a problem?

Silly? No. Well, you need minimum phase filters for noise shaping. So, there's no advantege of FIR filters over IIR filters. In fact, it's fairly easy to design low order IIR filters with desirable responses whereas FIR filters need to be "long" to match the desired response. It's not a problem but an unnecessary restriction which comes at the cost of reduced speed.

PS:
I may publish a graphical IIR filter design tool that let's you listen to shaped white noise while editing the filter. You could then design your own noise shaping filters.
Firon
I compared the output from your program using one of my songs, and then compared to the same song truncated to 10 bits with foobar2000. The truncated version sounded less objectionable (to my ears), though the difference wasn't so great when I used my cheapo headphones instead of my speakers.
kjoonlee
Was the comparison double-blind? smile.gif
2Bdecided
Can I make a terrible suggestion (especially given the arguments raging in other threads)?

It's possible to noise shape without dithering.

What this means is that the quantisation distortion stays exactly that - distortion - but its spectrum is shaped to try to make it less audible.

It's how SACD works (with its one bit!).

It might just be worth a try at 10-bits.

The other trick you can try is to use sub-optimal dither - e.g. lower amplitude. By the time you get to half what you should have, distortion starts to be obvious (though not always objectionable). On many signals, the distortion is comparatively low (sometimes inaudible) at dither levels between half the correct amount, and "the correct amount".

So it might be worth reducing the dither amplitude, if possible.

(Yes, this is all terrible, and not optimal at all - but he's talking about 10 bits!!!)

Cheers,
David.
SebastianG
Actually that's what I tried. I was able to reduce the amount of dither when noise shaping was enabled. I tried it with 8 bits/sample + the ATH derived noise shaping filter. My test song started out silently so I could hear the difference between rectangular and triangular dithering wihouth noise shaping. With noise shaping enabled it sounded pretty good with a quite low dither less than +/- 1/2 LSB of rectangular dither. However dithering below a certain amplitude -- say +/-1/4 LSB -- doesn't really help reducing the noise power. But it does seem to be sufficient in most cases when strong noise shaping is in use.

Of course, to be on the safe side you can still use full triangular dithering
2Bdecided
That inspired me to play with the options in Cool Edit Pro.

In answer to "how many bits is enough", if you're listening to pop music in a noisy environment, I'd say between 6 and 7!

Click to view attachment
Click to view attachment

(CEP settings: 0.1 bit dither, triangular, 48kHz (!) noise shaping, 6 or 7 bits target padded to 8-bits)

Heavy noise shaping at 44.1kHz prevents you going much further because the high frequency noise is taking up ~ 4-bits!

With this kind of processing, where do you go with a portable device that is so quiet that you need more than 10-bits?! wink.gif

Cheers,
David.
SebastianG
noise power relative to full rectangular dither (+/-0.5) under the assumption the noise is NOT correlated before shaping (ie no non-linear distortions):
CODE

rectangular dither: +/- 0.5   -0.00 dB (obviously)
rectangular dither: +/- 0.4   -0.86 dB
rectangular dither: +/- 0.3   -1.67 dB
rectangular dither: +/- 0.2   -2.37 dB
rectangular dither: +/- 0.15  -2.64 dB
rectangular dither: +/- 0.1   -2.84 dB
rectangular dither: +/- 0.05  -2.97 dB
rectangular dither: +/- 0.0   -3.01 dB

Decide for yourself whether a given dither level is worth the risk of harmonic distortions.
I'd probably try 0.2 next time because below that the noise power doesn't drop significantly.

Is there any interest in an interactive/live noise shaper design tool?
I could make the proggy a bit more user-friendly if anyone whishes to have a play ...

BTW: I'm totally fine with 12 bits at 44kHz with noise shaping enabled and moderate dithering.
I really can't distinguish it from the 16 bit version using ear buds. It may be due to my computer's fans.

2Bdecided: Could you post a file containing TPDF dithered silence using the same noise shaper you used to make the 6bit/7bit files? I'm interested in what the shaper actually does. I have no CE Pro smile.gif

Edit: I think it's possible to prove that a certain dither level (below the alredy known-to-be-safe levels) is secure given the impulse response of the noise shaper -- me needs to think more about it.

Edit2: The old Beatles song may already contain enough noise so one does not need a dither. It'd be nice to have a 16 bit reference.
2Bdecided
Hi Sebastian,

0.1 bits isn't enough to be clean on silent parts. To avoid distortion entirely with noise shaping you need 0.5 bits of dither (as CEP counts it, compared to 1-bit without noise shaping).

I'll try to remember to post the various CEP noise shaping curves next week. They're not that interesting really.

Cheers,
David.


QUOTE(SebastianG @ Sep 1 2006, 14:38) *

Edit: I think it's possible to prove that a certain dither level (below the alredy known-to-be-safe levels) is secure given the impulse response of the noise shaper -- me needs to think more about it.


Practical experience suggests you're on to something there.

I wonder if the Lipshitz and Vanderkooy vs James Angus arguments about DSD (1-bit systems) ever mentioned this? It could have been crucial if true, because it could demolish Lipshitz and Vanderkooy's argument against DSD (which, put simply, is that to avoid distortion, you have to fill the one bit you have with dither, thus leaving no room for a signal!).

I used to have some of the papers, but can't find them now.

Cheers,
David.
Woodinville
QUOTE(2Bdecided @ Sep 1 2006, 09:14) *
I wonder if the Lipshitz and Vanderkooy vs James Angus arguments about DSD (1-bit systems) ever mentioned this? It could have been crucial if true, because it could demolish Lipshitz and Vanderkooy's argument against DSD (which, put simply, is that to avoid distortion, you have to fill the one bit you have with dither, thus leaving no room for a signal!).

I used to have some of the papers, but can't find them now.

Cheers,
David.


Err, no, you still have overload if you have half a bit of dither, and 1 bit of signal.
SebastianG
Actually -- from what I know -- you don't have "one bit of signal". Suppose the DSD's bits correspond to the levels -1 and 1 then the DSD encoder makes sure the signal is scaled to be within -0.5 ... 0.5 (I'm not sure about the exact range, it may also be -0.7 ... 0.7)

At least this is what I remember having read somewhere (sorry, no reference)
jlt
@ Sebastian
QUOTE
Is there any interest in an interactive/live noise shaper design tool?
I could make the proggy a bit more user-friendly if anyone whishes to have a play ...

cool.gif
please,do that.

thanks smile.gif
Firon
SebastianG: here's a 30s clip of the main song I've been using to test the dithering. It has a quiet section in it, so it's pretty good for testing.
http://utorrent.com/steveconte-noreply_clip.flac

And sorry for my lack of response! I've been busy, and I no longer have the actual system to test on, had to send it off for repair laugh.gif But no matter, I can still test well enough on the PC 'till I get it back.
SebastianG
QUOTE(2Bdecided @ Sep 1 2006, 18:14) *

QUOTE(SebastianG @ Sep 1 2006, 14:38) *

Edit: I think it's possible to prove that a certain dither level (below the alredy known-to-be-safe levels) is secure given the impulse response of the noise shaper -- me needs to think more about it.

Practical experience suggests you're on to something there.

Sorry, folks. False alarm.

QUOTE(jlt @ Sep 1 2006, 19:33) *

QUOTE
Is there any interest in an interactive/live noise shaper design tool?
I could make the proggy a bit more user-friendly if anyone whishes to have a play ...

cool.gif
please,do that. thanks smile.gif

Have a look at my little homepage.

QUOTE(Firon @ Sep 4 2006, 01:44) *

here's a 30s clip of the main song I've been using to test the dithering. It has a quiet section in it, so it's pretty good for testing.

I'll probably check it out later today.

QUOTE(Firon @ Sep 4 2006, 01:44) *

But no matter, I can still test well enough on the PC 'till I get it back.

You might also want to try the noise shaper design tool. smile.gif

BTW: Discussion of these tools should be done in this thread.

Cheers!
Firon
I'm trying it, and it just occurred to me that I had the equalizer on in my soundcard's DSP, turning that off made a world of difference. laugh.gif

And threads like these are the reason why I love HA, you ask for help with weird things, and there's always someone who knows what you're talking about. biggrin.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.