1
// -------------------------------------------------------------------------
3
// Copyright (C) 2010 Fons Adriaensen <fons@linuxaudio.org>
5
// This program is free software; you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation; either version 2 of the License, or
8
// (at your option) any later version.
10
// This program is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU General Public License for more details.
15
// You should have received a copy of the GNU General Public License
16
// along with this program; if not, write to the Free Software
17
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
// -------------------------------------------------------------------------
27
float Dither::_div = 0;
29
#define SCALE 32768.0f
37
_div = ldexpf (1.0f, 32);
41
void Dither::reset (void)
43
memset (_err, 0, (SIZE + 4) * sizeof(float));
49
void Dither::proc_rectangular (const float *srce, int16_t *dest, int step, int nsam)
56
r = genrand () - 0.5f;
57
v = *srce * SCALE + r;
59
if (k < -LIMIT) k = -LIMIT;
60
else if (k > LIMIT) k = LIMIT;
68
void Dither::proc_triangular (const float *srce, int16_t *dest, int step, int nsam)
77
v = *srce * SCALE + r0 - r1;
80
if (k < -LIMIT) k = -LIMIT;
81
else if (k > LIMIT) k = LIMIT;
90
void Dither::proc_lipschitz (const float *srce, int16_t *dest, int step, int nsam)
106
v = u + genrand () - genrand ();
109
if (k < -LIMIT) k = -LIMIT;
110
else if (k > LIMIT) k = LIMIT;
114
_err [SIZE + 0] = _err [0];
115
_err [SIZE + 1] = _err [1];
116
_err [SIZE + 2] = _err [2];
117
_err [SIZE + 3] = _err [3];