Experimental implementation of the adaptive filter of "Interface" magazine in 2016-2017
Dependencies: amakusa mbed-dsp mbed shimabara ukifune unzen_nucleo_f746
Fork of skeleton_unzen_nucleo_f746 by
ハードウェアおよびソフトウェアはskelton_unzen_nucleo_f746を基本にしています。
signal_processing.h@19:f5e785fe50b1, 2017-02-03 (annotated)
- Committer:
- shorie
- Date:
- Fri Feb 03 14:35:46 2017 +0000
- Revision:
- 19:f5e785fe50b1
- Parent:
- 18:b9b1116f8768
- Child:
- 20:699e209fd19a
Total structure is refactored to use the Monophonic.
Who changed what in which revision?
User | Revision | Line number | New 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 | |
shorie | 16:d4ea3e6a0bce | 33 | // internal variable. |
shorie | 19:f5e785fe50b1 | 34 | int current_phase; // internal variable of VFO. |
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 | 19:f5e785fe50b1 | 42 | // Blocking DC |
shorie | 19:f5e785fe50b1 | 43 | class DCBlocker : public amakusa::AbstractFilter { |
shorie | 19:f5e785fe50b1 | 44 | public: |
shorie | 19:f5e785fe50b1 | 45 | DCBlocker( uint32_t blockSize ); |
shorie | 19:f5e785fe50b1 | 46 | virtual void run( float32_t *pSrc, float32_t *pDst, uint32_t blockSize = 0 ); |
shorie | 19:f5e785fe50b1 | 47 | private: |
shorie | 19:f5e785fe50b1 | 48 | float x_last; |
shorie | 19:f5e785fe50b1 | 49 | float y_last; |
shorie | 19:f5e785fe50b1 | 50 | }; |
shorie | 19:f5e785fe50b1 | 51 | |
shorie | 18:b9b1116f8768 | 52 | // Monophonic synthsizer class |
shorie | 18:b9b1116f8768 | 53 | class Monophonic { |
shorie | 18:b9b1116f8768 | 54 | public: |
shorie | 18:b9b1116f8768 | 55 | Monophonic( unsigned int block_size ); |
shorie | 18:b9b1116f8768 | 56 | virtual ~Monophonic(void); |
shorie | 18:b9b1116f8768 | 57 | void run( |
shorie | 18:b9b1116f8768 | 58 | float out_buffer[], // place to write the right output samples |
shorie | 18:b9b1116f8768 | 59 | unsigned int block_size // block size [sample] |
shorie | 18:b9b1116f8768 | 60 | ); |
shorie | 18:b9b1116f8768 | 61 | void set_Fs( int Fs ); // unit is Hz. |
shorie | 18:b9b1116f8768 | 62 | void set_vfo_frequency( int freq ); // unit is Hz. |
shorie | 18:b9b1116f8768 | 63 | void set_vfo_duty_cycle( float duty ); // 0 ... 0.5 |
shorie | 18:b9b1116f8768 | 64 | void set_vfo_wave_form( wave_form form ); |
shorie | 18:b9b1116f8768 | 65 | private: |
shorie | 18:b9b1116f8768 | 66 | VFO *vfo; |
shorie | 18:b9b1116f8768 | 67 | }; |
shorie | 18:b9b1116f8768 | 68 | |
shorie | 14:cec63d8da48c | 69 | |
shorie | 6:486b1cb03e61 | 70 | // User Signal processing Class |
shorie | 6:486b1cb03e61 | 71 | class SignalProcessing { |
shorie | 6:486b1cb03e61 | 72 | public: |
shorie | 6:486b1cb03e61 | 73 | // essential members. Do not touch |
shorie | 6:486b1cb03e61 | 74 | SignalProcessing( unsigned int block_size ); |
shorie | 6:486b1cb03e61 | 75 | void run( |
shorie | 6:486b1cb03e61 | 76 | float rx_left_buffer[], // array of the left input samples |
shorie | 6:486b1cb03e61 | 77 | float rx_right_buffer[], // array of the right input samples |
shorie | 6:486b1cb03e61 | 78 | float tx_left_buffer[], // place to write the left output samples |
shorie | 13:b33cb5925113 | 79 | float tx_right_buffer[], // place to write the right output samples |
shorie | 6:486b1cb03e61 | 80 | unsigned int block_size // block size [sample] |
shorie | 6:486b1cb03e61 | 81 | ); |
shorie | 6:486b1cb03e61 | 82 | |
shorie | 6:486b1cb03e61 | 83 | // project depenedent members. |
shorie | 6:486b1cb03e61 | 84 | void set_volume( float vol ); |
shorie | 14:cec63d8da48c | 85 | void set_Fs( int Fs ); // unit is Hz. |
shorie | 15:de22b9d147e0 | 86 | void set_vfo_frequency( int freq ); // unit is Hz. |
shorie | 15:de22b9d147e0 | 87 | void set_vfo_duty_cycle( float duty ); // 0 ... 0.5 |
shorie | 18:b9b1116f8768 | 88 | void set_vfo_wave_form( wave_form form ); |
shorie | 6:486b1cb03e61 | 89 | private: |
shorie | 6:486b1cb03e61 | 90 | // essential members. Do not touch. |
shorie | 6:486b1cb03e61 | 91 | void enter_critical_section(void); |
shorie | 6:486b1cb03e61 | 92 | void leave_critical_section(void); |
shorie | 6:486b1cb03e61 | 93 | |
shorie | 6:486b1cb03e61 | 94 | // project dependent members. |
shorie | 14:cec63d8da48c | 95 | float volume_level; // 0 ... 1.0 |
shorie | 18:b9b1116f8768 | 96 | Monophonic * note; |
shorie | 6:486b1cb03e61 | 97 | }; |
shorie | 6:486b1cb03e61 | 98 | |
shorie | 6:486b1cb03e61 | 99 | #endif |