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:
Wed Feb 01 15:00:31 2017 +0000
Revision:
18:b9b1116f8768
Parent:
16:d4ea3e6a0bce
Child:
19:f5e785fe50b1
Update ciomment

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 18:b9b1116f8768 9
shorie 18:b9b1116f8768 10 // Variable Frequency Oscillator. Only square and triangle
shorie 14:cec63d8da48c 11 class VFO {
shorie 14:cec63d8da48c 12 public:
shorie 14:cec63d8da48c 13 VFO( void );
shorie 18:b9b1116f8768 14 virtual ~VFO(void);
shorie 14:cec63d8da48c 15 void run(
shorie 18:b9b1116f8768 16 float out_buffer[], // place to write the right output samples
shorie 14:cec63d8da48c 17 unsigned int block_size // block size [sample]
shorie 14:cec63d8da48c 18 );
shorie 14:cec63d8da48c 19
shorie 14:cec63d8da48c 20 // parameter settings
shorie 18:b9b1116f8768 21 void set_frequency( int freq ); // unit is Hz.
shorie 18:b9b1116f8768 22 void set_Fs( int Fs ); // unit is Hz.
shorie 14:cec63d8da48c 23 void set_duty_cycle( float duty ); // 0 ... 0.5
shorie 18:b9b1116f8768 24 void set_wave_form( wave_form form );
shorie 14:cec63d8da48c 25 private:
shorie 14:cec63d8da48c 26
shorie 16:d4ea3e6a0bce 27 // control variables.
shorie 14:cec63d8da48c 28 int frequency; // VFO frequency [Hz]
shorie 14:cec63d8da48c 29 int Fs; // sampling Frequency [Hz]
shorie 14:cec63d8da48c 30 float duty_cycle; // VFO duty cycle. 0 ... 0.5
shorie 18:b9b1116f8768 31 wave_form form; // form of the wave form.
shorie 15:de22b9d147e0 32 int current_phase; // internal variable of VFO.
shorie 15:de22b9d147e0 33
shorie 16:d4ea3e6a0bce 34 // internal variable.
shorie 16:d4ea3e6a0bce 35 int half_way; // change point by duty cycle. ( period * duty_cycle ).
shorie 16:d4ea3e6a0bce 36 float rising_rate;
shorie 16:d4ea3e6a0bce 37 float falling_rate;
shorie 16:d4ea3e6a0bce 38
shorie 16:d4ea3e6a0bce 39 void update_parameters(void); // call one of the parameter is changed.
shorie 14:cec63d8da48c 40 };
shorie 14:cec63d8da48c 41
shorie 18:b9b1116f8768 42 // Monophonic synthsizer class
shorie 18:b9b1116f8768 43 class Monophonic {
shorie 18:b9b1116f8768 44 public:
shorie 18:b9b1116f8768 45 Monophonic( unsigned int block_size );
shorie 18:b9b1116f8768 46 virtual ~Monophonic(void);
shorie 18:b9b1116f8768 47 void run(
shorie 18:b9b1116f8768 48 float out_buffer[], // place to write the right output samples
shorie 18:b9b1116f8768 49 unsigned int block_size // block size [sample]
shorie 18:b9b1116f8768 50 );
shorie 18:b9b1116f8768 51 void set_Fs( int Fs ); // unit is Hz.
shorie 18:b9b1116f8768 52 void set_vfo_frequency( int freq ); // unit is Hz.
shorie 18:b9b1116f8768 53 void set_vfo_duty_cycle( float duty ); // 0 ... 0.5
shorie 18:b9b1116f8768 54 void set_vfo_wave_form( wave_form form );
shorie 18:b9b1116f8768 55 private:
shorie 18:b9b1116f8768 56 VFO *vfo;
shorie 18:b9b1116f8768 57 };
shorie 18:b9b1116f8768 58
shorie 14:cec63d8da48c 59
shorie 6:486b1cb03e61 60 // User Signal processing Class
shorie 6:486b1cb03e61 61 class SignalProcessing {
shorie 6:486b1cb03e61 62 public:
shorie 6:486b1cb03e61 63 // essential members. Do not touch
shorie 6:486b1cb03e61 64 SignalProcessing( unsigned int block_size );
shorie 6:486b1cb03e61 65 void run(
shorie 6:486b1cb03e61 66 float rx_left_buffer[], // array of the left input samples
shorie 6:486b1cb03e61 67 float rx_right_buffer[], // array of the right input samples
shorie 6:486b1cb03e61 68 float tx_left_buffer[], // place to write the left output samples
shorie 13:b33cb5925113 69 float tx_right_buffer[], // place to write the right output samples
shorie 6:486b1cb03e61 70 unsigned int block_size // block size [sample]
shorie 6:486b1cb03e61 71 );
shorie 6:486b1cb03e61 72
shorie 6:486b1cb03e61 73 // project depenedent members.
shorie 6:486b1cb03e61 74 void set_volume( float vol );
shorie 14:cec63d8da48c 75 void set_Fs( int Fs ); // unit is Hz.
shorie 15:de22b9d147e0 76 void set_vfo_frequency( int freq ); // unit is Hz.
shorie 15:de22b9d147e0 77 void set_vfo_duty_cycle( float duty ); // 0 ... 0.5
shorie 18:b9b1116f8768 78 void set_vfo_wave_form( wave_form form );
shorie 6:486b1cb03e61 79 private:
shorie 6:486b1cb03e61 80 // essential members. Do not touch.
shorie 6:486b1cb03e61 81 void enter_critical_section(void);
shorie 6:486b1cb03e61 82 void leave_critical_section(void);
shorie 6:486b1cb03e61 83
shorie 6:486b1cb03e61 84 // project dependent members.
shorie 14:cec63d8da48c 85 float volume_level; // 0 ... 1.0
shorie 18:b9b1116f8768 86 Monophonic * note;
shorie 6:486b1cb03e61 87 };
shorie 6:486b1cb03e61 88
shorie 6:486b1cb03e61 89 #endif