From b359f2ffaeab1407f79431463c7f572c7597b159 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Tue, 10 May 2022 18:03:02 +0200 Subject: [PATCH] Fix for panning by sin/cos and not linear. Also added missing gain fix. --- src/effect_mixer.hpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/effect_mixer.hpp b/src/effect_mixer.hpp index 65b9b18..2e55378 100644 --- a/src/effect_mixer.hpp +++ b/src/effect_mixer.hpp @@ -63,7 +63,7 @@ public: gain = MAX_GAIN; else if (gain < MIN_GAIN) gain = MIN_GAIN; - multiplier[i] = gain; + multiplier[i] = powf(gain, 4); // see: https://www.dr-lex.be/info-stuff/volumecontrols.html#ideal2 } } @@ -114,16 +114,22 @@ public: void doAddMix(uint8_t channel, float32_t* in) { float32_t tmp[buffer_length]; + float32_t sin_pan; + float32_t cos_pan; assert(in); + // From: https://stackoverflow.com/questions/67062207/how-to-pan-audio-sample-data-naturally + sin_pan=arm_sin_f32(mapfloat(panorama[channel], MIN_PANORAMA, MAX_PANORAMA, 0.0, M_PI/2.0)); + cos_pan=arm_cos_f32(mapfloat(panorama[channel], MIN_PANORAMA, MAX_PANORAMA, 0.0, M_PI/2.0)); + // left - arm_scale_f32(in, 1.0f-panorama[channel], tmp, buffer_length); + arm_scale_f32(in, sin_pan, tmp, buffer_length); if(multiplier[channel]!=UNITY_GAIN) arm_scale_f32(tmp,multiplier[channel],tmp,buffer_length); arm_add_f32(sumbufL, tmp, sumbufL, buffer_length); // right - arm_scale_f32(in, panorama[channel], tmp, buffer_length); + arm_scale_f32(in, cos_pan, tmp, buffer_length); if(multiplier[channel]!=UNITY_GAIN) arm_scale_f32(tmp,multiplier[channel],tmp,buffer_length); arm_add_f32(sumbufR, tmp, sumbufR, buffer_length);