Synthesizer based on the Unzen / Nucleo F746ZG

Dependencies:   amakusa mbed-dsp mbed shimabara ukifune unzen_nucleo_f746

Fork of skeleton_unzen_nucleo_f746 by seiichi horie

雲仙フレームワークのテストとして作っているプロジェクトです。中身はどんどん変っていきます。 説明はDSP空挺団の「シンセサイザー」カテゴリーを参照してください。初回は「ドッグフードを食べる」です。

Revision:
20:53021b2c424d
Parent:
19:f5e785fe50b1
Child:
22:dc2cbe8db9d9
--- a/signal_processing.h	Fri Feb 03 14:35:46 2017 +0000
+++ b/signal_processing.h	Sat Feb 04 15:03:41 2017 +0000
@@ -6,6 +6,7 @@
 #define SAMPLING_FREQUENCY 48000
 
 enum wave_form { triangle, square };
+enum svf_mode { lpf, hpf, bpf };
 
     // Variable Frequency Oscillator. Only square and triangle
 class VFO {
@@ -14,7 +15,7 @@
     virtual ~VFO(void);
     void run(           
         float out_buffer[],         // place to write the right output samples
-        unsigned int block_size     // block size [sample]
+        unsigned int block_size =0    // block size [sample]
         );
            
         // parameter settings
@@ -49,6 +50,27 @@
     float y_last;
 };
 
+    // State Variable Filter
+    // The f * f_factor must be < Fs/6.
+class SVFilter : public amakusa::AbstractFilter {
+public:
+    SVFilter( uint32_t blockSize );
+    virtual void run( float32_t *pSrc, float32_t *pDst, uint32_t blockSize = 0 );
+    void set_Q( float32_t Q );              // real Q factor [ 0.5 ... inf ]
+    void set_Fs( int new_Fs );              // Hz
+    void set_fc( int new_fc );                // Hz
+    void set_f_factor( float32_t new_f_factor );   
+    void set_mode( svf_mode new_mode );
+private:    
+        // internal variable
+    float32_t d1, d2;                       // delay 1, delay 2;
+    float32_t q, f;                         // q = 1/Q, f = 2 * sin( fc*f_factor*pi/Fs );
+        // parameter set by method
+    int Fs, fc, f_factor;                   // sampling frequency and control frequency
+    svf_mode mode;                          // lpf, hpf, bpf
+    void update_parameters( void );
+};
+
     // Monophonic synthsizer class
 class Monophonic {
 public:
@@ -56,7 +78,7 @@
     virtual ~Monophonic(void);
     void run(           
         float out_buffer[],         // place to write the right output samples
-        unsigned int block_size     // block size [sample]
+        unsigned int block_size = 0    // block size [sample]
         );
     void set_Fs( int Fs );                  // unit is Hz.
     void set_vfo_frequency( int freq );     // unit is Hz.
@@ -64,6 +86,9 @@
     void set_vfo_wave_form( wave_form form );
 private:
     VFO *vfo;
+    DCBlocker *dc_blocker;
+    SVFilter *sv_filter;
+    float32_t *work_buf_a, *work_buf_b;
 };