Trying to optimize calculations.

pull/32/head
Holger Wirtz 5 years ago
parent b0e432a9e0
commit 1651855403
  1. 9
      PluginFx.cpp
  2. 4
      config.h
  3. 15
      effect_mono_stereo.cpp
  4. 2
      effect_mono_stereo.h
  5. 2
      effect_stereo_mono.cpp
  6. 41
      synth.h

@ -25,6 +25,7 @@
#define _USE_MATH_DEFINES
#include <math.h>
#include "PluginFx.h"
#include "synth.h"
const float dc = 1e-18;
@ -48,7 +49,7 @@ inline static float tptlpupw(float & state , float inp , float cutoff , float sr
//}
static float logsc(float param, const float min, const float max, const float rolloff = 19.0f) {
return ((expf(param * logf(rolloff + 1)) - 1.0f) / (rolloff)) * (max - min) + min;
return ((EXP_FUNC(param * LOG_FUNC(rolloff + 1)) - 1.0f) / (rolloff)) * (max - min) + min;
}
PluginFx::PluginFx() {
@ -67,7 +68,11 @@ void PluginFx::init(int sr) {
sampleRate = sr;
sampleRateInv = 1 / sampleRate;
float rcrate = sqrt((44000 / sampleRate));
#if defined(ARM_SQRT_FUNC)
float rcrate; ARM_SQRT_FUNC(44000 / sampleRate, &rcrate);
#else
float rcrate = SQRT_FUNC((44000 / sampleRate));
#endif
rcor24 = (970.0 / 44000) * rcrate;
rcor24Inv = 1 / rcor24;

@ -229,9 +229,9 @@ enum { DEXED, REVERB, DELAY, CHORUS };
// Teensy-3.6 settings
#define MIDI_DEVICE_USB_HOST 1
#if defined(USE_REVERB)
#define MAX_NOTES 11
#else
#define MAX_NOTES 14
#else
#define MAX_NOTES 16
#endif
#endif

@ -51,20 +51,15 @@ void AudioEffectMonoStereo::update(void)
if (in && mod && out[0] && out[1])
{
int16_t *ip = in->data;
float pan = mapfloat(mod->data[0], -1.0, 1.0, 0.0, 1.0);
int16_t *op[2] = { out[0]->data, out[1]->data };
const float f[2] = { _pseudo_log * arm_sin_f32(pan * PI / 2), _pseudo_log * arm_cos_f32(pan * PI / 2) }; // Pan [L0.0 ... M0.5 ... 1.0R]
float f_l = _pseudo_log * sinf(pan * PI / 2); // Pan [L0.0 ... M0.5 ... 1.0R]
float f_r = _pseudo_log * cosf(pan * PI / 2);
arm_q15_to_float (in->data, in_f, AUDIO_BLOCK_SAMPLES);
for (uint16_t i = 0; i < AUDIO_BLOCK_SAMPLES; i++)
for (uint8_t i = 0; i < 2; i++)
{
*op[0] = int16_t(f_l * (*ip));
*op[1] = int16_t(f_r * (*ip));
op[0]++;
op[1]++;
ip++;
arm_scale_f32 (in_f, f[i], out_f[i], AUDIO_BLOCK_SAMPLES);
arm_float_to_q15 (out_f[i], out[i]->data, AUDIO_BLOCK_SAMPLES);
}
if (in)

@ -45,6 +45,8 @@ class AudioEffectMonoStereo : public AudioStream
private:
audio_block_t *inputQueueArray[2];
audio_block_t *out[2];
float in_f[AUDIO_BLOCK_SAMPLES];
float out_f[2][AUDIO_BLOCK_SAMPLES];
const float _pseudo_log = 1048575 / (float)(1 << 20);
};

@ -56,7 +56,7 @@ void AudioEffectStereoMono::update(void)
bp[1]++;
}
#else
// device every channel by 2
// devide every channel by 2
arm_shift_q15(block[0]->data, -1, block[0]->data, AUDIO_BLOCK_SAMPLES);
arm_shift_q15(block[1]->data, -1, block[1]->data, AUDIO_BLOCK_SAMPLES);
// add channel 2 to channel 1

@ -1,18 +1,18 @@
/*
* Copyright 2012 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Copyright 2012 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef __SYNTH_H
#define __SYNTH_H
@ -53,20 +53,25 @@ typedef __int16 SInt16;
template<typename T>
inline static T min(const T& a, const T& b) {
return a < b ? a : b;
return a < b ? a : b;
}
template<typename T>
inline static T max(const T& a, const T& b) {
return a > b ? a : b;
return a > b ? a : b;
}
#define QER(n,b) ( ((float)n)/(1<<b) )
#define FRAC_NUM float
#define SIN_FUNC sinf
#define COS_FUNC cosf
//#define SIN_FUNC sinf
#define SIN_FUNC arm_sin_f32 // very fast but not as accurate
//#define COS_FUNC cosf
#define COS_FUNC arm_cos_f32 // very fast but not as accurate
#define LOG_FUNC logf
#define EXP_FUNC expf
#define SQRT_FUNC sqrtf
#define ARM_SQRT_FUNC arm_sqrt_f32 // fast but not as accurate
#endif // __SYNTH_H

Loading…
Cancel
Save