From 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d Mon Sep 17 00:00:00 2001 From: Jef Date: Tue, 24 Sep 2024 14:54:57 +0200 Subject: Initial community commit --- .../openmpt-trunk/soundlib/MixerLoops.cpp | 183 +++++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 Src/external_dependencies/openmpt-trunk/soundlib/MixerLoops.cpp (limited to 'Src/external_dependencies/openmpt-trunk/soundlib/MixerLoops.cpp') diff --git a/Src/external_dependencies/openmpt-trunk/soundlib/MixerLoops.cpp b/Src/external_dependencies/openmpt-trunk/soundlib/MixerLoops.cpp new file mode 100644 index 00000000..e0dc098a --- /dev/null +++ b/Src/external_dependencies/openmpt-trunk/soundlib/MixerLoops.cpp @@ -0,0 +1,183 @@ +/* + * MixerLoops.cpp + * -------------- + * Purpose: Utility inner loops for mixer-related functionality. + * Notes : This file contains performance-critical loops. + * Authors: Olivier Lapicque + * OpenMPT Devs + * The OpenMPT source code is released under the BSD license. Read LICENSE for more details. + */ + + +#include "stdafx.h" +#include "MixerLoops.h" +#include "Snd_defs.h" +#include "ModChannel.h" + + +OPENMPT_NAMESPACE_BEGIN + + + +void FloatToStereoMix(const float *pIn1, const float *pIn2, int32 *pOut, uint32 nCount, const float _f2ic) +{ + for(uint32 i=0; i=0; i--) + { + pFrontBuf[i*4+3] = pRearBuf[i*2+1]; + pFrontBuf[i*4+2] = pRearBuf[i*2+0]; + pFrontBuf[i*4+1] = pFrontBuf[i*2+1]; + pFrontBuf[i*4+0] = pFrontBuf[i*2+0]; + } +} + + + +void MonoFromStereo(mixsample_t *pMixBuf, uint32 nSamples) +{ + for(uint32 i=0; i(1.0 / (1 << 20)) // Decay threshold for floating point mixer + + +void StereoFill(mixsample_t *pBuffer, uint32 nSamples, mixsample_t &rofs, mixsample_t &lofs) +{ + if((!rofs) && (!lofs)) + { + InitMixBuffer(pBuffer, nSamples*2); + return; + } + for(uint32 i=0; i 0 ? 255 : -255)) / 256; + const mixsample_t x_r = mpt::rshift_signed(rofs + (mpt::rshift_signed(-rofs, sizeof(mixsample_t) * 8 - 1) & OFSDECAYMASK), OFSDECAYSHIFT); + const mixsample_t x_l = mpt::rshift_signed(lofs + (mpt::rshift_signed(-lofs, sizeof(mixsample_t) * 8 - 1) & OFSDECAYMASK), OFSDECAYSHIFT); +#else + const mixsample_t x_r = rofs * (1.0f / (1 << OFSDECAYSHIFT)); + const mixsample_t x_l = lofs * (1.0f / (1 << OFSDECAYSHIFT)); +#endif + rofs -= x_r; + lofs -= x_l; + pBuffer[i*2] = rofs; + pBuffer[i*2+1] = lofs; + } + +#ifndef MPT_INTMIXER + if(fabs(rofs) < OFSTHRESHOLD) rofs = 0; + if(fabs(lofs) < OFSTHRESHOLD) lofs = 0; +#endif +} + + +void EndChannelOfs(ModChannel &chn, mixsample_t *pBuffer, uint32 nSamples) +{ + + mixsample_t rofs = chn.nROfs; + mixsample_t lofs = chn.nLOfs; + + if((!rofs) && (!lofs)) + { + return; + } + for(uint32 i=0; i