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@14:cec63d8da48c, 2017-01-30 (annotated)
- Committer:
- shorie
- Date:
- Mon Jan 30 14:48:42 2017 +0000
- Revision:
- 14:cec63d8da48c
- Parent:
- 13:b33cb5925113
- Child:
- 15:de22b9d147e0
VFO added.
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 | 14:cec63d8da48c | 35 | void SignalProcessing::set_Fs( int Fs ) |
shorie | 14:cec63d8da48c | 36 | { |
shorie | 14:cec63d8da48c | 37 | this->vfo->set_Fs( Fs ); |
shorie | 14:cec63d8da48c | 38 | } |
shorie | 14:cec63d8da48c | 39 | |
shorie | 14:cec63d8da48c | 40 | void SignalProcessing::set_frequency( int freq ) |
shorie | 14:cec63d8da48c | 41 | { |
shorie | 14:cec63d8da48c | 42 | this->vfo->set_frequency( freq ); |
shorie | 14:cec63d8da48c | 43 | } |
shorie | 14:cec63d8da48c | 44 | |
shorie | 14:cec63d8da48c | 45 | void SignalProcessing::set_duty_cycle( float duty ) |
shorie | 14:cec63d8da48c | 46 | { |
shorie | 14:cec63d8da48c | 47 | this->vfo->set_duty_cycle( duty ); |
shorie | 14:cec63d8da48c | 48 | } |
shorie | 14:cec63d8da48c | 49 | |
shorie | 14:cec63d8da48c | 50 | void SignalProcessing::set_wave_style( wave_style style ) |
shorie | 14:cec63d8da48c | 51 | { |
shorie | 14:cec63d8da48c | 52 | this->vfo->set_wave_style( style ); |
shorie | 14:cec63d8da48c | 53 | } |
shorie | 14:cec63d8da48c | 54 | |
shorie | 14:cec63d8da48c | 55 | |
shorie | 6:486b1cb03e61 | 56 | |
shorie | 10:a00c73efc6c3 | 57 | // Sample method. Set the volume level to the object. |
shorie | 6:486b1cb03e61 | 58 | void SignalProcessing::set_volume( float vol ) |
shorie | 6:486b1cb03e61 | 59 | { |
shorie | 6:486b1cb03e61 | 60 | this->enter_critical_section(); // forbidden interrrupt. |
shorie | 6:486b1cb03e61 | 61 | this->volume_level = vol; |
shorie | 6:486b1cb03e61 | 62 | this->leave_critical_section(); // now, ok to accept interrupt. |
shorie | 6:486b1cb03e61 | 63 | } |
shorie | 6:486b1cb03e61 | 64 | |
shorie | 6:486b1cb03e61 | 65 | |
shorie | 6:486b1cb03e61 | 66 | |
shorie | 10:a00c73efc6c3 | 67 | /************************** skeleton dependent methond. ***********************/ |
shorie | 6:486b1cb03e61 | 68 | // essential members. Do not touch. |
shorie | 6:486b1cb03e61 | 69 | void SignalProcessing::enter_critical_section(void) |
shorie | 6:486b1cb03e61 | 70 | { |
shorie | 6:486b1cb03e61 | 71 | __disable_irq(); // globaly forbid all interrupt |
shorie | 6:486b1cb03e61 | 72 | } |
shorie | 6:486b1cb03e61 | 73 | |
shorie | 6:486b1cb03e61 | 74 | void SignalProcessing::leave_critical_section(void) |
shorie | 6:486b1cb03e61 | 75 | { |
shorie | 6:486b1cb03e61 | 76 | __enable_irq(); // globaly allow all interrupts |
shorie | 6:486b1cb03e61 | 77 | } |
shorie | 6:486b1cb03e61 | 78 |