MPD 0.20.6

- Main Page
- Namespaces
- Data Structures
- Files

- File List
- Globals

PcmDither.hxx
Go to the documentation of this file.
1 /*
2 * Copyright 2003-2017 The Music Player Daemon Project
3 * http://www.musicpd.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef MPD_PCM_DITHER_HXX
21 #define MPD_PCM_DITHER_HXX
22
23 #include <stdint.h>
24
25 enum class SampleFormat : uint8_t;
26
27 class PcmDither {
28 int32_t error[3];
29 int32_t random;
30
31 public:
32 constexpr PcmDither()
33 :error{0, 0, 0}, random(0) {}
34
44 template<typename ST, unsigned SBITS, unsigned DBITS>
45 ST DitherShift(ST sample);
46
47 void Dither24To16(int16_t *dest, const int32_t *src,
48 const int32_t *src_end);
49
50 void Dither32To16(int16_t *dest, const int32_t *src,
51 const int32_t *src_end);
52
53 private:
64 template<typename T, T MIN, T MAX, unsigned scale_bits>
65 T Dither(T sample);
66
75 template<typename ST, typename DT>
76 typename DT::value_type DitherConvert(typename ST::value_type sample);
77
78 template<typename ST, typename DT>
79 void DitherConvert(typename DT::pointer_type dest,
80 typename ST::const_pointer_type src,
81 typename ST::const_pointer_type src_end);
82 };
83
84 #endif
PcmDither::Dither32To16
void Dither32To16(int16_t *dest, const int32_t *src, const int32_t *src_end)
PcmDither::Dither24To16
void Dither24To16(int16_t *dest, const int32_t *src, const int32_t *src_end)
SampleFormat
SampleFormat
Definition: SampleFormat.hxx:33
PcmDither::PcmDither
constexpr PcmDither()
Definition: PcmDither.hxx:32
PcmDither::DitherShift
ST DitherShift(ST sample)
Shift the given sample by #SBITS-#DBITS to the right, and apply dithering.
PcmDither
Definition: PcmDither.hxx:27