From c02169a6c8ba7cd9b9b06f8670187bdbced8283a Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Mon, 18 Jan 2021 15:29:13 +0100 Subject: [PATCH] Micro-optimization: pre-calculate pan-law powf() is very expensive to call, and as long as the pan-law is fixed, there is no need to re-calculate coefficient scale factor on every update. --- libs/panners/1in2out/panner_1in2out.cc | 13 ++++++++++--- libs/panners/2in2out/panner_2in2out.cc | 10 +++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/libs/panners/1in2out/panner_1in2out.cc b/libs/panners/1in2out/panner_1in2out.cc index 8cf6b70e0c..14e9d614af 100644 --- a/libs/panners/1in2out/panner_1in2out.cc +++ b/libs/panners/1in2out/panner_1in2out.cc @@ -101,12 +101,15 @@ Panner1in2out::~Panner1in2out () void Panner1in2out::update () { - float panR, panL; +#if 0 float const pan_law_attenuation = -3.0f; float const scale = 2.0f - 4.0f * powf (10.0f, pan_law_attenuation / 20.0f); +#else + float const scale = -0.831783138f; +#endif - panR = _pannable->pan_azimuth_control->get_value (); - panL = 1 - panR; + float const panR = _pannable->pan_azimuth_control->get_value (); + float const panL = 1 - panR; desired_left = panL * (scale * panL + 1.0f - scale); desired_right = panR * (scale * panR + 1.0f - scale); @@ -275,8 +278,12 @@ Panner1in2out::distribute_one_automated (AudioBuffer& srcbuf, BufferSet& obufs, each buffer (output) */ +#if 0 const float pan_law_attenuation = -3.0f; const float scale = 2.0f - 4.0f * powf (10.0f, pan_law_attenuation / 20.0f); +#else + float const scale = -0.831783138f; +#endif for (pframes_t n = 0; n < nframes; ++n) { float panR = position[n]; diff --git a/libs/panners/2in2out/panner_2in2out.cc b/libs/panners/2in2out/panner_2in2out.cc index e7c1365e46..0664bc63cd 100644 --- a/libs/panners/2in2out/panner_2in2out.cc +++ b/libs/panners/2in2out/panner_2in2out.cc @@ -184,9 +184,13 @@ Panner2in2out::update () } /* compute target gain coefficients for both input signals */ - +#if 0 float const pan_law_attenuation = -3.0f; float const scale = 2.0f - 4.0f * powf (10.0f, pan_law_attenuation / 20.0f); +#else + float const scale = -0.831783138f; +#endif + float panR; float panL; @@ -408,8 +412,12 @@ Panner2in2out::distribute_one_automated (AudioBuffer& srcbuf, BufferSet& obufs, * each buffer (output) */ +#if 0 const float pan_law_attenuation = -3.0f; const float scale = 2.0f - 4.0f * powf (10.0f, pan_law_attenuation / 20.0f); +#else + float const scale = -0.831783138f; +#endif for (pframes_t n = 0; n < nframes; ++n) { float panR;