Consolidate gdither noise code
This commit is contained in:
parent
2a8d3ff4f0
commit
9131cd17a0
@ -1,38 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2000-2007 Paul Davis
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef NOISE_H
|
||||
#define NOISE_H
|
||||
|
||||
/* Can be overrriden with any code that produces whitenoise between 0.0f and
|
||||
* 1.0f, eg (random() / (float)RAND_MAX) should be a good source of noise, but
|
||||
* its expensive */
|
||||
#ifndef GDITHER_NOISE
|
||||
#define GDITHER_NOISE gdither_noise()
|
||||
#endif
|
||||
|
||||
inline static float gdither_noise()
|
||||
{
|
||||
static uint32_t rnd = 23232323;
|
||||
rnd = (rnd * 196314165) + 907633515;
|
||||
|
||||
return rnd * 2.3283064365387e-10f;
|
||||
}
|
||||
|
||||
#endif
|
@ -19,7 +19,6 @@
|
||||
|
||||
#include "gdither_types_internal.h"
|
||||
#include "gdither.h"
|
||||
#include "noise.h"
|
||||
|
||||
/* this monstrosity is necessary to get access to lrintf() and random().
|
||||
whoever is writing the glibc headers <cmath> and <cstdlib> should be
|
||||
@ -62,6 +61,14 @@ static const float shaped_bs[] = { 2.033f, -2.165f, 1.959f, -1.590f, 0.6149f };
|
||||
#define MIN_S24 -8388608
|
||||
#define SCALE_S24 8388608.0f
|
||||
|
||||
inline static float gdither_noise ()
|
||||
{
|
||||
static uint32_t rnd = 23232323;
|
||||
rnd = (rnd * 196314165) + 907633515;
|
||||
|
||||
return rnd * 2.3283064365387e-10f;
|
||||
}
|
||||
|
||||
GDither gdither_new(GDitherType type, uint32_t channels,
|
||||
|
||||
GDitherSize bit_depth, int dither_depth)
|
||||
@ -189,10 +196,10 @@ inline static void gdither_innner_loop(const GDitherType dt,
|
||||
case GDitherNone:
|
||||
break;
|
||||
case GDitherRect:
|
||||
tmp -= GDITHER_NOISE;
|
||||
tmp -= gdither_noise ();
|
||||
break;
|
||||
case GDitherTri:
|
||||
r = GDITHER_NOISE - 0.5f;
|
||||
r = gdither_noise () - 0.5f;
|
||||
tmp -= r - ts[channel];
|
||||
ts[channel] = r;
|
||||
break;
|
||||
@ -202,7 +209,7 @@ inline static void gdither_innner_loop(const GDitherType dt,
|
||||
ideal = tmp;
|
||||
|
||||
/* Run FIR and add white noise */
|
||||
ss->buffer[ss->phase] = GDITHER_NOISE * 0.5f;
|
||||
ss->buffer[ss->phase] = gdither_noise () * 0.5f;
|
||||
tmp += ss->buffer[ss->phase] * shaped_bs[0]
|
||||
+ ss->buffer[(ss->phase - 1) & GDITHER_SH_BUF_MASK]
|
||||
* shaped_bs[1]
|
||||
@ -265,10 +272,10 @@ inline static void gdither_innner_loop_fp(const GDitherType dt,
|
||||
case GDitherNone:
|
||||
break;
|
||||
case GDitherRect:
|
||||
tmp -= GDITHER_NOISE;
|
||||
tmp -= gdither_noise ();
|
||||
break;
|
||||
case GDitherTri:
|
||||
r = GDITHER_NOISE - 0.5f;
|
||||
r = gdither_noise () - 0.5f;
|
||||
tmp -= r - ts[channel];
|
||||
ts[channel] = r;
|
||||
break;
|
||||
@ -278,7 +285,7 @@ inline static void gdither_innner_loop_fp(const GDitherType dt,
|
||||
ideal = tmp;
|
||||
|
||||
/* Run FIR and add white noise */
|
||||
ss->buffer[ss->phase] = GDITHER_NOISE * 0.5f;
|
||||
ss->buffer[ss->phase] = gdither_noise () * 0.5f;
|
||||
tmp += ss->buffer[ss->phase] * shaped_bs[0]
|
||||
+ ss->buffer[(ss->phase - 1) & GDITHER_SH_BUF_MASK]
|
||||
* shaped_bs[1]
|
||||
|
Loading…
Reference in New Issue
Block a user