Skip to content
Snippets Groups Projects

(external) bl00mbox: more inlining, performance++

Merged moon2 requested to merge blminline2 into main
8 files
+ 80
109
Compare changes
  • Side-by-side
  • Inline
Files
8
#include "lowpass.h"
//#define LOWPASS_DEBUG_PRINT
#ifdef LOWPASS_DEBUG_PRINT
#include <stdio.h>
#endif
radspa_t * lowpass_create(uint32_t init_var);
radspa_descriptor_t lowpass_desc = {
.name = "lowpass",
@@ -23,63 +17,37 @@ radspa_descriptor_t lowpass_desc = {
#define LOWPASS_GAIN 4
#define LOWPASS_INTERNAL_SHIFT 14
#define LOWPASS_OUT_COEFF_SHIFT 11
static void coeff_shift(uint64_t coeff, int32_t *shift, int32_t * shifted_coeff) {
int32_t ret = 22;
uint64_t ret_coeff = coeff >> (32-ret);
while(1){
if(ret > 31){
ret = 31;
ret_coeff = coeff >> (32-ret);
break;
}
if(ret < (LOWPASS_INTERNAL_SHIFT)){
ret = (LOWPASS_INTERNAL_SHIFT);
ret_coeff = coeff >> (32-ret);
break;
}
if(ret_coeff > (1UL<<14)){
ret -= 3;
ret_coeff = coeff >> (32-ret);
} else if (ret_coeff < (1UL<<11)){
ret += 3;
ret_coeff = coeff >> (32-ret);
} else {
break;
}
}
* shift = ret;
* shifted_coeff = (int32_t) ret_coeff;
}
#define LOWPASS_OUT_COEFF_SHIFT 30
#define LOWPASS_SUM_SHIFT 25
static void set_lowpass_coeffs(lowpass_data_t * data, int32_t freq, int32_t mq){
if(freq < 15.) freq = 15.;
if(freq > 15000.) freq = 15000.;
if(mq < 130) mq = 130;
if(mq < 140) mq = 140;
int32_t K = 15287; // 2*48000/6.28
int32_t omega = freq;
int32_t mq_rec = (1UL<<31)/(mq+1);
int32_t A[3];
A[0] = K * K;
A[1] = K * 1000;
A[1] = (int64_t) A[1] * omega / (mq+1);
A[1] = K * omega * 8;
A[1] = ((int64_t) A[1] * mq_rec) >> 32;
A[1] *= 250;
A[2] = omega*omega;
int32_t sum_a = A[0] + A[1] + A[2];
int64_t round = A[2];
// slow, figure out smth smarther:
int32_t sum_a_rec = (1ULL<<(32 + (LOWPASS_SUM_SHIFT))) / (A[0] + A[1] + A[2]);
round = (round << 32) / sum_a;
int32_t shift;
int32_t shifted_coeff;
coeff_shift(round, &shift, &shifted_coeff);
data->in_coeff_shift = shift - (LOWPASS_INTERNAL_SHIFT);
data->in_coeff = shifted_coeff;
int32_t tmp;
round = 2.*(A[2]-A[0]);
data->out_coeff[0] = round * (1LL<<(LOWPASS_OUT_COEFF_SHIFT)) / sum_a;
tmp = (int64_t) A[2] * sum_a_rec >> 32;
data->in_coeff = tmp << (32-LOWPASS_SUM_SHIFT);
round = (A[0]-A[1]+A[2]);
data->out_coeff[1] = round * (1LL<<(LOWPASS_OUT_COEFF_SHIFT)) / sum_a;
tmp = 2.*(A[2]-A[0]);
tmp = ((int64_t) tmp * sum_a_rec) >> 32;
data->out_coeff[0] = tmp<<((LOWPASS_OUT_COEFF_SHIFT) - (LOWPASS_SUM_SHIFT));
tmp = (A[0]-A[1]+A[2]);
tmp = ((int64_t) tmp * sum_a_rec) >> 32;
data->out_coeff[1] = tmp<<((LOWPASS_OUT_COEFF_SHIFT) - (LOWPASS_SUM_SHIFT));
}
@@ -100,11 +68,6 @@ void lowpass_run(radspa_t * lowpass, uint16_t num_samples, uint32_t render_pass_
if((freq != data->prev_freq) | (q != data->prev_q)){
set_lowpass_coeffs(data, freq, q);
#ifdef LOWPASS_DEBUG_PRINT
printf("\nfreq: %ld, q: %d\n", freq, q);
printf("in_coeff: %ld >> %ld, ", data->in_coeff, data->in_coeff_shift);
printf("out_coeffs: %ld, %ld\n", data->out_coeff[0], data->out_coeff[1]);
#endif
data->prev_freq = freq;
data->prev_q = q;
}
@@ -121,11 +84,13 @@ void lowpass_run(radspa_t * lowpass, uint16_t num_samples, uint32_t render_pass_
int8_t pos = data->pos - i - 1;
if(pos < 0) pos += 3;
in_acc += (2-i)*data->in_history[pos];
ret -= (((int64_t) data->out_history[pos]) * data->out_coeff[i]) >> (LOWPASS_OUT_COEFF_SHIFT);
ret -= (((int64_t) data->out_history[pos]) * data->out_coeff[i]) >> 32;
}
ret += (in_acc * data->in_coeff) >> data->in_coeff_shift;
ret = ret << (32 - LOWPASS_OUT_COEFF_SHIFT);
in_acc = in_acc << (LOWPASS_INTERNAL_SHIFT);
in_acc = ((int64_t) in_acc * data->in_coeff) >> 32;
ret += in_acc;
data->out_history[data->pos] = ret;
Loading