|
Packit |
c948fe |
/*
|
|
Packit |
c948fe |
* Copyright (C) 2002 Steve Harris <steve@plugin.org.uk>
|
|
Packit |
c948fe |
*
|
|
Packit |
c948fe |
* This program is free software; you can redistribute it and/or modify
|
|
Packit |
c948fe |
* it under the terms of the GNU General Public License as published by
|
|
Packit |
c948fe |
* the Free Software Foundation; either version 2 of the License, or
|
|
Packit |
c948fe |
* (at your option) any later version.
|
|
Packit |
c948fe |
*
|
|
Packit |
c948fe |
* This program is distributed in the hope that it will be useful,
|
|
Packit |
c948fe |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
c948fe |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
c948fe |
* GNU General Public License for more details.
|
|
Packit |
c948fe |
*
|
|
Packit |
c948fe |
* You should have received a copy of the GNU General Public License
|
|
Packit |
c948fe |
* along with this program; if not, write to the Free Software
|
|
Packit |
c948fe |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
Packit |
c948fe |
*
|
|
Packit |
c948fe |
* $Id: dither.h,v 1.1 2003/01/07 16:44:16 pbd Exp $
|
|
Packit |
c948fe |
*/
|
|
Packit |
c948fe |
|
|
Packit |
c948fe |
#ifndef GDITHER_H
|
|
Packit |
c948fe |
#define GDITHER_H
|
|
Packit |
c948fe |
|
|
Packit |
c948fe |
#ifdef __cplusplus
|
|
Packit |
c948fe |
extern "C" {
|
|
Packit |
c948fe |
#endif
|
|
Packit |
c948fe |
|
|
Packit |
c948fe |
#include "gdither_types.h"
|
|
Packit |
c948fe |
|
|
Packit |
c948fe |
/* Create and initialise a state structure, takes a dither type, a number of
|
|
Packit |
c948fe |
* channels and a bit depth as input
|
|
Packit |
c948fe |
*
|
|
Packit |
c948fe |
* The Dither type is one of
|
|
Packit |
c948fe |
*
|
|
Packit |
c948fe |
* GDitherNone - straight nearest neighbour rounding. Theres no pressing
|
|
Packit |
c948fe |
* reason to do this at 8 or 16 bit, but you might want to at 24, for some
|
|
Packit |
c948fe |
* reason. At the lest it will save you writing int->float conversion code,
|
|
Packit |
c948fe |
* which is arder than it sounds.
|
|
Packit |
c948fe |
*
|
|
Packit |
c948fe |
* GDitherRect - mathematically most accurate, lowest noise floor, but not
|
|
Packit |
c948fe |
* that good for audio. It is the fastest though.
|
|
Packit |
c948fe |
*
|
|
Packit |
c948fe |
* GDitherTri - a happy medium between Rectangular and Shaped, reasonable
|
|
Packit |
c948fe |
* noise floor, not too obvious, quite fast.
|
|
Packit |
c948fe |
*
|
|
Packit |
c948fe |
* GDitherShaped - should have the least audible impact, but has the highest
|
|
Packit |
c948fe |
* noise floor, fairly CPU intensive. Not advisible if your going to apply
|
|
Packit |
c948fe |
* any frequency manipulation afterwards.
|
|
Packit |
c948fe |
*
|
|
Packit |
c948fe |
* channels, sets the number of channels in the output data, output data will
|
|
Packit |
c948fe |
* be written interleaved into the area given to gdither_run(). Set to 1
|
|
Packit |
c948fe |
* if you are not working with interleaved buffers.
|
|
Packit |
c948fe |
*
|
|
Packit |
c948fe |
* bit depth, sets the bit width of the output sample data, it can be one of:
|
|
Packit |
c948fe |
*
|
|
Packit |
c948fe |
* GDither8bit - 8 bit unsiged
|
|
Packit |
c948fe |
* GDither16bit - 16 bit signed
|
|
Packit |
c948fe |
* GDither32bit - 24+bits in upper bits of a 32 bit word
|
|
Packit |
c948fe |
* GDitherFloat - IEEE floating point (32bits)
|
|
Packit |
c948fe |
* GDitherDouble - Double precision IEEE floating point (64bits)
|
|
Packit |
c948fe |
*
|
|
Packit |
c948fe |
* dither_depth, set the number of bits before the signal will be truncated to,
|
|
Packit |
c948fe |
* eg. 16 will produce an output stream with 16bits-worth of signal. Setting to
|
|
Packit |
c948fe |
* zero or greater than the width of the output format will dither to the
|
|
Packit |
c948fe |
* maximum precision allowed by the output format.
|
|
Packit |
c948fe |
*/
|
|
Packit |
c948fe |
GDither gdither_new(GDitherType type, unsigned int channels,
|
|
Packit |
c948fe |
GDitherSize bit_depth, int dither_depth);
|
|
Packit |
c948fe |
|
|
Packit |
c948fe |
/* Frees memory used by gdither_new.
|
|
Packit |
c948fe |
*/
|
|
Packit |
c948fe |
void gdither_free(GDither s);
|
|
Packit |
c948fe |
|
|
Packit |
c948fe |
/* Applies dithering to the supplied signal.
|
|
Packit |
c948fe |
*
|
|
Packit |
c948fe |
* channel is the channel number you are processing (0 - channles-1), length is
|
|
Packit |
c948fe |
* the length of the input, in samples, x is the input samples (float), y is
|
|
Packit |
c948fe |
* where the output samples will be written, it should have the approaprate
|
|
Packit |
c948fe |
* type for the chosen bit depth
|
|
Packit |
c948fe |
*/
|
|
Packit |
c948fe |
void gdither_runf(GDither s, unsigned int channel, unsigned int length,
|
|
Packit |
c948fe |
float *x, void *y);
|
|
Packit |
c948fe |
|
|
Packit |
c948fe |
/* see gdither_runf, vut input argument is double format */
|
|
Packit |
c948fe |
void gdither_run(GDither s, unsigned int channel, unsigned int length,
|
|
Packit |
c948fe |
double *x, void *y);
|
|
Packit |
c948fe |
|
|
Packit |
c948fe |
#ifdef __cplusplus
|
|
Packit |
c948fe |
}
|
|
Packit |
c948fe |
#endif
|
|
Packit |
c948fe |
|
|
Packit |
c948fe |
#endif
|