2 * Copyright (C) 2002 Steve Harris <steve@plugin.org.uk>
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.
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.
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.
28 #include "gdither_types.h"
30 /* Create and initialise a state structure, takes a dither type, a number of
31 * channels and a bit depth as input
33 * The Dither type is one of
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.
40 * GDitherRect - mathematically most accurate, lowest noise floor, but not
41 * that good for audio. It is the fastest though.
43 * GDitherTri - a happy medium between Rectangular and Shaped, reasonable
44 * noise floor, not too obvious, quite fast.
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.
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.
54 * bit depth, sets the bit width of the output sample data, it can be one of:
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)
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.
67 GDither gdither_new(GDitherType type, uint32_t channels,
69 GDitherSize bit_depth, int dither_depth);
71 /* Frees memory used by gdither_new.
73 void gdither_free(GDither s);
75 /* Applies dithering to the supplied signal.
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
82 void gdither_runf(GDither s, uint32_t channel, uint32_t length,
85 /* see gdither_runf, vut input argument is double format */
86 void gdither_run(GDither s, uint32_t channel, uint32_t length,