Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recording: Add dither when using fixed point samples #8679

Open
mixxxbot opened this issue Aug 23, 2022 · 9 comments
Open

Recording: Add dither when using fixed point samples #8679

mixxxbot opened this issue Aug 23, 2022 · 9 comments

Comments

@mixxxbot
Copy link
Collaborator

Reported by: daschuer
Date: 2016-11-05T20:11:45Z
Status: Confirmed
Importance: Low
Launchpad Issue: lp1639499
Tags: portaudio, recording


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

@mixxxbot
Copy link
Collaborator Author

Commented by: JosepMaJAZ
Date: 2016-11-05T20:34:04Z


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

libsndfile/libsndfile#188

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

@mixxxbot
Copy link
Collaborator Author

Commented by: daschuer
Date: 2016-11-05T21:53:33Z


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.

@mixxxbot
Copy link
Collaborator Author

Commented by: JosepMaJAZ
Date: 2016-11-06T22:51:37Z


Completely unimplemented, it seems:

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

@mixxxbot
Copy link
Collaborator Author

Commented by: daschuer
Date: 2016-11-06T23:27:03Z


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.

@mixxxbot
Copy link
Collaborator Author

Commented by: Be-ing
Date: 2016-11-07T00:29:07Z


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

@mixxxbot
Copy link
Collaborator Author

Commented by: daschuer
Date: 2016-11-07T10:25:52Z


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.

@mixxxbot
Copy link
Collaborator Author

Commented by: Be-ing
Date: 2016-11-07T18:04:33Z


"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?

@mixxxbot
Copy link
Collaborator Author

Commented by: JosepMaJAZ
Date: 2016-11-07T18:29:39Z


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.

@mixxxbot
Copy link
Collaborator Author

Commented by: daschuer
Date: 2016-11-07T23:52:46Z


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

@mixxxbot mixxxbot transferred this issue from another repository Aug 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant