diff options
Diffstat (limited to 'src/pcm/PcmDither.hxx')
-rw-r--r-- | src/pcm/PcmDither.hxx | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/src/pcm/PcmDither.hxx b/src/pcm/PcmDither.hxx index 106382307..473a45ac3 100644 --- a/src/pcm/PcmDither.hxx +++ b/src/pcm/PcmDither.hxx @@ -22,6 +22,8 @@ #include <stdint.h> +enum class SampleFormat : uint8_t; + class PcmDither { int32_t error[3]; int32_t random; @@ -30,6 +32,18 @@ public: constexpr PcmDither() :error{0, 0, 0}, random(0) {} + /** + * Shift the given sample by #SBITS-#DBITS to the right, and + * apply dithering. + * + * @param ST the input sample type + * @param SBITS the input bit width + * @param DBITS the output bit width + * @param sample the input sample value + */ + template<typename ST, unsigned SBITS, unsigned DBITS> + ST DitherShift(ST sample); + void Dither24To16(int16_t *dest, const int32_t *src, const int32_t *src_end); @@ -37,8 +51,34 @@ public: const int32_t *src_end); private: - int16_t Dither24To16(int_fast32_t sample); - int16_t Dither32To16(int_fast32_t sample); + /** + * Shift the given sample by #scale_bits to the right, and + * apply dithering. + * + * @param T the input sample type + * @param MIN the minimum input sample value + * @param MAX the maximum input sample value + * @param scale_bits the number of bits to be discarded + * @param sample the input sample value + */ + template<typename T, T MIN, T MAX, unsigned scale_bits> + T Dither(T sample); + + /** + * Convert the given sample from one sample format to another, + * discarding bits. + * + * @param ST the input #SampleTraits class + * @param ST the output #SampleTraits class + * @param sample the input sample value + */ + template<typename ST, typename DT> + typename DT::value_type DitherConvert(typename ST::value_type sample); + + template<typename ST, typename DT> + void DitherConvert(typename DT::pointer_type dest, + typename ST::const_pointer_type src, + typename ST::const_pointer_type src_end); }; #endif |