From 79120eb0b120fbd411637195d8250c6a47a324bb Mon Sep 17 00:00:00 2001 From: Vesa Date: Mon, 14 Apr 2014 12:45:07 +0300 Subject: [PATCH] Watsyn updates: use sinc instead of cubic for oversampling of the wavegraph --- plugins/watsyn/Watsyn.cpp | 8 ++++---- plugins/watsyn/Watsyn.h | 31 ++++++++++++++++++++++--------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/plugins/watsyn/Watsyn.cpp b/plugins/watsyn/Watsyn.cpp index ab1393aeb..9d7be21b2 100644 --- a/plugins/watsyn/Watsyn.cpp +++ b/plugins/watsyn/Watsyn.cpp @@ -612,10 +612,10 @@ void WatsynInstrument::updateFreq() void WatsynInstrument::updateWaves() { // do cip+oversampling on the wavetables to improve quality - cipcpy( &A1_wave[0], const_cast( a1_graph.samples() ) ); - cipcpy( &A2_wave[0], const_cast( a2_graph.samples() ) ); - cipcpy( &B1_wave[0], const_cast( b1_graph.samples() ) ); - cipcpy( &B2_wave[0], const_cast( b2_graph.samples() ) ); + srccpy( &A1_wave[0], const_cast( a1_graph.samples() ) ); + srccpy( &A2_wave[0], const_cast( a2_graph.samples() ) ); + srccpy( &B1_wave[0], const_cast( b1_graph.samples() ) ); + srccpy( &B2_wave[0], const_cast( b2_graph.samples() ) ); } diff --git a/plugins/watsyn/Watsyn.h b/plugins/watsyn/Watsyn.h index 37c607d0f..2590d287c 100644 --- a/plugins/watsyn/Watsyn.h +++ b/plugins/watsyn/Watsyn.h @@ -34,6 +34,7 @@ #include "TempoSyncKnob.h" #include "NotePlayHandle.h" #include "pixmap_button.h" +#include #define makeknob( name, x, y, hint, unit, oname ) \ @@ -102,12 +103,6 @@ public: } private: - // linear interpolation -/* inline sample_t interpolate( sample_t s1, sample_t s2, float x ) - { - return s1 + ( s2 - s1 ) * x; - }*/ // we use the one in interpolation.h now - int m_amod; int m_bmod; @@ -178,8 +173,25 @@ private: return ( _pan >= 0 ? 1.0 : 1.0 + ( _pan / 100.0 ) ) * _vol / 100.0; } - // memcpy with cubic interpolation (cip for short) and 10x oversampling to increase wavetable quality - inline void cipcpy( float * _dst, float * _src ) + // memcpy utilizing libsamplerate (src) for sinc interpolation + inline void srccpy( float * _dst, float * _src ) + { + int err; + SRC_STATE * src_state = src_new( SRC_SINC_MEDIUM_QUALITY, 1, &err ); + SRC_DATA src_data; + src_data.data_in = _src; + src_data.input_frames = GRAPHLEN; + src_data.data_out = _dst; + src_data.output_frames = WAVELEN; + src_data.src_ratio = static_cast( WAVERATIO ); + src_data.end_of_input = 1; + err = src_process( src_state, &src_data ); + if( err ) { qDebug( "Watsyn SRC error: %s", src_strerror( err ) ); } + src_delete( src_state ); + } + + // memcpy utilizing cubic interpolation +/* inline void cipcpy( float * _dst, float * _src ) { // calculate cyclic tangents float tang[GRAPHLEN]; @@ -207,7 +219,8 @@ private: ( ( x3 - x2 * 2 + x ) * m1 ) + ( ( x3 - x2 ) * m2 ); } - } + }*/ + FloatModel a1_vol; FloatModel a2_vol;