Synthesizer based on the Unzen / Nucleo F746ZG
Dependencies: amakusa mbed-dsp mbed shimabara ukifune unzen_nucleo_f746
Fork of skeleton_unzen_nucleo_f746 by
雲仙フレームワークのテストとして作っているプロジェクトです。中身はどんどん変っていきます。 説明はDSP空挺団の「シンセサイザー」カテゴリーを参照してください。初回は「ドッグフードを食べる」です。
signal_processing.cpp@29:8ee84bda128c, 2017-02-18 (annotated)
- Committer:
- shorie
- Date:
- Sat Feb 18 04:37:19 2017 +0000
- Revision:
- 29:8ee84bda128c
- Parent:
- 28:547f19ed6f67
Limiter function is confirmed. SV filter ignored bug was fixed.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shorie | 6:486b1cb03e61 | 1 | #include "signal_processing.h" |
shorie | 6:486b1cb03e61 | 2 | |
shorie | 10:a00c73efc6c3 | 3 | /*========================= Project Dependent Method =========================*/ |
shorie | 10:a00c73efc6c3 | 4 | // Modify this constructor to initialize your audio algorithm. |
shorie | 6:486b1cb03e61 | 5 | SignalProcessing::SignalProcessing( unsigned int block_size ) |
shorie | 6:486b1cb03e61 | 6 | { |
shorie | 6:486b1cb03e61 | 7 | // place the signal processing initializing code here. |
shorie | 6:486b1cb03e61 | 8 | this->volume_level = 0.0; // sample initializaiton |
shorie | 18:b9b1116f8768 | 9 | this->note = new Monophonic(block_size); // allocate VFO |
shorie | 18:b9b1116f8768 | 10 | note->set_Fs( SAMPLING_FREQUENCY ); |
shorie | 18:b9b1116f8768 | 11 | note->set_vfo_frequency( 440 ); |
shorie | 18:b9b1116f8768 | 12 | note->set_vfo_wave_form( triangle ); |
shorie | 10:a00c73efc6c3 | 13 | } // End of constructor() |
shorie | 6:486b1cb03e61 | 14 | |
shorie | 10:a00c73efc6c3 | 15 | |
shorie | 10:a00c73efc6c3 | 16 | // Modify this method to implement your audio algorithm. |
shorie | 6:486b1cb03e61 | 17 | void SignalProcessing::run( |
shorie | 6:486b1cb03e61 | 18 | float rx_left_buffer[], // array of the left input samples |
shorie | 6:486b1cb03e61 | 19 | float rx_right_buffer[], // array of the right input samples |
shorie | 6:486b1cb03e61 | 20 | float tx_left_buffer[], // place to write the left output samples |
shorie | 13:b33cb5925113 | 21 | float tx_right_buffer[], // place to write the right output samples |
shorie | 6:486b1cb03e61 | 22 | unsigned int block_size // block size [sample] |
shorie | 6:486b1cb03e61 | 23 | ) |
shorie | 6:486b1cb03e61 | 24 | { |
shorie | 6:486b1cb03e61 | 25 | // place the signal processing coce here |
shorie | 14:cec63d8da48c | 26 | |
shorie | 14:cec63d8da48c | 27 | // VFO |
shorie | 26:e99f71165e19 | 28 | this->note->run( tx_left_buffer); |
shorie | 14:cec63d8da48c | 29 | |
shorie | 14:cec63d8da48c | 30 | // apply gain and copy to right ch. |
shorie | 6:486b1cb03e61 | 31 | for ( int i= 0; i< block_size; i++ ) |
shorie | 6:486b1cb03e61 | 32 | { |
shorie | 14:cec63d8da48c | 33 | tx_right_buffer[i] = tx_left_buffer[i] *= this->volume_level; |
shorie | 6:486b1cb03e61 | 34 | } |
shorie | 10:a00c73efc6c3 | 35 | } // End of run() |
shorie | 10:a00c73efc6c3 | 36 | |
shorie | 14:cec63d8da48c | 37 | |
shorie | 15:de22b9d147e0 | 38 | // Sampling Frequency |
shorie | 14:cec63d8da48c | 39 | void SignalProcessing::set_Fs( int Fs ) |
shorie | 14:cec63d8da48c | 40 | { |
shorie | 15:de22b9d147e0 | 41 | this->enter_critical_section(); // forbidden interrrupt. |
shorie | 18:b9b1116f8768 | 42 | this->note->set_Fs( Fs ); |
shorie | 15:de22b9d147e0 | 43 | this->leave_critical_section(); // now, ok to accept interrupt. |
shorie | 14:cec63d8da48c | 44 | } |
shorie | 14:cec63d8da48c | 45 | |
shorie | 15:de22b9d147e0 | 46 | // Oscillation Frequency |
shorie | 28:547f19ed6f67 | 47 | void SignalProcessing::set_vfo_frequency( float freq ) |
shorie | 14:cec63d8da48c | 48 | { |
shorie | 15:de22b9d147e0 | 49 | this->enter_critical_section(); // forbidden interrrupt. |
shorie | 18:b9b1116f8768 | 50 | this->note->set_vfo_frequency( freq ); |
shorie | 15:de22b9d147e0 | 51 | this->leave_critical_section(); // now, ok to accept interrupt. |
shorie | 14:cec63d8da48c | 52 | } |
shorie | 14:cec63d8da48c | 53 | |
shorie | 15:de22b9d147e0 | 54 | // Duty Cycle of VFO |
shorie | 15:de22b9d147e0 | 55 | void SignalProcessing::set_vfo_duty_cycle( float duty ) |
shorie | 14:cec63d8da48c | 56 | { |
shorie | 22:dc2cbe8db9d9 | 57 | duty *= 0.5f; // [0.0,0.5] |
shorie | 15:de22b9d147e0 | 58 | this->enter_critical_section(); // forbidden interrrupt. |
shorie | 18:b9b1116f8768 | 59 | this->note->set_vfo_duty_cycle( duty ); |
shorie | 15:de22b9d147e0 | 60 | this->leave_critical_section(); // now, ok to accept interrupt. |
shorie | 14:cec63d8da48c | 61 | } |
shorie | 14:cec63d8da48c | 62 | |
shorie | 18:b9b1116f8768 | 63 | // VFO wave form |
shorie | 18:b9b1116f8768 | 64 | void SignalProcessing::set_vfo_wave_form( wave_form form ) |
shorie | 14:cec63d8da48c | 65 | { |
shorie | 15:de22b9d147e0 | 66 | this->enter_critical_section(); // forbidden interrrupt. |
shorie | 18:b9b1116f8768 | 67 | this->note->set_vfo_wave_form( form ); |
shorie | 15:de22b9d147e0 | 68 | this->leave_critical_section(); // now, ok to accept interrupt. |
shorie | 14:cec63d8da48c | 69 | } |
shorie | 14:cec63d8da48c | 70 | |
shorie | 6:486b1cb03e61 | 71 | |
shorie | 15:de22b9d147e0 | 72 | // Set the volume level to the object. |
shorie | 6:486b1cb03e61 | 73 | void SignalProcessing::set_volume( float vol ) |
shorie | 6:486b1cb03e61 | 74 | { |
shorie | 6:486b1cb03e61 | 75 | this->enter_critical_section(); // forbidden interrrupt. |
shorie | 6:486b1cb03e61 | 76 | this->volume_level = vol; |
shorie | 6:486b1cb03e61 | 77 | this->leave_critical_section(); // now, ok to accept interrupt. |
shorie | 6:486b1cb03e61 | 78 | } |
shorie | 6:486b1cb03e61 | 79 | |
shorie | 22:dc2cbe8db9d9 | 80 | // Set the lpf/hpf/bpf |
shorie | 22:dc2cbe8db9d9 | 81 | void SignalProcessing::set_filter_mode( svf_mode mode ) |
shorie | 22:dc2cbe8db9d9 | 82 | { |
shorie | 22:dc2cbe8db9d9 | 83 | this->enter_critical_section(); // forbidden interrrupt. |
shorie | 22:dc2cbe8db9d9 | 84 | this->note->set_filter_mode( mode ); |
shorie | 22:dc2cbe8db9d9 | 85 | this->leave_critical_section(); // now, ok to accept interrupt. |
shorie | 22:dc2cbe8db9d9 | 86 | } |
shorie | 6:486b1cb03e61 | 87 | |
shorie | 22:dc2cbe8db9d9 | 88 | // Set the Q value. |
shorie | 22:dc2cbe8db9d9 | 89 | void SignalProcessing::set_filter_Q( float Q ) |
shorie | 22:dc2cbe8db9d9 | 90 | { |
shorie | 22:dc2cbe8db9d9 | 91 | // range of the parameter Q ( volume input ) is [0,1.0]. |
shorie | 22:dc2cbe8db9d9 | 92 | // Transform it to [0.1,10] |
shorie | 22:dc2cbe8db9d9 | 93 | Q *= 9.9f; |
shorie | 22:dc2cbe8db9d9 | 94 | Q += 0.1f; |
shorie | 22:dc2cbe8db9d9 | 95 | |
shorie | 22:dc2cbe8db9d9 | 96 | this->enter_critical_section(); // forbidden interrrupt. |
shorie | 22:dc2cbe8db9d9 | 97 | this->note->set_filter_Q( Q ); |
shorie | 22:dc2cbe8db9d9 | 98 | this->leave_critical_section(); // now, ok to accept interrupt. |
shorie | 22:dc2cbe8db9d9 | 99 | } |
shorie | 22:dc2cbe8db9d9 | 100 | |
shorie | 22:dc2cbe8db9d9 | 101 | // Set the f_factor value. |
shorie | 22:dc2cbe8db9d9 | 102 | void SignalProcessing::set_filter_f_factor( float f_factor ) |
shorie | 22:dc2cbe8db9d9 | 103 | { |
shorie | 22:dc2cbe8db9d9 | 104 | // range of the parameter f_factor ( volume input ) is [0,1.0]. |
shorie | 22:dc2cbe8db9d9 | 105 | // Transform it to [0.1,5.0] |
shorie | 22:dc2cbe8db9d9 | 106 | f_factor *= 4.9f; |
shorie | 22:dc2cbe8db9d9 | 107 | f_factor += 0.1f; |
shorie | 22:dc2cbe8db9d9 | 108 | |
shorie | 22:dc2cbe8db9d9 | 109 | this->enter_critical_section(); // forbidden interrrupt. |
shorie | 22:dc2cbe8db9d9 | 110 | this->note->set_filter_f_factor( f_factor ); |
shorie | 22:dc2cbe8db9d9 | 111 | this->leave_critical_section(); // now, ok to accept interrupt. |
shorie | 22:dc2cbe8db9d9 | 112 | } |
shorie | 6:486b1cb03e61 | 113 | |
shorie | 26:e99f71165e19 | 114 | void SignalProcessing::eg_on(void) |
shorie | 26:e99f71165e19 | 115 | { |
shorie | 26:e99f71165e19 | 116 | this->enter_critical_section(); // forbidden interrrupt. |
shorie | 26:e99f71165e19 | 117 | this->note->eg_on(); |
shorie | 26:e99f71165e19 | 118 | this->leave_critical_section(); // now, ok to accept interrupt. |
shorie | 26:e99f71165e19 | 119 | } |
shorie | 26:e99f71165e19 | 120 | |
shorie | 26:e99f71165e19 | 121 | void SignalProcessing::eg_off(void) |
shorie | 26:e99f71165e19 | 122 | { |
shorie | 26:e99f71165e19 | 123 | this->enter_critical_section(); // forbidden interrrupt. |
shorie | 26:e99f71165e19 | 124 | this->note->eg_off(); |
shorie | 26:e99f71165e19 | 125 | this->leave_critical_section(); // now, ok to accept interrupt. |
shorie | 26:e99f71165e19 | 126 | } |
shorie | 26:e99f71165e19 | 127 | |
shorie | 26:e99f71165e19 | 128 | void SignalProcessing::set_eg_attack( float32_t attack ) |
shorie | 26:e99f71165e19 | 129 | { |
shorie | 26:e99f71165e19 | 130 | this->enter_critical_section(); // forbidden interrrupt. |
shorie | 26:e99f71165e19 | 131 | this->note->set_eg_attack( attack ); |
shorie | 26:e99f71165e19 | 132 | this->leave_critical_section(); // now, ok to accept interrupt. |
shorie | 26:e99f71165e19 | 133 | } |
shorie | 26:e99f71165e19 | 134 | |
shorie | 26:e99f71165e19 | 135 | void SignalProcessing::set_eg_decay( float32_t decay ) |
shorie | 26:e99f71165e19 | 136 | { |
shorie | 26:e99f71165e19 | 137 | this->enter_critical_section(); // forbidden interrrupt. |
shorie | 26:e99f71165e19 | 138 | this->note->set_eg_decay( decay ); |
shorie | 26:e99f71165e19 | 139 | this->leave_critical_section(); // now, ok to accept interrupt. |
shorie | 26:e99f71165e19 | 140 | } |
shorie | 26:e99f71165e19 | 141 | |
shorie | 26:e99f71165e19 | 142 | void SignalProcessing::set_eg_sustain( float32_t sustain ) // [0,1.0] |
shorie | 26:e99f71165e19 | 143 | { |
shorie | 26:e99f71165e19 | 144 | this->enter_critical_section(); // forbidden interrrupt. |
shorie | 26:e99f71165e19 | 145 | this->note->set_eg_sustain( sustain ); |
shorie | 26:e99f71165e19 | 146 | this->leave_critical_section(); // now, ok to accept interrupt. |
shorie | 26:e99f71165e19 | 147 | } |
shorie | 26:e99f71165e19 | 148 | |
shorie | 26:e99f71165e19 | 149 | void SignalProcessing::set_eg_release ( float32_t release ) // [0,1.0] |
shorie | 26:e99f71165e19 | 150 | { |
shorie | 26:e99f71165e19 | 151 | this->enter_critical_section(); // forbidden interrrupt. |
shorie | 26:e99f71165e19 | 152 | this->note->set_eg_release( release ); |
shorie | 26:e99f71165e19 | 153 | this->leave_critical_section(); // now, ok to accept interrupt. |
shorie | 26:e99f71165e19 | 154 | } |
shorie | 26:e99f71165e19 | 155 | |
shorie | 26:e99f71165e19 | 156 | |
shorie | 26:e99f71165e19 | 157 | |
shorie | 26:e99f71165e19 | 158 | |
shorie | 10:a00c73efc6c3 | 159 | /************************** skeleton dependent methond. ***********************/ |
shorie | 6:486b1cb03e61 | 160 | // essential members. Do not touch. |
shorie | 6:486b1cb03e61 | 161 | void SignalProcessing::enter_critical_section(void) |
shorie | 6:486b1cb03e61 | 162 | { |
shorie | 6:486b1cb03e61 | 163 | __disable_irq(); // globaly forbid all interrupt |
shorie | 6:486b1cb03e61 | 164 | } |
shorie | 6:486b1cb03e61 | 165 | |
shorie | 6:486b1cb03e61 | 166 | void SignalProcessing::leave_critical_section(void) |
shorie | 6:486b1cb03e61 | 167 | { |
shorie | 6:486b1cb03e61 | 168 | __enable_irq(); // globaly allow all interrupts |
shorie | 6:486b1cb03e61 | 169 | } |
shorie | 6:486b1cb03e61 | 170 |