1
0

Dither.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Dither.h
  3. * --------
  4. * Purpose: Dithering when converting to lower resolution sample formats.
  5. * Notes : (currently none)
  6. * Authors: Olivier Lapicque
  7. * OpenMPT Devs
  8. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  9. */
  10. #pragma once
  11. #include "openmpt/all/BuildSettings.hpp"
  12. #include "mpt/base/macros.hpp"
  13. #include "mpt/string/types.hpp"
  14. #include "openmpt/soundbase/Dither.hpp"
  15. #include "openmpt/soundbase/DitherModPlug.hpp"
  16. #include "openmpt/soundbase/DitherNone.hpp"
  17. #include "openmpt/soundbase/DitherSimple.hpp"
  18. #include "mptRandom.h"
  19. #include <vector>
  20. #include <variant>
  21. #include <cstddef>
  22. OPENMPT_NAMESPACE_BEGIN
  23. using Dither_Default = Dither_Simple;
  24. class DitherNamesOpenMPT
  25. {
  26. public:
  27. static mpt::ustring GetModeName(std::size_t mode)
  28. {
  29. mpt::ustring result;
  30. switch(mode)
  31. {
  32. case 0:
  33. // no dither
  34. result = MPT_USTRING("no");
  35. break;
  36. case 1:
  37. // chosen by OpenMPT code, might change
  38. result = MPT_USTRING("default");
  39. break;
  40. case 2:
  41. // rectangular, 0.5 bit depth, no noise shaping (original ModPlug Tracker)
  42. result = MPT_USTRING("0.5 bit");
  43. break;
  44. case 3:
  45. // rectangular, 1 bit depth, simple 1st order noise shaping
  46. result = MPT_USTRING("1 bit");
  47. break;
  48. default:
  49. result = MPT_USTRING("");
  50. break;
  51. }
  52. return result;
  53. }
  54. };
  55. using DithersOpenMPT =
  56. Dithers<std::variant<MultiChannelDither<Dither_None>, MultiChannelDither<Dither_Default>, MultiChannelDither<Dither_ModPlug>, MultiChannelDither<Dither_Simple>>, DitherNamesOpenMPT, 4, 1, 0, mpt::good_prng>;
  57. struct DithersWrapperOpenMPT
  58. : DithersOpenMPT
  59. {
  60. template <typename Trd>
  61. DithersWrapperOpenMPT(Trd &rd, std::size_t mode = DithersOpenMPT::DefaultDither, std::size_t channels = DithersOpenMPT::DefaultChannels)
  62. : DithersOpenMPT(rd, mode, channels)
  63. {
  64. return;
  65. }
  66. };
  67. OPENMPT_NAMESPACE_END