diff options
author | Robin Gareus <robin@gareus.org> | 2019-02-28 20:40:45 +0100 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2019-02-28 20:40:45 +0100 |
commit | 9131cd17a02eb8721b75cbf57305f3d25f589982 (patch) | |
tree | 315f580714d5da23a80ec1d89693fa6f4b726f65 /libs/audiographer | |
parent | 2a8d3ff4f052b5fc0988f782fe35dbb9773de430 (diff) |
Consolidate gdither noise code
Diffstat (limited to 'libs/audiographer')
-rw-r--r-- | libs/audiographer/private/gdither/gdither.cc | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/libs/audiographer/private/gdither/gdither.cc b/libs/audiographer/private/gdither/gdither.cc index 8fa1ea6cd5..fd057ded37 100644 --- a/libs/audiographer/private/gdither/gdither.cc +++ b/libs/audiographer/private/gdither/gdither.cc @@ -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] |