ref: 5b1e9a8637cb7a2a1f95f4bee6f688982e2b5191
parent: 585045c0398595059dbd37aeb7c4f1110af6b38c
author: robs <robs>
date: Fri Mar 20 16:24:40 EDT 2009
clean up dither changes
--- a/sox.1
+++ b/sox.1
@@ -1635,41 +1635,40 @@
%-2 delay 0 .05 .1 .15 .2 .25 remix - fade 0 4 .1 norm -1
.EE
.TP
-\fBdither\fR [\fB\-R\fR] [\fB\-r\fR\^|\^\fB\-t\fR] [\fB\-s\fR\^|\^\fB\-f \fIfilter\fR] [\fIdepth\fR]
+\fBdither\fR [\fB\-a\fR] [\fB\-s\fR\^|\^\fB\-f \fIfilter\fR]
Apply dithering to the audio.
-Dithering deliberately adds a small amount of noise to the signal
-in order to mask audible quantization effects that
-can occur if the output sample size is less than 24 bits.
-The default (or with the
-.B \-t
-option) is Triangular (TPDF) white noise.
-The
-.B \-r
-option can be used to select Rectangular Probability Density Function
-(RPDF) white noise.
-Noise-shaping (only for certain sample rates) can be selected with
+Dithering deliberately adds a small amount of noise to the signal in
+order to mask audible quantization effects that can occur if the output
+sample size is less than 24 bits. The default is to add triangular
+(TPDF) white noise. Noise-shaping (only for certain sample rates) can
+be selected with
.BR \-s .
With the
.B \-f
option, it is possible to select a particular noise-shaping filter from
the following list: lipshitz, f-weighted, modified-e-weighted,
-improved-e-weighted, gesemann, shibata, low-shibata, high-shibata.
-Note that most filter types are available only with 44100Hz sample rate.
-The filter types are distinguished by the following properties:
-audibility of noise, level of (inaudible, but in some circumstances,
-otherwise problematic) shaped high frequency noise, and
-processing speed.
+improved-e-weighted, gesemann, shibata, low-shibata, high-shibata. Note
+that most filter types are available only with 44100Hz sample rate. The
+filter types are distinguished by the following properties: audibility
+of noise, level of (inaudible, but in some circumstances, otherwise
+problematic) shaped high frequency noise, and processing speed.
.SP
-By default, the amount of noise added is \(+-\(12 bit for RPDF, \(+-1 bit
-for TPDF;
-the optional \fIdepth\fR parameter (0.5 to 1) is a (linear or voltage)
-multiplier of this amount. Reducing this value reduces the audibility
-of the added white noise, but correspondingly creates residual
-quantization noise, so it should not normally be changed.
+The
+.B \-a
+option enables a mode where dithering (and noise-shaping if applicable)
+are automatically enabled only when needed. The most likely use for
+this is when applying fade in or out to an already dithered file, so
+that the redithering applies only to the faded portions. However, auto
+dithering is not fool proof, so the fades should be carefully checked
+for any noise modulation; if this occurs, then either redither the whole
+file, or use
+.BR trim ,
+.BR fade ,
+and concatencate.
.SP
-If
+If the SoX global option
.B \-R
-option is given, then the pseudo-random number generator used to
+option is not given, then the pseudo-random number generator used to
generate the white noise will be `reseeded', i.e. the generated noise
will be different between invocations.
.SP
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -58,7 +58,7 @@
libsox_la_SOURCES += \
band.h bend.c biquad.c biquad.h biquads.c chorus.c compand.c crop.c \
compandt.c compandt.h contrast.c dcshift.c delay.c dft_filter.c \
- dft_filter.h dither.c dither_fir.h dither_iir.h earwax.c echo.c \
+ dft_filter.h dither.c dither.h earwax.c echo.c \
echos.c effects.c effects.h effects_i.c effects_i_dsp.c fade.c fft4g.c \
fft4g.h fifo.h filter.c fir.c firfit.c flanger.c gain.c input.c \
ladspa.c loudness.c mcompand.c mcompand_xover.h mixer.c noiseprof.c \
--- a/src/dither.c
+++ b/src/dither.c
@@ -196,11 +196,8 @@
double d = *ibuf++ + (double)(RANQD1 >> p->prec) + (RANQD1 >> p->prec);
d /= (1 << (32 - p->prec));
d = (int)(d < 0? d - .5 : d + .5);
- if (d < (-1 << (p->prec-1)))
- ++effp->clips, *obuf = -1 << (p->prec-1);
- else if (d > SOX_INT_MAX(p->prec))
- ++effp->clips, *obuf = SOX_INT_MAX(p->prec);
- else *obuf = d;
+ *obuf = d < (-1 << (p->prec-1))? ++effp->clips, -1 << (p->prec-1) :
+ d > SOX_INT_MAX(p->prec)? ++effp->clips, SOX_INT_MAX(p->prec) : d;
*obuf++ <<= 32 - p->prec;
if (p->dither_off)
lsx_debug("flow %u: on @ %u", effp->flow, (unsigned)p->num_output);