1
0

Mixer.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Mixer.h
  3. * -------
  4. * Purpose: Basic mixer constants
  5. * Notes : (currently none)
  6. * Authors: OpenMPT Devs
  7. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  8. */
  9. #pragma once
  10. #include "openmpt/all/BuildSettings.hpp"
  11. #include "openmpt/soundbase/MixSample.hpp"
  12. OPENMPT_NAMESPACE_BEGIN
  13. #define MPT_INTMIXER
  14. #ifdef MPT_INTMIXER
  15. using mixsample_t = MixSampleIntTraits::sample_type;
  16. enum { MIXING_FILTER_PRECISION = MixSampleIntTraits::filter_precision_bits }; // Fixed point resonant filter bits
  17. #else
  18. using mixsample_t = MixSampleFloat;
  19. #endif
  20. enum { MIXING_ATTENUATION = MixSampleIntTraits::mix_headroom_bits };
  21. enum { MIXING_FRACTIONAL_BITS = MixSampleIntTraits::mix_fractional_bits };
  22. inline constexpr float MIXING_SCALEF = MixSampleIntTraits::mix_scale<float>;
  23. #ifdef MPT_INTMIXER
  24. static_assert(sizeof(mixsample_t) == 4);
  25. static_assert(MIXING_FILTER_PRECISION == 24);
  26. static_assert(MIXING_ATTENUATION == 4);
  27. static_assert(MIXING_FRACTIONAL_BITS == 27);
  28. static_assert(MixSampleIntTraits::mix_clip_max == int32(0x7FFFFFF));
  29. static_assert(MixSampleIntTraits::mix_clip_min == (0 - int32(0x7FFFFFF)));
  30. static_assert(MIXING_SCALEF == 134217728.0f);
  31. #else
  32. static_assert(sizeof(mixsample_t) == 4);
  33. #endif
  34. #define MIXBUFFERSIZE 512
  35. #define NUMMIXINPUTBUFFERS 4
  36. #define VOLUMERAMPPRECISION 12 // Fractional bits in volume ramp variables
  37. // The absolute maximum number of sampling points any interpolation algorithm is going to look at in any direction from the current sampling point
  38. // Currently, the maximum is 4 sampling points forwards and 3 sampling points backwards (Polyphase / FIR algorithms).
  39. // Hence, this value must be at least 4.
  40. inline constexpr uint8 InterpolationMaxLookahead = 4;
  41. // While we could directly use the previous value in various places such as the interpolation wrap-around handling at loop points,
  42. // choosing a higher value (e.g. 16) will reduce CPU usage when using many extremely short (length < 16) samples.
  43. inline constexpr uint8 InterpolationLookaheadBufferSize = 16;
  44. static_assert(InterpolationLookaheadBufferSize >= InterpolationMaxLookahead);
  45. // Maximum size of a sampling point of a sample, in bytes.
  46. // The biggest sampling point size is currently 16-bit stereo = 2 * 2 bytes.
  47. inline constexpr uint8 MaxSamplingPointSize = 4;
  48. OPENMPT_NAMESPACE_END