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空挺団の「シンセサイザー」カテゴリーを参照してください。初回は「ドッグフードを食べる」です。

Committer:
shorie
Date:
Sat Feb 04 15:03:41 2017 +0000
Revision:
20:53021b2c424d
Parent:
19:f5e785fe50b1
Child:
22:dc2cbe8db9d9
Added SV Filter

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shorie 6:486b1cb03e61 1 #ifndef _SIGNAL_PROCESSING_H_
shorie 6:486b1cb03e61 2 #define _SIGNAL_PROCESSING_H_
shorie 6:486b1cb03e61 3
shorie 6:486b1cb03e61 4 #include "amakusa.h"
shorie 6:486b1cb03e61 5
shorie 18:b9b1116f8768 6 #define SAMPLING_FREQUENCY 48000
shorie 14:cec63d8da48c 7
shorie 18:b9b1116f8768 8 enum wave_form { triangle, square };
shorie 20:53021b2c424d 9 enum svf_mode { lpf, hpf, bpf };
shorie 18:b9b1116f8768 10
shorie 18:b9b1116f8768 11 // Variable Frequency Oscillator. Only square and triangle
shorie 14:cec63d8da48c 12 class VFO {
shorie 14:cec63d8da48c 13 public:
shorie 14:cec63d8da48c 14 VFO( void );
shorie 18:b9b1116f8768 15 virtual ~VFO(void);
shorie 14:cec63d8da48c 16 void run(
shorie 18:b9b1116f8768 17 float out_buffer[], // place to write the right output samples
shorie 20:53021b2c424d 18 unsigned int block_size =0 // block size [sample]
shorie 14:cec63d8da48c 19 );
shorie 14:cec63d8da48c 20
shorie 14:cec63d8da48c 21 // parameter settings
shorie 18:b9b1116f8768 22 void set_frequency( int freq ); // unit is Hz.
shorie 18:b9b1116f8768 23 void set_Fs( int Fs ); // unit is Hz.
shorie 14:cec63d8da48c 24 void set_duty_cycle( float duty ); // 0 ... 0.5
shorie 18:b9b1116f8768 25 void set_wave_form( wave_form form );
shorie 14:cec63d8da48c 26 private:
shorie 14:cec63d8da48c 27
shorie 16:d4ea3e6a0bce 28 // control variables.
shorie 14:cec63d8da48c 29 int frequency; // VFO frequency [Hz]
shorie 14:cec63d8da48c 30 int Fs; // sampling Frequency [Hz]
shorie 14:cec63d8da48c 31 float duty_cycle; // VFO duty cycle. 0 ... 0.5
shorie 18:b9b1116f8768 32 wave_form form; // form of the wave form.
shorie 15:de22b9d147e0 33
shorie 16:d4ea3e6a0bce 34 // internal variable.
shorie 19:f5e785fe50b1 35 int current_phase; // internal variable of VFO.
shorie 16:d4ea3e6a0bce 36 int half_way; // change point by duty cycle. ( period * duty_cycle ).
shorie 16:d4ea3e6a0bce 37 float rising_rate;
shorie 16:d4ea3e6a0bce 38 float falling_rate;
shorie 16:d4ea3e6a0bce 39
shorie 16:d4ea3e6a0bce 40 void update_parameters(void); // call one of the parameter is changed.
shorie 14:cec63d8da48c 41 };
shorie 14:cec63d8da48c 42
shorie 19:f5e785fe50b1 43 // Blocking DC
shorie 19:f5e785fe50b1 44 class DCBlocker : public amakusa::AbstractFilter {
shorie 19:f5e785fe50b1 45 public:
shorie 19:f5e785fe50b1 46 DCBlocker( uint32_t blockSize );
shorie 19:f5e785fe50b1 47 virtual void run( float32_t *pSrc, float32_t *pDst, uint32_t blockSize = 0 );
shorie 19:f5e785fe50b1 48 private:
shorie 19:f5e785fe50b1 49 float x_last;
shorie 19:f5e785fe50b1 50 float y_last;
shorie 19:f5e785fe50b1 51 };
shorie 19:f5e785fe50b1 52
shorie 20:53021b2c424d 53 // State Variable Filter
shorie 20:53021b2c424d 54 // The f * f_factor must be < Fs/6.
shorie 20:53021b2c424d 55 class SVFilter : public amakusa::AbstractFilter {
shorie 20:53021b2c424d 56 public:
shorie 20:53021b2c424d 57 SVFilter( uint32_t blockSize );
shorie 20:53021b2c424d 58 virtual void run( float32_t *pSrc, float32_t *pDst, uint32_t blockSize = 0 );
shorie 20:53021b2c424d 59 void set_Q( float32_t Q ); // real Q factor [ 0.5 ... inf ]
shorie 20:53021b2c424d 60 void set_Fs( int new_Fs ); // Hz
shorie 20:53021b2c424d 61 void set_fc( int new_fc ); // Hz
shorie 20:53021b2c424d 62 void set_f_factor( float32_t new_f_factor );
shorie 20:53021b2c424d 63 void set_mode( svf_mode new_mode );
shorie 20:53021b2c424d 64 private:
shorie 20:53021b2c424d 65 // internal variable
shorie 20:53021b2c424d 66 float32_t d1, d2; // delay 1, delay 2;
shorie 20:53021b2c424d 67 float32_t q, f; // q = 1/Q, f = 2 * sin( fc*f_factor*pi/Fs );
shorie 20:53021b2c424d 68 // parameter set by method
shorie 20:53021b2c424d 69 int Fs, fc, f_factor; // sampling frequency and control frequency
shorie 20:53021b2c424d 70 svf_mode mode; // lpf, hpf, bpf
shorie 20:53021b2c424d 71 void update_parameters( void );
shorie 20:53021b2c424d 72 };
shorie 20:53021b2c424d 73
shorie 18:b9b1116f8768 74 // Monophonic synthsizer class
shorie 18:b9b1116f8768 75 class Monophonic {
shorie 18:b9b1116f8768 76 public:
shorie 18:b9b1116f8768 77 Monophonic( unsigned int block_size );
shorie 18:b9b1116f8768 78 virtual ~Monophonic(void);
shorie 18:b9b1116f8768 79 void run(
shorie 18:b9b1116f8768 80 float out_buffer[], // place to write the right output samples
shorie 20:53021b2c424d 81 unsigned int block_size = 0 // block size [sample]
shorie 18:b9b1116f8768 82 );
shorie 18:b9b1116f8768 83 void set_Fs( int Fs ); // unit is Hz.
shorie 18:b9b1116f8768 84 void set_vfo_frequency( int freq ); // unit is Hz.
shorie 18:b9b1116f8768 85 void set_vfo_duty_cycle( float duty ); // 0 ... 0.5
shorie 18:b9b1116f8768 86 void set_vfo_wave_form( wave_form form );
shorie 18:b9b1116f8768 87 private:
shorie 18:b9b1116f8768 88 VFO *vfo;
shorie 20:53021b2c424d 89 DCBlocker *dc_blocker;
shorie 20:53021b2c424d 90 SVFilter *sv_filter;
shorie 20:53021b2c424d 91 float32_t *work_buf_a, *work_buf_b;
shorie 18:b9b1116f8768 92 };
shorie 18:b9b1116f8768 93
shorie 14:cec63d8da48c 94
shorie 6:486b1cb03e61 95 // User Signal processing Class
shorie 6:486b1cb03e61 96 class SignalProcessing {
shorie 6:486b1cb03e61 97 public:
shorie 6:486b1cb03e61 98 // essential members. Do not touch
shorie 6:486b1cb03e61 99 SignalProcessing( unsigned int block_size );
shorie 6:486b1cb03e61 100 void run(
shorie 6:486b1cb03e61 101 float rx_left_buffer[], // array of the left input samples
shorie 6:486b1cb03e61 102 float rx_right_buffer[], // array of the right input samples
shorie 6:486b1cb03e61 103 float tx_left_buffer[], // place to write the left output samples
shorie 13:b33cb5925113 104 float tx_right_buffer[], // place to write the right output samples
shorie 6:486b1cb03e61 105 unsigned int block_size // block size [sample]
shorie 6:486b1cb03e61 106 );
shorie 6:486b1cb03e61 107
shorie 6:486b1cb03e61 108 // project depenedent members.
shorie 6:486b1cb03e61 109 void set_volume( float vol );
shorie 14:cec63d8da48c 110 void set_Fs( int Fs ); // unit is Hz.
shorie 15:de22b9d147e0 111 void set_vfo_frequency( int freq ); // unit is Hz.
shorie 15:de22b9d147e0 112 void set_vfo_duty_cycle( float duty ); // 0 ... 0.5
shorie 18:b9b1116f8768 113 void set_vfo_wave_form( wave_form form );
shorie 6:486b1cb03e61 114 private:
shorie 6:486b1cb03e61 115 // essential members. Do not touch.
shorie 6:486b1cb03e61 116 void enter_critical_section(void);
shorie 6:486b1cb03e61 117 void leave_critical_section(void);
shorie 6:486b1cb03e61 118
shorie 6:486b1cb03e61 119 // project dependent members.
shorie 14:cec63d8da48c 120 float volume_level; // 0 ... 1.0
shorie 18:b9b1116f8768 121 Monophonic * note;
shorie 6:486b1cb03e61 122 };
shorie 6:486b1cb03e61 123
shorie 6:486b1cb03e61 124 #endif