aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2019-08-23 11:31:11 +0200
committerAndreas Eversberg <jolly@eversberg.eu>2019-08-26 21:10:39 +0200
commit31fca59294d2a916c3c74fcd90310ec293480b02 (patch)
tree59f254b79323c83414d7ba5a2ff5c38dddc2b2c3 /src
parentf86adf4bb5b40a2e8a255ad9eb064a5daea0bb6e (diff)
Fixed performance issue with IIR filter
Passing samples with zero value (0.0) causes very slow processing of IIR filter on my test machine 'nuedel'. I don't know why. To solve this, I add a very small number to each input sample.
Diffstat (limited to 'src')
-rw-r--r--src/libfilter/iir_filter.c8
-rw-r--r--src/libfm/fm.c5
2 files changed, 5 insertions, 8 deletions
diff --git a/src/libfilter/iir_filter.c b/src/libfilter/iir_filter.c
index 2123feb..5872d61 100644
--- a/src/libfilter/iir_filter.c
+++ b/src/libfilter/iir_filter.c
@@ -104,7 +104,7 @@ void iir_notch_init(iir_filter_t *filter, double frequency, int samplerate, int
filter->b1 = filter->a1;
filter->b2 = (1 - K / Q + K * K) * norm;
}
-
+
void iir_process(iir_filter_t *filter, sample_t *samples, int length)
{
double a0, a1, a2, b1, b2;
@@ -126,7 +126,8 @@ void iir_process(iir_filter_t *filter, sample_t *samples, int length)
/* process filter */
for (i = 0; i < length; i++) {
- in = *samples;
+ /* add a small value, otherwise this loop will perform really bad on my 'nuedel' machine!!! */
+ in = *samples + 0.000000001;
for (j = 0; j < iterations; j++) {
out = in * a0 + z1[j];
z1[j] = in * a1 + z2[j] - b1 * out;
@@ -163,7 +164,8 @@ void iir_process_baseband(iir_filter_t *filter, float *baseband, int length)
/* process filter */
for (i = 0; i < length; i++) {
- in = *baseband;
+ /* add a small value, otherwise this loop will perform really bad on my 'nuedel' machine!!! */
+ in = *baseband + 0.000000001;
for (j = 0; j < iterations; j++) {
out = in * a0 + z1[j];
#ifdef DEBUG_NAN
diff --git a/src/libfm/fm.c b/src/libfm/fm.c
index 48b4f11..d8f7afa 100644
--- a/src/libfm/fm.c
+++ b/src/libfm/fm.c
@@ -92,7 +92,6 @@ int fm_mod_init(fm_mod_t *mod, double samplerate, double offset, double amplitud
/* generate ramp up with ramp_length */
for (i = 0; i < mod->ramp_length; i++)
mod->ramp_tab[i] = 0.5 - cos(M_PI * i / mod->ramp_length) / 2.0;
- mod->ramp_tab[0] = mod->ramp_tab[1] / 2.0; /* never be 0 */
return 0;
}
@@ -199,10 +198,6 @@ again:
dev = offset + *frequency++;
power++;
length--;
- /* somehow we need to have some value, otherwise IIR filter will be very slow!
- * we still continue with a carrier, but it has very low amplitude.
- * the low amplitude is set in ramp_tab[0]
- */
if (fast_math) {
phase += 65536.0 * dev / rate;
if (phase < 0.0)