Sample program of the mbed Audio Framework for the Nucleo F746ZG
Dependencies: amakusa mbed-dsp mbed shimabara ukifune unzen_nucleo_f746
Fork of Signal_nucleo_f746 by
main.cpp
00001 #include "mbed.h" 00002 00003 // Note : Do not touch the "unzen dependent" part. No need to read. 00004 // Modify the "project dependent" part. 00005 // Also, Modify the SignalProcessing class. 00006 00007 00008 /************************** unzen dependent constants. ************************/ 00009 #define CODEC_I2C_ADDR 0x38 // Address of the ADAU-1361A 00010 00011 00012 /*========================= Project Dependent Constants ======================*/ 00013 #define BLOCKSIZE 16 // number of the sample to be processed at once. 00014 #define FS shimabara::Fs_48 // Fs can be Fs_32, Fs_441, Fs_48, Fs_96 00015 00016 00017 /************************** unzen dependent include. **************************/ 00018 #include "unzen.h" // audio framework include file 00019 #include "umb_adau1361a.h" // audio codec contoler include file 00020 #include "amakusa.h" // audio signal processing class library. 00021 #include "ukifune.h" // UI board support routines 00022 #include "signal_processing.h" // Implementaion of user signal processing. 00023 00024 00025 /************************* Unzen Dependent Global Variables *******************/ 00026 // I2C is essential to talk with ADAU1361 00027 static I2C i2c(D14, D15); 00028 // create an audio codec contoler 00029 static shimabara::UMB_ADAU1361A codec(FS, i2c, CODEC_I2C_ADDR ); 00030 // create an audio framework by singlton pattern 00031 static unzen::Framework audio; 00032 // create a pointer to the signal processing object. 00033 static SignalProcessing * process; 00034 00035 00036 /************************* Unzen Dependent Function Prototype *****************/ 00037 // for system usage. Do not care. 00038 void initialize_system(void); 00039 00040 00041 /*========================= Main program. ====================================*/ 00042 int main() 00043 { 00044 uint32_t pushing, releasing, holding; 00045 00046 // start audio. Do not touch 00047 initialize_system(); 00048 00049 // main loop. Signal processing is done in background. 00050 while(1) 00051 { // place your foreground program here. 00052 00053 // get volume from UI panel, then apply it to signal processing. 00054 process->set_volume( ukifune::get_volume(0) ); 00055 00056 // sample usage of button switch detection 00057 ukifune::get_button_state( pushing, releasing, holding); 00058 00059 // pushing detection demo 00060 if ( pushing & (1 << ukifune::swm1 ) ) // is SWM1 switch pusshing down? 00061 ukifune::toggle_led( ukifune::led1_1 ); // then, toggle LED1_1 00062 00063 // releasing detection demo 00064 if ( releasing & (1 << ukifune::swm2 ) ) // is SWM2 switch releasing? 00065 ukifune::toggle_led( ukifune::led2_1 ); // then toggle LED2_1 00066 00067 // holding detection demo 00068 if ( holding & (1 << ukifune::swm3 ) ) // is SWM3 switch holding? 00069 ukifune::turn_led_on( ukifune::led3_1 ); // then turn LED3_1 on 00070 else 00071 ukifune::turn_led_off( ukifune::led3_1 ); // else off 00072 00073 00074 // you have to call tick() every 20mS-50mS if you need get_volume() 00075 wait(0.05); 00076 ukifune::tick(); 00077 } 00078 } // End of main 00079 00080 00081 /************************* Unzen Dependent Callbacks **************************/ 00082 // customer signal processing initialization call back. 00083 void init_callback( 00084 unsigned int block_size // block size [sample] 00085 ) 00086 { 00087 // place initialization code here 00088 process = new SignalProcessing( block_size ); 00089 } // end of init_callback 00090 00091 00092 // customer signal processing call back. 00093 void process_callback( 00094 float rx_left_buffer[], // array of the left input samples 00095 float rx_right_buffer[], // array of the right input samples 00096 float tx_left_buffer[], // place to write the left output samples 00097 float tx_right_buffer[], // place to write the right output samples 00098 unsigned int block_size // block size [sample] 00099 ) 00100 { 00101 // place signal processing code here 00102 process->run( rx_left_buffer, rx_right_buffer, tx_left_buffer, tx_right_buffer, block_size ); 00103 } // End of process_callback 00104 00105 00106 /************************* Unzen Dependent Function implementation ************/ 00107 void initialize_system(void) 00108 { 00109 // Set I3C clock to 100kHz 00110 i2c.frequency( 100000 ); 00111 00112 // Configure the optional block size of signal processing. By default, it is 1[Sample] 00113 audio.set_block_size(BLOCKSIZE); 00114 00115 // Start UI module. 00116 ukifune::init( & audio ); 00117 00118 // Start the ADAU1361. Audio codec starts to generate the I2C signals 00119 codec.start(); 00120 // Start the audio framework on ARM processor. 00121 audio.start( init_callback, process_callback); // path the initializaiton and process call back to framework 00122 00123 // Setup initial analog gain 00124 codec.set_hp_output_gain( 0, 0 ); 00125 codec.set_line_output_gain( 0, 0 ); 00126 }
Generated on Sun Jul 17 2022 15:20:51 by 1.7.2