51343b13c4d9df38584092c29391ac5f2ebcec8a
[ardour.git] / libs / ardour / ardour / gdither.h
1 /*
2  *  Copyright (C) 2002 Steve Harris <steve@plugin.org.uk>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  *
18  *  $Id$
19  */
20
21 #ifndef GDITHER_H
22 #define GDITHER_H
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 #include "gdither_types.h"
29
30 /* Create and initialise a state structure, takes a dither type, a number of
31  * channels and a bit depth as input
32  *
33  * The Dither type is one of
34  *
35  *   GDitherNone - straight nearest neighbour rounding. Theres no pressing
36  *   reason to do this at 8 or 16 bit, but you might want to at 24, for some
37  *   reason. At the lest it will save you writing int->float conversion code,
38  *   which is arder than it sounds.
39  *
40  *   GDitherRect - mathematically most accurate, lowest noise floor, but not
41  *   that good for audio. It is the fastest though.
42  *
43  *   GDitherTri - a happy medium between Rectangular and Shaped, reasonable
44  *   noise floor, not too obvious, quite fast.
45  *
46  *   GDitherShaped - should have the least audible impact, but has the highest
47  *   noise floor, fairly CPU intensive. Not advisible if your going to apply
48  *   any frequency manipulation afterwards.
49  *
50  * channels, sets the number of channels in the output data, output data will
51  * be written interleaved into the area given to gdither_run(). Set to 1
52  * if you are not working with interleaved buffers.
53  *
54  * bit depth, sets the bit width of the output sample data, it can be one of:
55  *
56  *   GDither8bit   - 8 bit unsiged
57  *   GDither16bit  - 16 bit signed
58  *   GDither32bit  - 24+bits in upper bits of a 32 bit word
59  *   GDitherFloat  - IEEE floating point (32bits)
60  *   GDitherDouble - Double precision IEEE floating point (64bits)
61  *
62  * dither_depth, set the number of bits before the signal will be truncated to,
63  * eg. 16 will produce an output stream with 16bits-worth of signal. Setting to
64  * zero or greater than the width of the output format will dither to the
65  * maximum precision allowed by the output format.
66  */
67 GDither gdither_new(GDitherType type, uint32_t channels,
68
69                     GDitherSize bit_depth, int dither_depth);
70
71 /* Frees memory used by gdither_new.
72  */
73 void gdither_free(GDither s);
74
75 /* Applies dithering to the supplied signal.
76  *
77  * channel is the channel number you are processing (0 - channles-1), length is
78  * the length of the input, in samples, x is the input samples (float), y is
79  * where the output samples will be written, it should have the approaprate
80  * type for the chosen bit depth
81  */
82 void gdither_runf(GDither s, uint32_t channel, uint32_t length,
83                    float *x, void *y);
84
85 /* see gdither_runf, vut input argument is double format */
86 void gdither_run(GDither s, uint32_t channel, uint32_t length,
87                    double *x, void *y);
88
89 #ifdef __cplusplus
90 }
91 #endif
92
93 #endif