00001 /* 00002 * Copyright (C) 2002 Steve Harris <steve@plugin.org.uk> 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 00017 * 00018 * $Id: gdither.h,v 1.2 2007/09/24 16:16:28 benjie Exp $ 00019 */ 00020 00021 #ifndef GDITHER_H 00022 #define GDITHER_H 00023 00024 #ifdef __cplusplus 00025 extern "C" { 00026 #endif 00027 00028 #include "gdither_types.h" 00029 00030 /* Create and initialise a state structure, takes a dither type, a number of 00031 * channels and a bit depth as input 00032 * 00033 * The Dither type is one of 00034 * 00035 * GDitherNone - straight nearest neighbour rounding. Theres no pressing 00036 * reason to do this at 8 or 16 bit, but you might want to at 24, for some 00037 * reason. At the least it will save you writing int->float conversion code, 00038 * which is harder than it sounds. 00039 * 00040 * GDitherRect - mathematically most accurate, lowest noise floor, but not 00041 * that good for audio. It is the fastest though. 00042 * 00043 * GDitherTri - a happy medium between Rectangular and Shaped, reasonable 00044 * noise floor, not too obvious, quite fast. 00045 * 00046 * GDitherShaped - should have the least audible impact, but has the highest 00047 * noise floor, fairly CPU intensive. Not advisible if your going to apply 00048 * any frequency manipulation afterwards. 00049 * 00050 * channels, sets the number of channels in the output data, output data will 00051 * be written interleaved into the area given to gdither_run(). Set to 1 00052 * if you are not working with interleaved buffers. 00053 * 00054 * bit depth, sets the bit width of the output sample data, it can be one of: 00055 * 00056 * GDither8bit - 8 bit unsiged 00057 * GDither16bit - 16 bit signed 00058 * GDither32bit - 24+bits in upper bits of a 32 bit word 00059 * GDitherFloat - IEEE floating point (32bits) 00060 * GDitherDouble - Double precision IEEE floating point (64bits) 00061 * 00062 * dither_depth, set the number of bits before the signal will be truncated to, 00063 * eg. 16 will produce an output stream with 16bits-worth of signal. Setting to 00064 * zero or greater than the width of the output format will dither to the 00065 * maximum precision allowed by the output format. 00066 */ 00067 GDither gdither_new(GDitherType type, uint32_t channels, 00068 00069 GDitherSize bit_depth, int dither_depth); 00070 00071 /* Frees memory used by gdither_new. 00072 */ 00073 void gdither_free(GDither s); 00074 00075 /* Applies dithering to the supplied signal. 00076 * 00077 * channel is the channel number you are processing (0 - channles-1), length is 00078 * the length of the input, in samples, x is the input samples (float), y is 00079 * where the output samples will be written, it should have the approaprate 00080 * type for the chosen bit depth 00081 */ 00082 void gdither_runf(GDither s, uint32_t channel, uint32_t length, 00083 float *x, void *y); 00084 00085 /* see gdither_runf, but input argument is double format */ 00086 void gdither_run(GDither s, uint32_t channel, uint32_t length, 00087 double *x, void *y); 00088 00089 #ifdef __cplusplus 00090 } 00091 #endif 00092 00093 #endif
1.5.5