aboutsummaryrefslogtreecommitdiffstats
path: root/src/PcmDither.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-04-09 01:24:52 +0200
committerMax Kellermann <max@duempel.org>2013-04-09 01:24:52 +0200
commitc654c7630aad220a4935c34b076e107b6b0561a5 (patch)
tree7ca6e4e30bee7153ed54f302467140180d77490d /src/PcmDither.cxx
parent3f3b26fb0ee090bfc1321572904aa94deca42a84 (diff)
downloadmpd-c654c7630aad220a4935c34b076e107b6b0561a5.tar.gz
mpd-c654c7630aad220a4935c34b076e107b6b0561a5.tar.xz
mpd-c654c7630aad220a4935c34b076e107b6b0561a5.zip
pcm_*: move to src/pcm/
Diffstat (limited to 'src/PcmDither.cxx')
-rw-r--r--src/PcmDither.cxx89
1 files changed, 0 insertions, 89 deletions
diff --git a/src/PcmDither.cxx b/src/PcmDither.cxx
deleted file mode 100644
index 98d0d443e..000000000
--- a/src/PcmDither.cxx
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright (C) 2003-2013 The Music Player Daemon Project
- * http://www.musicpd.org
- *
- * 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.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include "config.h"
-#include "PcmDither.hxx"
-#include "PcmPrng.hxx"
-
-inline int16_t
-PcmDither::Dither24To16(int_fast32_t sample)
-{
- constexpr unsigned from_bits = 24;
- constexpr unsigned to_bits = 16;
- constexpr unsigned scale_bits = from_bits - to_bits;
- constexpr int_fast32_t round = 1 << (scale_bits - 1);
- constexpr int_fast32_t mask = (1 << scale_bits) - 1;
- constexpr int_fast32_t ONE = 1 << (from_bits - 1);
- constexpr int_fast32_t MIN = -ONE;
- constexpr int_fast32_t MAX = ONE - 1;
-
- sample += error[0] - error[1] + error[2];
-
- error[2] = error[1];
- error[1] = error[0] / 2;
-
- /* round */
- int_fast32_t output = sample + round;
-
- int_fast32_t rnd = pcm_prng(random);
- output += (rnd & mask) - (random & mask);
-
- random = rnd;
-
- /* clip */
- if (output > MAX) {
- output = MAX;
-
- if (sample > MAX)
- sample = MAX;
- } else if (output < MIN) {
- output = MIN;
-
- if (sample < MIN)
- sample = MIN;
- }
-
- output &= ~mask;
-
- error[0] = sample - output;
-
- return (int16_t)(output >> scale_bits);
-}
-
-void
-PcmDither::Dither24To16(int16_t *dest, const int32_t *src,
- const int32_t *src_end)
-{
- while (src < src_end)
- *dest++ = Dither24To16(*src++);
-}
-
-inline int16_t
-PcmDither::Dither32To16(int_fast32_t sample)
-{
- return Dither24To16(sample >> 8);
-}
-
-void
-PcmDither::Dither32To16(int16_t *dest, const int32_t *src,
- const int32_t *src_end)
-{
- while (src < src_end)
- *dest++ = Dither32To16(*src++);
-}