From 6dd9bb923ba2f4a25608a7c53a841838e957ec87 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Fri, 12 Jul 2019 17:59:42 +0200 Subject: [PATCH] Removed code for spline interpolation. --- config.h | 7 +-- effect_modulated_delay.cpp | 23 +------- effect_modulated_delay.h | 6 -- spline.cpp | 111 ------------------------------------- spline.h | 43 -------------- 5 files changed, 3 insertions(+), 187 deletions(-) delete mode 100644 spline.cpp delete mode 100644 spline.h diff --git a/config.h b/config.h index f120947..6a81f83 100644 --- a/config.h +++ b/config.h @@ -26,7 +26,6 @@ #include "midinotes.h" #include -#include "spline.h" // ATTENTION! For better latency you have to redefine AUDIO_BLOCK_SAMPLES from // 128 to 64 in /cores/teensy3/AudioStream.h @@ -60,10 +59,6 @@ #define CHORUS_WAVEFORM WAVEFORM_TRIANGLE // WAVEFORM_SINE WAVEFORM_TRIANGLE WAVEFORM_SAWTOOTH WAVEFORM_SAWTOOTH_REVERSE #define CHORUS_MODULATOR_FILTER_FRQ 500 #define CHORUS_MODULATOR_FILTER_Q 0.7 -//#define CHORUS_INTERPOLATION_MODE 0 // no interpolation -//#define CHORUS_INTERPOLATION_MODE 1 // linear interpolation -//#define CHORUS_INTERPOLATION_MODE Catmull // spline interpolation -#define CHORUS_INTERPOLATION_WINDOW_SIZE 5 // only uneven numbers bigger than 3!!! //************************************************************************************************* //* DEBUG OUTPUT SETTINGS @@ -73,7 +68,7 @@ #define SERIAL_SPEED 38400 #define SHOW_XRUN 1 #define SHOW_CPU_LOAD_MSEC 5000 -#define DEBUG_AUDIO 50 +//#define DEBUG_AUDIO 50 //************************************************************************************************* //* HARDWARE SETTINGS diff --git a/effect_modulated_delay.cpp b/effect_modulated_delay.cpp index 5a020de..7693fa0 100644 --- a/effect_modulated_delay.cpp +++ b/effect_modulated_delay.cpp @@ -25,7 +25,6 @@ #include #include "limits.h" #include "effect_modulated_delay.h" -#include "spline.h" #include "config.h" /******************************************************************/ @@ -87,10 +86,6 @@ void AudioEffectModulatedDelay::update(void) float mod_idx; float mod_number; float mod_fraction; -#ifdef CHORUS_INTERPOLATION_MODE - int8_t j; - uint8_t c; -#endif bp = block->data; mp = modulation->data; @@ -106,21 +101,7 @@ void AudioEffectModulatedDelay::update(void) // The index is located around the half of the delay length multiplied by the current amount of the modulator mod_idx = _delay_offset + ((float(*mp) / SHRT_MAX) * _modulation_intensity); mod_fraction = modff(mod_idx, &mod_number); - // Generate a an array with the size of CHORUS_INTERPOLATION_WINDOW_SIZE of x/y values around mod_idx for interpolation -#ifdef CHORUS_INTERPOLATION_MODE - // spline interpolation - c_mod_idx = _circ_idx - int(mod_idx); // This is the pointer to the value in the circular buffer at the current modulation index - for (j = (CHORUS_INTERPOLATION_WINDOW_SIZE / -2), c = 0; j <= (CHORUS_INTERPOLATION_WINDOW_SIZE / 2); j++, c++) - { - int16_t jc_mod_idx = (c_mod_idx + j) % _delay_length; // The modulation index pointer plus the value of the current window pointer - if (jc_mod_idx < 0) // check for negative offsets and correct them - y[c] = float(_delayline[_delay_length + jc_mod_idx]); - else - y[c] = float(_delayline[jc_mod_idx]); - x[c] = float(j); - } - *bp = int(round(spline->value(mod_fraction))); // use spline interpolated value -#else + // linear interpolation c_mod_idx = _circ_idx - round(mod_idx); if (mod_idx < 0.0) // c_mod_idx is the pointer to the value in the circular buffer at the current modulation index @@ -144,7 +125,7 @@ void AudioEffectModulatedDelay::update(void) idx[1] = c_mod_idx + 1; } *bp = round(float(_delayline[idx[0]]) * (1.0 - mod_fraction) + float(_delayline[idx[1]]) * mod_fraction); -#endif + bp++; // next audio data mp++; // next modulation data _circ_idx++; // next circular buffer index diff --git a/effect_modulated_delay.h b/effect_modulated_delay.h index bb60fa4..86bcc46 100644 --- a/effect_modulated_delay.h +++ b/effect_modulated_delay.h @@ -57,13 +57,7 @@ class AudioEffectModulatedDelay : uint16_t _modulation_intensity; uint16_t _delay_length; int16_t c_mod_idx; -#ifdef CHORUS_INTERPOLATION_MODE - float x[CHORUS_INTERPOLATION_WINDOW_SIZE]; - float y[CHORUS_INTERPOLATION_WINDOW_SIZE]; - Spline* spline; -#else uint16_t idx[2]; -#endif }; #endif diff --git a/spline.cpp b/spline.cpp deleted file mode 100644 index 913c647..0000000 --- a/spline.cpp +++ /dev/null @@ -1,111 +0,0 @@ -// From: https://raw.githubusercontent.com/kerinin/arduino-splines/master/spline.cpp -#include "Arduino.h" -#include "spline.h" -#include - -Spline::Spline(void) { - _prev_point = 0; -} - -Spline::Spline( float x[], float y[], int numPoints, int degree ) -{ - setPoints(x,y,numPoints); - setDegree(degree); - _prev_point = 0; -} - -Spline::Spline( float x[], float y[], float m[], int numPoints ) -{ - setPoints(x,y,m,numPoints); - setDegree(Hermite); - _prev_point = 0; -} - -void Spline::setPoints( float x[], float y[], int numPoints ) { - _x = x; - _y = y; - _length = numPoints; -} - -void Spline::setPoints( float x[], float y[], float m[], int numPoints ) { - _x = x; - _y = y; - _m = m; - _length = numPoints; -} - -void Spline::setDegree( int degree ){ - _degree = degree; -} - -float Spline::value( float x ) -{ - if( _x[0] > x ) { - return _y[0]; - } - else if ( _x[_length-1] < x ) { - return _y[_length-1]; - } - else { - for(int i = 0; i < _length; i++ ) - { - int index = ( i + _prev_point ) % _length; - - if( _x[index] == x ) { - _prev_point = index; - return _y[index]; - } else if( (_x[index] < x) && (x < _x[index+1]) ) { - _prev_point = index; - return calc( x, index ); - } - } - } -} - -float Spline::calc( float x, int i ) -{ - switch( _degree ) { - case 0: - return _y[i]; - case 1: - if( _x[i] == _x[i+1] ) { - // Avoids division by 0 - return _y[i]; - } else { - return _y[i] + (_y[i+1] - _y[i]) * ( x - _x[i]) / ( _x[i+1] - _x[i] ); - } - case Hermite: - return hermite( ((x-_x[i]) / (_x[i+1]-_x[i])), _y[i], _y[i+1], _m[i], _m[i+1], _x[i], _x[i+1] ); - case Catmull: - if( i == 0 ) { - // x prior to spline start - first point used to determine tangent - return _y[1]; - } else if( i == _length-2 ) { - // x after spline end - last point used to determine tangent - return _y[_length-2]; - } else { - float t = (x-_x[i]) / (_x[i+1]-_x[i]); - float m0 = (i==0 ? 0 : catmull_tangent(i) ); - float m1 = (i==_length-1 ? 0 : catmull_tangent(i+1) ); - return hermite( t, _y[i], _y[i+1], m0, m1, _x[i], _x[i+1]); - } - } -} - -float Spline::hermite( float t, float p0, float p1, float m0, float m1, float x0, float x1 ) { - return (hermite_00(t)*p0) + (hermite_10(t)*(x1-x0)*m0) + (hermite_01(t)*p1) + (hermite_11(t)*(x1-x0)*m1); -} -float Spline::hermite_00( float t ) { return (2*pow(t,3)) - (3*pow(t,2)) + 1;} -float Spline::hermite_10( float t ) { return pow(t,3) - (2*pow(t,2)) + t; } -float Spline::hermite_01( float t ) { return (3*pow(t,2)) - (2*pow(t,3)); } -float Spline::hermite_11( float t ) { return pow(t,3) - pow(t,2); } - -float Spline::catmull_tangent( int i ) -{ - if( _x[i+1] == _x[i-1] ) { - // Avoids division by 0 - return 0; - } else { - return (_y[i+1] - _y[i-1]) / (_x[i+1] - _x[i-1]); - } -} diff --git a/spline.h b/spline.h deleted file mode 100644 index 0382de9..0000000 --- a/spline.h +++ /dev/null @@ -1,43 +0,0 @@ -// From https://raw.githubusercontent.com/kerinin/arduino-splines/master/spline.h -/* - Library for 1-d splines - Copyright Ryan Michael - Licensed under the LGPLv3 -*/ -#ifndef spline_h -#define spline_h - -#include "Arduino.h" - -#define Hermite 10 -#define Catmull 11 - -class Spline -{ - public: - Spline( void ); - Spline( float x[], float y[], int numPoints, int degree = 1 ); - Spline( float x[], float y[], float m[], int numPoints ); - float value( float x ); - void setPoints( float x[], float y[], int numPoints ); - void setPoints( float x[], float y[], float m[], int numPoints ); - void setDegree( int degree ); - - private: - float calc( float, int); - float* _x; - float* _y; - float* _m; - int _degree; - int _length; - int _prev_point; - - float hermite( float t, float p0, float p1, float m0, float m1, float x0, float x1 ); - float hermite_00( float t ); - float hermite_10( float t ); - float hermite_01( float t ); - float hermite_11( float t ); - float catmull_tangent( int i ); -}; - -#endif