From 807d152020ac2f6e498f33cbbd025f5c7261c163 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Tue, 18 Jun 2019 11:13:18 +0200 Subject: [PATCH] Added IIR filter (1-order, 3-order) for filtering LP-filtering the mdulation signal at 5000 Hz (just for testing). --- config.h | 7 ++--- effect_modulated_delay.cpp | 52 +++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/config.h b/config.h index ebf74a8..c067c6c 100644 --- a/config.h +++ b/config.h @@ -56,9 +56,10 @@ #define REDUCE_LOUDNESS 0 #define USE_XFADE_DATA 1 // CHORUS parameters -#define INTERPOLATION_WINDOW_SIZE 21 // use only odd numbers!!! -//#define INTERPOLATE_MODE 11 -#define CHORUS_WAVEFORM WAVEFORM_SINE // WAVEFORM_SINE WAVEFORM_TRIANGLE WAVEFORM_SAWTOOTH WAVEFORM_SAWTOOTH_REVERSE +#define INTERPOLATION_WINDOW_SIZE 7 // use only odd numbers!!! +#define INTERPOLATE_MODE 11 +#define FILTER_IIR_ORDER_3 1 +#define CHORUS_WAVEFORM WAVEFORM_TRIANGLE // WAVEFORM_SINE WAVEFORM_TRIANGLE WAVEFORM_SAWTOOTH WAVEFORM_SAWTOOTH_REVERSE #define CHORUS_DELAY_LENGTH_SAMPLES (15*AUDIO_BLOCK_SAMPLES) // one AUDIO_BLOCK_SAMPLES = 2.902ms; you need doubled length, e.g. delay point is 20ms, so you need up to 40ms delay! //************************************************************************************************* diff --git a/effect_modulated_delay.cpp b/effect_modulated_delay.cpp index c0e06f1..46d8b85 100644 --- a/effect_modulated_delay.cpp +++ b/effect_modulated_delay.cpp @@ -26,6 +26,7 @@ #include "limits.h" #include "effect_modulated_delay.h" #include "spline.h" +#include "config.h" /******************************************************************/ @@ -99,7 +100,56 @@ void AudioEffectModulatedDelay::update(void) // Calculate modulation index as a float, for interpolation later. // The index is located around the half of the delay length multiplied by the current amount of the modulator - mod_idx = float(*mp) / SHRT_MAX * float(_delay_length >> 1); + /************************************************************************************************************** + Use an IIR filter on the modulation for avoiding aliasing (http://www-users.cs.york.ac.uk/~fisher/mkfilter/) */ +#if defined(FILTER_IIR_ORDER_1) + /* Digital filter designed by mkfilter/mkshape/gencode A.J. Fisher + Command line: /www/usr/fisher/helpers/mkfilter -Bu -Lp -o 1 -a 1.1333499558e-01 0.0000000000e+00 -l + Parameters: filtertype = Butterworth + passtype = Lowpass + ripple = + order = 1 + samplerate = 44117.64706 + corner1 = 5000 + corner2 = + adzero = + logmin = + **************************************************************************************************************/ +#define NZEROS 1 +#define NPOLES 1 +#define GAIN 3.688918967e+00 + static float xv[NZEROS + 1], yv[NPOLES + 1]; + xv[0] = xv[1]; + xv[1] = (float(*mp) / SHRT_MAX) / GAIN; + yv[0] = yv[1]; + yv[1] = (xv[0] + xv[1]) + (0.4578357460 * yv[0]); + //new_value = yv[1]; + mod_idx = yv[1] * float(_delay_length >> 1); +#elif defined(FILTER_IIR_ORDER_3) + /* Digital filter designed by mkfilter/mkshape/gencode A.J. Fisher + Command line: /www/usr/fisher/helpers/mkfilter -Bu -Lp -o 3 -a 1.1333333333e-01 0.0000000000e+00 -l + raw alpha1 = 0.1133333333 + raw alpha2 = 0.1133333333 + warped alpha1 = 0.1183783855 + warped alpha2 = 0.1183783855 + gain at dc : mag = 4.028005941e+01 phase = 0.0000000000 pi + gain at centre: mag = 2.848230315e+01 phase = -0.7500000000 pi + gain at hf : mag = 0.000000000e+00 + **************************************************************************************************************/ +#define NZEROS 3 +#define NPOLES 3 +#define GAIN 4.028005941e+01 + static float xv[NZEROS + 1], yv[NPOLES + 1]; + xv[0] = xv[1]; xv[1] = xv[2]; xv[2] = xv[3]; + xv[3] = (float(*mp) / SHRT_MAX) / GAIN; + yv[0] = yv[1]; yv[1] = yv[2]; yv[2] = yv[3]; + yv[3] = (xv[0] + xv[3]) + 3 * (xv[1] + xv[2]) + + ( 0.2323461955 * yv[0]) + ( -1.0299524229 * yv[1]) + + ( 1.5989967885 * yv[2]); + //new_value = yv[3]; + mod_idx = yv[3] * float(_delay_length >> 1); + /************************************************************************/ +#endif mod_fraction = modff(mod_idx, &mod_number); #ifdef INTERPOLATE_MODE