summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorJan Holthuis <jan.holthuis@ruhr-uni-bochum.de>2020-06-20 12:39:22 +0200
committerJan Holthuis <jan.holthuis@ruhr-uni-bochum.de>2020-06-20 12:39:22 +0200
commit075ecf50e0d60cf65d4eb280a7d939086c54468e (patch)
tree649d4149ca6f047bb450e2b5d3ca0a18017ab1d0 /src/util
parentc3d69aed24546dec3bdb01898a629024808c0028 (diff)
parentc1b119aeecd449e1e68b984d1a05d5835ec9301a (diff)
Merge branch '2.3' of github.com:mixxxdj/mixxx
Diffstat (limited to 'src/util')
-rw-r--r--src/util/sample.cpp30
-rw-r--r--src/util/sample.h13
2 files changed, 30 insertions, 13 deletions
diff --git a/src/util/sample.cpp b/src/util/sample.cpp
index d657979773..ba79d67ab9 100644
--- a/src/util/sample.cpp
+++ b/src/util/sample.cpp
@@ -446,19 +446,37 @@ void SampleUtil::deinterleaveBuffer(CSAMPLE* M_RESTRICT pDest1,
}
// static
-void SampleUtil::linearCrossfadeBuffers(CSAMPLE* pDest,
- const CSAMPLE* pSrcFadeOut, const CSAMPLE* pSrcFadeIn,
+void SampleUtil::linearCrossfadeBuffersOut(
+ CSAMPLE* pDestSrcFadeOut,
+ const CSAMPLE* pSrcFadeIn,
SINT numSamples) {
+ // M_RESTRICT unoptimizes the function for some reason.
const CSAMPLE_GAIN cross_inc = CSAMPLE_GAIN_ONE
/ CSAMPLE_GAIN(numSamples / 2);
// note: LOOP VECTORIZED. only with "int i"
for (int i = 0; i < numSamples / 2; ++i) {
const CSAMPLE_GAIN cross_mix = cross_inc * i;
- pDest[i * 2] = pSrcFadeIn[i * 2] * cross_mix
- + pSrcFadeOut[i * 2] * (CSAMPLE_GAIN_ONE - cross_mix);
- pDest[i * 2 + 1] = pSrcFadeIn[i * 2 + 1] * cross_mix
- + pSrcFadeOut[i * 2 + 1] * (CSAMPLE_GAIN_ONE - cross_mix);
+ pDestSrcFadeOut[i * 2] *= (CSAMPLE_GAIN_ONE - cross_mix);
+ pDestSrcFadeOut[i * 2] += pSrcFadeIn[i * 2] * cross_mix;
+ pDestSrcFadeOut[i * 2 + 1] *= (CSAMPLE_GAIN_ONE - cross_mix);
+ pDestSrcFadeOut[i * 2 + 1] += pSrcFadeIn[i * 2 + 1] * cross_mix;
+ }
+}
+// static
+void SampleUtil::linearCrossfadeBuffersIn(
+ CSAMPLE* pDestSrcFadeIn,
+ const CSAMPLE* pSrcFadeOut,
+ SINT numSamples) {
+ // M_RESTRICT unoptimizes the function for some reason.
+ const CSAMPLE_GAIN cross_inc = CSAMPLE_GAIN_ONE / CSAMPLE_GAIN(numSamples / 2);
+ // note: LOOP VECTORIZED. only with "int i"
+ for (int i = 0; i < numSamples / 2; ++i) {
+ const CSAMPLE_GAIN cross_mix = cross_inc * i;
+ pDestSrcFadeIn[i * 2] *= cross_mix;
+ pDestSrcFadeIn[i * 2] += pSrcFadeOut[i * 2] * (CSAMPLE_GAIN_ONE - cross_mix);
+ pDestSrcFadeIn[i * 2 + 1] *= cross_mix;
+ pDestSrcFadeIn[i * 2 + 1] += pSrcFadeOut[i * 2 + 1] * (CSAMPLE_GAIN_ONE - cross_mix);
}
}
diff --git a/src/util/sample.h b/src/util/sample.h
index fbf5510fb1..4ccabe13c0 100644
--- a/src/util/sample.h
+++ b/src/util/sample.h
@@ -223,13 +223,12 @@ class SampleUtil {
static void deinterleaveBuffer(CSAMPLE* pDest1, CSAMPLE* pDest2,
const CSAMPLE* pSrc, SINT numSamples);
- // Crossfade two buffers together and put the result in pDest. All the
- // buffers must be the same length. pDest may be an alias of the source
- // buffers. It is preferable to use the copyWithRamping functions, but
- // sometimes this function is necessary.
- static void linearCrossfadeBuffers(CSAMPLE* pDest,
- const CSAMPLE* pSrcFadeOut, const CSAMPLE* pSrcFadeIn,
- SINT numSamples);
+ /// Crossfade two buffers together. All the buffers must be the same length.
+ /// pDest is in one version the Out and in the other version the In buffer.
+ static void linearCrossfadeBuffersOut(
+ CSAMPLE* pDestSrcFadeOut, const CSAMPLE* pSrcFadeIn, SINT numSamples);
+ static void linearCrossfadeBuffersIn(
+ CSAMPLE* pDestSrcFadeIn, const CSAMPLE* pSrcFadeOut, SINT numSamples);
// Mix a buffer down to mono, putting the result in both of the channels.
// This uses a simple (L+R)/2 method, which assumes that the audio is