Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: amakusa mbed-dsp mbed shimabara ukifune unzen_nucleo_f746
Fork of skeleton_unzen_nucleo_f746 by
signal_processing.cpp
00001 #include "signal_processing.h" 00002 00003 /*========================= Project Dependent Method =========================*/ 00004 // Modify this constructor to initialize your audio algorithm. 00005 SignalProcessing::SignalProcessing( unsigned int block_size ) 00006 { 00007 // place the signal processing initializing code here. 00008 this->volume_level = 0.0; // sample initializaiton 00009 this->note = new Monophonic(block_size); // allocate VFO 00010 note->set_Fs( SAMPLING_FREQUENCY ); 00011 note->set_vfo_frequency( 440 ); 00012 note->set_vfo_wave_form( triangle ); 00013 } // End of constructor() 00014 00015 00016 // Modify this method to implement your audio algorithm. 00017 void SignalProcessing::run( 00018 float rx_left_buffer[], // array of the left input samples 00019 float rx_right_buffer[], // array of the right input samples 00020 float tx_left_buffer[], // place to write the left output samples 00021 float tx_right_buffer[], // place to write the right output samples 00022 unsigned int block_size // block size [sample] 00023 ) 00024 { 00025 // place the signal processing coce here 00026 00027 // VFO 00028 this->note->run( tx_left_buffer); 00029 00030 // apply gain and copy to right ch. 00031 for ( int i= 0; i< block_size; i++ ) 00032 { 00033 tx_right_buffer[i] = tx_left_buffer[i] *= this->volume_level; 00034 } 00035 } // End of run() 00036 00037 00038 // Sampling Frequency 00039 void SignalProcessing::set_Fs( int Fs ) 00040 { 00041 this->enter_critical_section(); // forbidden interrrupt. 00042 this->note->set_Fs( Fs ); 00043 this->leave_critical_section(); // now, ok to accept interrupt. 00044 } 00045 00046 // Oscillation Frequency 00047 void SignalProcessing::set_vfo_frequency( float freq ) 00048 { 00049 this->enter_critical_section(); // forbidden interrrupt. 00050 this->note->set_vfo_frequency( freq ); 00051 this->leave_critical_section(); // now, ok to accept interrupt. 00052 } 00053 00054 // Duty Cycle of VFO 00055 void SignalProcessing::set_vfo_duty_cycle( float duty ) 00056 { 00057 duty *= 0.5f; // [0.0,0.5] 00058 this->enter_critical_section(); // forbidden interrrupt. 00059 this->note->set_vfo_duty_cycle( duty ); 00060 this->leave_critical_section(); // now, ok to accept interrupt. 00061 } 00062 00063 // VFO wave form 00064 void SignalProcessing::set_vfo_wave_form( wave_form form ) 00065 { 00066 this->enter_critical_section(); // forbidden interrrupt. 00067 this->note->set_vfo_wave_form( form ); 00068 this->leave_critical_section(); // now, ok to accept interrupt. 00069 } 00070 00071 00072 // Set the volume level to the object. 00073 void SignalProcessing::set_volume( float vol ) 00074 { 00075 this->enter_critical_section(); // forbidden interrrupt. 00076 this->volume_level = vol; 00077 this->leave_critical_section(); // now, ok to accept interrupt. 00078 } 00079 00080 // Set the lpf/hpf/bpf 00081 void SignalProcessing::set_filter_mode( svf_mode mode ) 00082 { 00083 this->enter_critical_section(); // forbidden interrrupt. 00084 this->note->set_filter_mode( mode ); 00085 this->leave_critical_section(); // now, ok to accept interrupt. 00086 } 00087 00088 // Set the Q value. 00089 void SignalProcessing::set_filter_Q( float Q ) 00090 { 00091 // range of the parameter Q ( volume input ) is [0,1.0]. 00092 // Transform it to [0.1,10] 00093 Q *= 9.9f; 00094 Q += 0.1f; 00095 00096 this->enter_critical_section(); // forbidden interrrupt. 00097 this->note->set_filter_Q( Q ); 00098 this->leave_critical_section(); // now, ok to accept interrupt. 00099 } 00100 00101 // Set the f_factor value. 00102 void SignalProcessing::set_filter_f_factor( float f_factor ) 00103 { 00104 // range of the parameter f_factor ( volume input ) is [0,1.0]. 00105 // Transform it to [0.1,5.0] 00106 f_factor *= 4.9f; 00107 f_factor += 0.1f; 00108 00109 this->enter_critical_section(); // forbidden interrrupt. 00110 this->note->set_filter_f_factor( f_factor ); 00111 this->leave_critical_section(); // now, ok to accept interrupt. 00112 } 00113 00114 void SignalProcessing::eg_on(void) 00115 { 00116 this->enter_critical_section(); // forbidden interrrupt. 00117 this->note->eg_on(); 00118 this->leave_critical_section(); // now, ok to accept interrupt. 00119 } 00120 00121 void SignalProcessing::eg_off(void) 00122 { 00123 this->enter_critical_section(); // forbidden interrrupt. 00124 this->note->eg_off(); 00125 this->leave_critical_section(); // now, ok to accept interrupt. 00126 } 00127 00128 void SignalProcessing::set_eg_attack( float32_t attack ) 00129 { 00130 this->enter_critical_section(); // forbidden interrrupt. 00131 this->note->set_eg_attack( attack ); 00132 this->leave_critical_section(); // now, ok to accept interrupt. 00133 } 00134 00135 void SignalProcessing::set_eg_decay( float32_t decay ) 00136 { 00137 this->enter_critical_section(); // forbidden interrrupt. 00138 this->note->set_eg_decay( decay ); 00139 this->leave_critical_section(); // now, ok to accept interrupt. 00140 } 00141 00142 void SignalProcessing::set_eg_sustain( float32_t sustain ) // [0,1.0] 00143 { 00144 this->enter_critical_section(); // forbidden interrrupt. 00145 this->note->set_eg_sustain( sustain ); 00146 this->leave_critical_section(); // now, ok to accept interrupt. 00147 } 00148 00149 void SignalProcessing::set_eg_release ( float32_t release ) // [0,1.0] 00150 { 00151 this->enter_critical_section(); // forbidden interrrupt. 00152 this->note->set_eg_release( release ); 00153 this->leave_critical_section(); // now, ok to accept interrupt. 00154 } 00155 00156 00157 00158 00159 /************************** skeleton dependent methond. ***********************/ 00160 // essential members. Do not touch. 00161 void SignalProcessing::enter_critical_section(void) 00162 { 00163 __disable_irq(); // globaly forbid all interrupt 00164 } 00165 00166 void SignalProcessing::leave_critical_section(void) 00167 { 00168 __enable_irq(); // globaly allow all interrupts 00169 } 00170
Generated on Wed Jul 13 2022 23:24:36 by
