Synthesizer based on the Unzen / Nucleo F746ZG

Dependencies:   amakusa mbed-dsp mbed shimabara ukifune unzen_nucleo_f746

Fork of skeleton_unzen_nucleo_f746 by seiichi horie

雲仙フレームワークのテストとして作っているプロジェクトです。中身はどんどん変っていきます。 説明はDSP空挺団の「シンセサイザー」カテゴリーを参照してください。初回は「ドッグフードを食べる」です。

Committer:
shorie
Date:
Wed Feb 01 15:00:31 2017 +0000
Revision:
18:b9b1116f8768
Parent:
15:de22b9d147e0
Child:
22:dc2cbe8db9d9
Update ciomment

Who changed what in which revision?

UserRevisionLine numberNew 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 15:de22b9d147e0 57 this->enter_critical_section(); // forbidden interrrupt.
shorie 18:b9b1116f8768 58 this->note->set_vfo_duty_cycle( duty );
shorie 15:de22b9d147e0 59 this->leave_critical_section(); // now, ok to accept interrupt.
shorie 14:cec63d8da48c 60 }
shorie 14:cec63d8da48c 61
shorie 18:b9b1116f8768 62 // VFO wave form
shorie 18:b9b1116f8768 63 void SignalProcessing::set_vfo_wave_form( wave_form form )
shorie 14:cec63d8da48c 64 {
shorie 15:de22b9d147e0 65 this->enter_critical_section(); // forbidden interrrupt.
shorie 18:b9b1116f8768 66 this->note->set_vfo_wave_form( form );
shorie 15:de22b9d147e0 67 this->leave_critical_section(); // now, ok to accept interrupt.
shorie 14:cec63d8da48c 68 }
shorie 14:cec63d8da48c 69
shorie 6:486b1cb03e61 70
shorie 15:de22b9d147e0 71 // Set the volume level to the object.
shorie 6:486b1cb03e61 72 void SignalProcessing::set_volume( float vol )
shorie 6:486b1cb03e61 73 {
shorie 6:486b1cb03e61 74 this->enter_critical_section(); // forbidden interrrupt.
shorie 6:486b1cb03e61 75 this->volume_level = vol;
shorie 6:486b1cb03e61 76 this->leave_critical_section(); // now, ok to accept interrupt.
shorie 6:486b1cb03e61 77 }
shorie 6:486b1cb03e61 78
shorie 6:486b1cb03e61 79
shorie 6:486b1cb03e61 80
shorie 10:a00c73efc6c3 81 /************************** skeleton dependent methond. ***********************/
shorie 6:486b1cb03e61 82 // essential members. Do not touch.
shorie 6:486b1cb03e61 83 void SignalProcessing::enter_critical_section(void)
shorie 6:486b1cb03e61 84 {
shorie 6:486b1cb03e61 85 __disable_irq(); // globaly forbid all interrupt
shorie 6:486b1cb03e61 86 }
shorie 6:486b1cb03e61 87
shorie 6:486b1cb03e61 88 void SignalProcessing::leave_critical_section(void)
shorie 6:486b1cb03e61 89 {
shorie 6:486b1cb03e61 90 __enable_irq(); // globaly allow all interrupts
shorie 6:486b1cb03e61 91 }
shorie 6:486b1cb03e61 92