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 10 11 #pragma once 12 13 #include "openmpt/all/BuildSettings.hpp" 14 15 #include "openmpt/soundbase/MixSample.hpp" 16 17 OPENMPT_NAMESPACE_BEGIN 18 19 #define MPT_INTMIXER 20 21 #ifdef MPT_INTMIXER 22 using mixsample_t = MixSampleIntTraits::sample_type; 23 enum { MIXING_FILTER_PRECISION = MixSampleIntTraits::filter_precision_bits }; // Fixed point resonant filter bits 24 #else 25 using mixsample_t = MixSampleFloat; 26 #endif 27 enum { MIXING_ATTENUATION = MixSampleIntTraits::mix_headroom_bits }; 28 enum { MIXING_FRACTIONAL_BITS = MixSampleIntTraits::mix_fractional_bits }; 29 30 inline constexpr float MIXING_SCALEF = MixSampleIntTraits::mix_scale<float>; 31 32 #ifdef MPT_INTMIXER 33 static_assert(sizeof(mixsample_t) == 4); 34 static_assert(MIXING_FILTER_PRECISION == 24); 35 static_assert(MIXING_ATTENUATION == 4); 36 static_assert(MIXING_FRACTIONAL_BITS == 27); 37 static_assert(MixSampleIntTraits::mix_clip_max == int32(0x7FFFFFF)); 38 static_assert(MixSampleIntTraits::mix_clip_min == (0 - int32(0x7FFFFFF))); 39 static_assert(MIXING_SCALEF == 134217728.0f); 40 #else 41 static_assert(sizeof(mixsample_t) == 4); 42 #endif 43 44 #define MIXBUFFERSIZE 512 45 #define NUMMIXINPUTBUFFERS 4 46 47 #define VOLUMERAMPPRECISION 12 // Fractional bits in volume ramp variables 48 49 // The absolute maximum number of sampling points any interpolation algorithm is going to look at in any direction from the current sampling point 50 // Currently, the maximum is 4 sampling points forwards and 3 sampling points backwards (Polyphase / FIR algorithms). 51 // Hence, this value must be at least 4. 52 inline constexpr uint8 InterpolationMaxLookahead = 4; 53 // While we could directly use the previous value in various places such as the interpolation wrap-around handling at loop points, 54 // choosing a higher value (e.g. 16) will reduce CPU usage when using many extremely short (length < 16) samples. 55 inline constexpr uint8 InterpolationLookaheadBufferSize = 16; 56 57 static_assert(InterpolationLookaheadBufferSize >= InterpolationMaxLookahead); 58 59 // Maximum size of a sampling point of a sample, in bytes. 60 // The biggest sampling point size is currently 16-bit stereo = 2 * 2 bytes. 61 inline constexpr uint8 MaxSamplingPointSize = 4; 62 63 OPENMPT_NAMESPACE_END 64