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@15:de22b9d147e0, 2017-01-30 (annotated)
- Committer:
- shorie
- Date:
- Mon Jan 30 15:01:29 2017 +0000
- Revision:
- 15:de22b9d147e0
- Parent:
- 14:cec63d8da48c
- Child:
- 18:b9b1116f8768
Update VFO.
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 | 14:cec63d8da48c | 9 | this->vfo = new VFO(); // allocate VFO |
shorie | 10:a00c73efc6c3 | 10 | } // End of constructor() |
shorie | 6:486b1cb03e61 | 11 | |
shorie | 10:a00c73efc6c3 | 12 | |
shorie | 10:a00c73efc6c3 | 13 | // Modify this method to implement your audio algorithm. |
shorie | 6:486b1cb03e61 | 14 | void SignalProcessing::run( |
shorie | 6:486b1cb03e61 | 15 | float rx_left_buffer[], // array of the left input samples |
shorie | 6:486b1cb03e61 | 16 | float rx_right_buffer[], // array of the right input samples |
shorie | 6:486b1cb03e61 | 17 | float tx_left_buffer[], // place to write the left output samples |
shorie | 13:b33cb5925113 | 18 | float tx_right_buffer[], // place to write the right output samples |
shorie | 6:486b1cb03e61 | 19 | unsigned int block_size // block size [sample] |
shorie | 6:486b1cb03e61 | 20 | ) |
shorie | 6:486b1cb03e61 | 21 | { |
shorie | 6:486b1cb03e61 | 22 | // place the signal processing coce here |
shorie | 14:cec63d8da48c | 23 | |
shorie | 14:cec63d8da48c | 24 | // VFO |
shorie | 14:cec63d8da48c | 25 | this->vfo->run( tx_left_buffer, block_size); |
shorie | 14:cec63d8da48c | 26 | |
shorie | 14:cec63d8da48c | 27 | // apply gain and copy to right ch. |
shorie | 6:486b1cb03e61 | 28 | for ( int i= 0; i< block_size; i++ ) |
shorie | 6:486b1cb03e61 | 29 | { |
shorie | 14:cec63d8da48c | 30 | tx_right_buffer[i] = tx_left_buffer[i] *= this->volume_level; |
shorie | 6:486b1cb03e61 | 31 | } |
shorie | 10:a00c73efc6c3 | 32 | } // End of run() |
shorie | 10:a00c73efc6c3 | 33 | |
shorie | 14:cec63d8da48c | 34 | |
shorie | 15:de22b9d147e0 | 35 | // Sampling Frequency |
shorie | 14:cec63d8da48c | 36 | void SignalProcessing::set_Fs( int Fs ) |
shorie | 14:cec63d8da48c | 37 | { |
shorie | 15:de22b9d147e0 | 38 | this->enter_critical_section(); // forbidden interrrupt. |
shorie | 14:cec63d8da48c | 39 | this->vfo->set_Fs( Fs ); |
shorie | 15:de22b9d147e0 | 40 | this->leave_critical_section(); // now, ok to accept interrupt. |
shorie | 14:cec63d8da48c | 41 | } |
shorie | 14:cec63d8da48c | 42 | |
shorie | 15:de22b9d147e0 | 43 | // Oscillation Frequency |
shorie | 15:de22b9d147e0 | 44 | void SignalProcessing::set_vfo_frequency( int freq ) |
shorie | 14:cec63d8da48c | 45 | { |
shorie | 15:de22b9d147e0 | 46 | this->enter_critical_section(); // forbidden interrrupt. |
shorie | 14:cec63d8da48c | 47 | this->vfo->set_frequency( freq ); |
shorie | 15:de22b9d147e0 | 48 | this->leave_critical_section(); // now, ok to accept interrupt. |
shorie | 14:cec63d8da48c | 49 | } |
shorie | 14:cec63d8da48c | 50 | |
shorie | 15:de22b9d147e0 | 51 | // Duty Cycle of VFO |
shorie | 15:de22b9d147e0 | 52 | void SignalProcessing::set_vfo_duty_cycle( float duty ) |
shorie | 14:cec63d8da48c | 53 | { |
shorie | 15:de22b9d147e0 | 54 | this->enter_critical_section(); // forbidden interrrupt. |
shorie | 14:cec63d8da48c | 55 | this->vfo->set_duty_cycle( duty ); |
shorie | 15:de22b9d147e0 | 56 | this->leave_critical_section(); // now, ok to accept interrupt. |
shorie | 14:cec63d8da48c | 57 | } |
shorie | 14:cec63d8da48c | 58 | |
shorie | 15:de22b9d147e0 | 59 | // VFO wave style |
shorie | 15:de22b9d147e0 | 60 | void SignalProcessing::set_vfo_wave_style( wave_style style ) |
shorie | 14:cec63d8da48c | 61 | { |
shorie | 15:de22b9d147e0 | 62 | this->enter_critical_section(); // forbidden interrrupt. |
shorie | 14:cec63d8da48c | 63 | this->vfo->set_wave_style( style ); |
shorie | 15:de22b9d147e0 | 64 | this->leave_critical_section(); // now, ok to accept interrupt. |
shorie | 14:cec63d8da48c | 65 | } |
shorie | 14:cec63d8da48c | 66 | |
shorie | 6:486b1cb03e61 | 67 | |
shorie | 15:de22b9d147e0 | 68 | // Set the volume level to the object. |
shorie | 6:486b1cb03e61 | 69 | void SignalProcessing::set_volume( float vol ) |
shorie | 6:486b1cb03e61 | 70 | { |
shorie | 6:486b1cb03e61 | 71 | this->enter_critical_section(); // forbidden interrrupt. |
shorie | 6:486b1cb03e61 | 72 | this->volume_level = vol; |
shorie | 6:486b1cb03e61 | 73 | this->leave_critical_section(); // now, ok to accept interrupt. |
shorie | 6:486b1cb03e61 | 74 | } |
shorie | 6:486b1cb03e61 | 75 | |
shorie | 6:486b1cb03e61 | 76 | |
shorie | 6:486b1cb03e61 | 77 | |
shorie | 10:a00c73efc6c3 | 78 | /************************** skeleton dependent methond. ***********************/ |
shorie | 6:486b1cb03e61 | 79 | // essential members. Do not touch. |
shorie | 6:486b1cb03e61 | 80 | void SignalProcessing::enter_critical_section(void) |
shorie | 6:486b1cb03e61 | 81 | { |
shorie | 6:486b1cb03e61 | 82 | __disable_irq(); // globaly forbid all interrupt |
shorie | 6:486b1cb03e61 | 83 | } |
shorie | 6:486b1cb03e61 | 84 | |
shorie | 6:486b1cb03e61 | 85 | void SignalProcessing::leave_critical_section(void) |
shorie | 6:486b1cb03e61 | 86 | { |
shorie | 6:486b1cb03e61 | 87 | __enable_irq(); // globaly allow all interrupts |
shorie | 6:486b1cb03e61 | 88 | } |
shorie | 6:486b1cb03e61 | 89 |