Recording: Add dither when using fixed point samples

Bug #1639499 reported by Daniel Schürmann
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mixxx
Confirmed
Low
Unassigned

Bug Description

Dither is required to replace quantization noise with less notable random noise when converting floating point samples into fixed point samples.
This should be done when recording as well.

libsndfile can dither the signal when required, but it is disabled by default.

Unfortunately it is an undocumented feature. The test code can be found here:
https://github.com/erikd/libsndfile/blob/2fcf531ac940829cf350f86786fcff5160a32143/tests/dither_test.c#L157

Revision history for this message
JosepMa (josepma) wrote :

I contacted the author and he said that the code has never been finished, so that's why it isn't documented

https://github.com/erikd/libsndfile/issues/188

I believe the intention was to have different dither models, not only white noise, and probably that's why it is unfinished.

Revision history for this message
Daniel Schürmann (daschuer) wrote :

How useful is the current state? What is missing to use it for Mixxx?
It looks somehow working.

It would be a pity, if we have to add our own dithering inside Mixxx which also stops us from using the sndfile integrated sample conversion routines.

Revision history for this message
JosepMa (josepma) wrote :

Completely unimplemented, it seems:

    for (ch = 0 ; ch < channels ; ch++)
     for (k = ch ; k < channels * frames ; k += channels)
      out [k] = in [k] ;

Revision history for this message
Daniel Schürmann (daschuer) wrote :

Thank you for the update.

Now we have two options to fix the bug,
Contribute to libsndfile and implement the dithering or move the sample conversion to Mixxx and dither there.

In both cases we can use the portaudio dither code, since the license is compatible.
But there are known issues in it, discussed lately in the portaudio mailing list.

It could be fun to contribute a improved version to both upstream projects.
But it seams to be a low prio issue for Mixxx, since no real user has ever complained about it.

Changed in mixxx:
status: New → Confirmed
importance: Undecided → Low
tags: added: portaudio recording
Revision history for this message
Be (be.ing) wrote :

Are there any other libraries that could be used for this? Maybe SoX? http://sox.sourceforge.net/SoX/NoiseShaping

Revision history for this message
Daniel Schürmann (daschuer) wrote :

The relevant sox code is here:
https://sourceforge.net/p/sox/code/ci/master/tree/src/dither.c

Noise shaping would be a nice, but it requires significant more CPU, so it should be optional.

libav / ffmpeg has also a dither solution:
http://code.metager.de/source/xref/ffmpeg/libavresample/dither.c

This is the Portaudio Implementation:
https://github.com/EddieRingle/portaudio/blob/9eb5f0b3d820a81d385504d9c54534abbeea1099/src/common/pa_converters.c#L673
The issue with that is that the noise is calculated on the fly and the high pass to the noise is questionable.

Revision history for this message
Be (be.ing) wrote :

"Noise shaping would be a nice, but it requires significant more CPU, so it should be optional."

This is for recording purposes, correct? If so, this doesn't have to be a real time process does it?

Revision history for this message
JosepMa (josepma) wrote :

It is a real time process. You record while you mix. This can be used to listen to it later (learn or share) as well as keeping a record of a live mix that you realize.

I'm not sure if the process itself should be too complex. Of course, there are different ways to dither with noise shape, but basically, the concepts are:

dither: add uncorrelated noise to the signal, so that when the bits of the signal are truncated, it does not generate correlated distortion (in form of frequencies correlated with the sound).

noise shaping: a technique in which white noise is modified in such a way that its frequency representation gets a different shape than flat line. Given the human ear, the shape commonly used is similar to an increasing line (i.e. lower power in the lower frequencies and higher power in the higher frequencies).

Usually, software use Triangular-PDF (the type of noise shaping) dither. Said that, I don't know the exact details of this technique.

Revision history for this message
Daniel Schürmann (daschuer) wrote :

Triangular-PDF is just the type of noise which is added for dither, to replace the quantization noise.

Noise shaping:
The inverse quantization error of sample N is feed back as noise for sample N+1
You can also put fancy filters into the feedback loop and add random noise as well.

Like shown here:
http://www.production-partner.de/wp-content/uploads/2015/03/Delta-sigma-noise-shaper.png

This is implemented in https://sourceforge.net/p/sox/code/ci/master/tree/src/dither.h

Revision history for this message
Swiftb0y (swiftb0y) wrote :

Mixxx now uses GitHub for bug tracking. This bug has been migrated to:
https://github.com/mixxxdj/mixxx/issues/8679

lock status: Metadata changes locked and limited to project staff
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.