1
0

MixFuncTable.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * MixFuncTable.cpp
  3. * ----------------
  4. * Purpose: Table containing all mixer functions.
  5. * Notes : The Visual Studio project settings for this file have been adjusted
  6. * to force function inlining, so that the mixer has a somewhat acceptable
  7. * performance in debug mode. If you need to debug anything here, be sure
  8. * to disable those optimizations if needed.
  9. * Authors: OpenMPT Devs
  10. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  11. */
  12. #include "stdafx.h"
  13. #include "Mixer.h"
  14. #include "Snd_defs.h"
  15. #include "ModChannel.h"
  16. #include "MixFuncTable.h"
  17. #ifdef MPT_INTMIXER
  18. #include "IntMixer.h"
  19. #else
  20. #include "FloatMixer.h"
  21. #endif // MPT_INTMIXER
  22. OPENMPT_NAMESPACE_BEGIN
  23. namespace MixFuncTable
  24. {
  25. #ifdef MPT_INTMIXER
  26. using I8M = Int8MToIntS;
  27. using I16M = Int16MToIntS;
  28. using I8S = Int8SToIntS;
  29. using I16S = Int16SToIntS;
  30. #else
  31. using I8M = Int8MToFloatS;
  32. using I16M = Int16MToFloatS;
  33. using I8S = Int8SToFloatS;
  34. using I16S = Int16SToFloatS;
  35. #endif // MPT_INTMIXER
  36. // Build mix function table for given resampling, filter and ramping settings: One function each for 8-Bit / 16-Bit Mono / Stereo
  37. #define BuildMixFuncTableRamp(resampling, filter, ramp) \
  38. SampleLoop<I8M, resampling<I8M>, filter<I8M>, MixMono ## ramp<I8M> >, \
  39. SampleLoop<I16M, resampling<I16M>, filter<I16M>, MixMono ## ramp<I16M> >, \
  40. SampleLoop<I8S, resampling<I8S>, filter<I8S>, MixStereo ## ramp<I8S> >, \
  41. SampleLoop<I16S, resampling<I16S>, filter<I16S>, MixStereo ## ramp<I16S> >
  42. // Build mix function table for given resampling, filter settings: With and without ramping
  43. #define BuildMixFuncTableFilter(resampling, filter) \
  44. BuildMixFuncTableRamp(resampling, filter, NoRamp), \
  45. BuildMixFuncTableRamp(resampling, filter, Ramp)
  46. // Build mix function table for given resampling settings: With and without filter
  47. #define BuildMixFuncTable(resampling) \
  48. BuildMixFuncTableFilter(resampling, NoFilter), \
  49. BuildMixFuncTableFilter(resampling, ResonantFilter)
  50. const MixFuncInterface Functions[6 * 16] =
  51. {
  52. BuildMixFuncTable(NoInterpolation), // No SRC
  53. BuildMixFuncTable(LinearInterpolation), // Linear SRC
  54. BuildMixFuncTable(FastSincInterpolation), // Fast Sinc (Cubic Spline) SRC
  55. BuildMixFuncTable(PolyphaseInterpolation), // Kaiser SRC
  56. BuildMixFuncTable(FIRFilterInterpolation), // FIR SRC
  57. BuildMixFuncTable(AmigaBlepInterpolation), // Amiga emulation
  58. };
  59. #undef BuildMixFuncTableRamp
  60. #undef BuildMixFuncTableFilter
  61. #undef BuildMixFuncTable
  62. ResamplingIndex ResamplingModeToMixFlags(ResamplingMode resamplingMode)
  63. {
  64. switch(resamplingMode)
  65. {
  66. case SRCMODE_NEAREST: return ndxNoInterpolation;
  67. case SRCMODE_LINEAR: return ndxLinear;
  68. case SRCMODE_CUBIC: return ndxFastSinc;
  69. case SRCMODE_SINC8LP: return ndxKaiser;
  70. case SRCMODE_SINC8: return ndxFIRFilter;
  71. case SRCMODE_AMIGA: return ndxAmigaBlep;
  72. default: MPT_ASSERT_NOTREACHED();
  73. }
  74. return ndxNoInterpolation;
  75. }
  76. } // namespace MixFuncTable
  77. OPENMPT_NAMESPACE_END