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@22:dc2cbe8db9d9, 2017-02-05 (annotated)
- Committer:
- shorie
- Date:
- Sun Feb 05 06:16:49 2017 +0000
- Revision:
- 22:dc2cbe8db9d9
- Parent:
- 18:b9b1116f8768
- Child:
- 26:e99f71165e19
Integrated filter
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 | 18:b9b1116f8768 | 28 | this->note->run( tx_left_buffer, block_size); |
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 | 15:de22b9d147e0 | 47 | void SignalProcessing::set_vfo_frequency( int 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 | 10:a00c73efc6c3 | 114 | /************************** skeleton dependent methond. ***********************/ |
shorie | 6:486b1cb03e61 | 115 | // essential members. Do not touch. |
shorie | 6:486b1cb03e61 | 116 | void SignalProcessing::enter_critical_section(void) |
shorie | 6:486b1cb03e61 | 117 | { |
shorie | 6:486b1cb03e61 | 118 | __disable_irq(); // globaly forbid all interrupt |
shorie | 6:486b1cb03e61 | 119 | } |
shorie | 6:486b1cb03e61 | 120 | |
shorie | 6:486b1cb03e61 | 121 | void SignalProcessing::leave_critical_section(void) |
shorie | 6:486b1cb03e61 | 122 | { |
shorie | 6:486b1cb03e61 | 123 | __enable_irq(); // globaly allow all interrupts |
shorie | 6:486b1cb03e61 | 124 | } |
shorie | 6:486b1cb03e61 | 125 |