From b6df892a44024f3c221a0cf67fa6748b3f4818d7 Mon Sep 17 00:00:00 2001 From: Holger Date: Wed, 11 May 2022 08:08:12 +0200 Subject: [PATCH] Fixing linear internal mixer to non-linear (x^4) / Fixing linear pan to non-linear (sin/cos) #182 (#210) --- src/effect_mixer.hpp | 14 ++++++++++---- src/serialmididevice.cpp | 2 ++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/effect_mixer.hpp b/src/effect_mixer.hpp index f8e7865..2e55378 100644 --- a/src/effect_mixer.hpp +++ b/src/effect_mixer.hpp @@ -52,7 +52,7 @@ public: gain = MAX_GAIN; else if (gain < MIN_GAIN) gain = MIN_GAIN; - multiplier[channel] = gain; + multiplier[channel] = powf(gain, 4); // see: https://www.dr-lex.be/info-stuff/volumecontrols.html#ideal2 } void gain(float32_t gain) @@ -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); diff --git a/src/serialmididevice.cpp b/src/serialmididevice.cpp index 6c484cf..fa81785 100644 --- a/src/serialmididevice.cpp +++ b/src/serialmididevice.cpp @@ -57,6 +57,8 @@ void CSerialMIDIDevice::Process (void) int nResult = m_Serial.Read (Buffer, sizeof Buffer); if (nResult <= 0) { + if(nResult!=0) + printf("Serial-Read: %d\n",nResult); return; }