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:
Sun Feb 05 06:16:49 2017 +0000
Revision:
22:dc2cbe8db9d9
Parent:
18:b9b1116f8768
Child:
26:e99f71165e19
Integrated filter

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shorie 1:98ddcbbe10ba 1 #include "mbed.h"
shorie 1:98ddcbbe10ba 2
shorie 9:7f521a0b397c 3 // Note : Do not touch the "unzen dependent" part. No need to read.
shorie 9:7f521a0b397c 4 // Modify the "project dependent" part.
shorie 9:7f521a0b397c 5 // Also, Modify the SignalProcessing class.
shorie 6:486b1cb03e61 6
shorie 6:486b1cb03e61 7
shorie 6:486b1cb03e61 8 /************************** unzen dependent constants. ************************/
shorie 6:486b1cb03e61 9 #define CODEC_I2C_ADDR 0x38 // Address of the ADAU-1361A
shorie 6:486b1cb03e61 10
shorie 6:486b1cb03e61 11
shorie 6:486b1cb03e61 12 /*========================= Project Dependent Constants ======================*/
shorie 6:486b1cb03e61 13 #define BLOCKSIZE 16 // number of the sample to be processed at once.
shorie 6:486b1cb03e61 14 #define FS shimabara::Fs_48 // Fs can be Fs_32, Fs_441, Fs_48, Fs_96
shorie 6:486b1cb03e61 15
shorie 6:486b1cb03e61 16
shorie 6:486b1cb03e61 17 /************************** unzen dependent include. **************************/
shorie 0:a837eeab3ca6 18 #include "unzen.h" // audio framework include file
shorie 1:98ddcbbe10ba 19 #include "umb_adau1361a.h" // audio codec contoler include file
shorie 3:1b420050bdda 20 #include "amakusa.h" // audio signal processing class library.
shorie 8:d8d1776e865b 21 #include "ukifune.h" // UI board support routines
shorie 8:d8d1776e865b 22 #include "signal_processing.h" // Implementaion of user signal processing.
shorie 2:d5028a37f17b 23
shorie 3:1b420050bdda 24
shorie 6:486b1cb03e61 25 /************************* Unzen Dependent Global Variables *******************/
shorie 6:486b1cb03e61 26 // I2C is essential to talk with ADAU1361
shorie 8:d8d1776e865b 27 static I2C i2c(D14, D15);
shorie 6:486b1cb03e61 28 // create an audio codec contoler
shorie 8:d8d1776e865b 29 static shimabara::UMB_ADAU1361A codec(FS, i2c, CODEC_I2C_ADDR );
shorie 6:486b1cb03e61 30 // create an audio framework by singlton pattern
shorie 8:d8d1776e865b 31 static unzen::Framework audio;
shorie 6:486b1cb03e61 32 // create a pointer to the signal processing object.
shorie 8:d8d1776e865b 33 static SignalProcessing * process;
shorie 6:486b1cb03e61 34
shorie 6:486b1cb03e61 35
shorie 6:486b1cb03e61 36 /************************* Unzen Dependent Function Prototype *****************/
shorie 6:486b1cb03e61 37 // for system usage. Do not care.
shorie 6:486b1cb03e61 38 void initialize_system(void);
shorie 0:a837eeab3ca6 39
shorie 2:d5028a37f17b 40
shorie 7:e86c645231ff 41 /*========================= Main program. ====================================*/
shorie 0:a837eeab3ca6 42 int main()
shorie 0:a837eeab3ca6 43 {
shorie 11:7d8740437e6a 44 uint32_t pushing, releasing, holding;
shorie 17:728ffc633179 45
shorie 18:b9b1116f8768 46 // VFO form
shorie 18:b9b1116f8768 47 wave_form form = triangle;
shorie 22:dc2cbe8db9d9 48
shorie 22:dc2cbe8db9d9 49 // filter mode
shorie 22:dc2cbe8db9d9 50 svf_mode filter_mode = lpf;
shorie 11:7d8740437e6a 51
shorie 6:486b1cb03e61 52 // start audio. Do not touch
shorie 6:486b1cb03e61 53 initialize_system();
shorie 22:dc2cbe8db9d9 54
shorie 22:dc2cbe8db9d9 55 // set tentative frequency
shorie 22:dc2cbe8db9d9 56 process->set_vfo_frequency( 440 );
shorie 17:728ffc633179 57
shorie 22:dc2cbe8db9d9 58 // set wave from
shorie 18:b9b1116f8768 59 process->set_vfo_wave_form( form );
shorie 22:dc2cbe8db9d9 60 ukifune::turn_led_on( ukifune::led1_1 );
shorie 22:dc2cbe8db9d9 61 ukifune::turn_led_off( ukifune::led1_2 );
shorie 22:dc2cbe8db9d9 62
shorie 22:dc2cbe8db9d9 63 // set filter mode
shorie 22:dc2cbe8db9d9 64 process->set_filter_mode( filter_mode );
shorie 22:dc2cbe8db9d9 65 ukifune::turn_led_on( ukifune::led2_1 );
shorie 22:dc2cbe8db9d9 66 ukifune::turn_led_off( ukifune::led2_2 );
shorie 22:dc2cbe8db9d9 67 ukifune::turn_led_off( ukifune::led2_3 );
shorie 22:dc2cbe8db9d9 68 ukifune::turn_led_off( ukifune::led2_4 );
shorie 22:dc2cbe8db9d9 69
shorie 0:a837eeab3ca6 70
shorie 6:486b1cb03e61 71 // main loop. Signal processing is done in background.
shorie 6:486b1cb03e61 72 while(1)
shorie 6:486b1cb03e61 73 { // place your foreground program here.
shorie 12:2b121255e2d1 74
shorie 12:2b121255e2d1 75 // get volume from UI panel, then apply it to signal processing.
shorie 17:728ffc633179 76 process->set_volume( ukifune::get_volume(0) );
shorie 17:728ffc633179 77 process->set_vfo_duty_cycle( ukifune::get_volume(1) );
shorie 22:dc2cbe8db9d9 78 process->set_filter_f_factor( ukifune::get_volume(2) );
shorie 22:dc2cbe8db9d9 79 process->set_filter_Q( ukifune::get_volume(3) );
shorie 2:d5028a37f17b 80
shorie 11:7d8740437e6a 81 // sample usage of button switch detection
shorie 11:7d8740437e6a 82 ukifune::get_button_state( pushing, releasing, holding);
shorie 11:7d8740437e6a 83
shorie 11:7d8740437e6a 84 // pushing detection demo
shorie 22:dc2cbe8db9d9 85 // waveform
shorie 11:7d8740437e6a 86 if ( pushing & (1 << ukifune::swm1 ) ) // is SWM1 switch pusshing down?
shorie 18:b9b1116f8768 87 if ( form == triangle )
shorie 17:728ffc633179 88 {
shorie 18:b9b1116f8768 89 form = square;
shorie 18:b9b1116f8768 90 process->set_vfo_wave_form( form );
shorie 22:dc2cbe8db9d9 91 ukifune::turn_led_off( ukifune::led1_1 );
shorie 22:dc2cbe8db9d9 92 ukifune::turn_led_on( ukifune::led1_2 );
shorie 17:728ffc633179 93 }
shorie 17:728ffc633179 94 else
shorie 17:728ffc633179 95 {
shorie 18:b9b1116f8768 96 form = triangle;
shorie 18:b9b1116f8768 97 process->set_vfo_wave_form( form );
shorie 22:dc2cbe8db9d9 98 ukifune::turn_led_on( ukifune::led1_1 );
shorie 22:dc2cbe8db9d9 99 ukifune::turn_led_off( ukifune::led1_2 );
shorie 17:728ffc633179 100 }
shorie 17:728ffc633179 101
shorie 22:dc2cbe8db9d9 102 // filter mode
shorie 22:dc2cbe8db9d9 103 if ( pushing & (1 << ukifune::swm2 ) ) // is SWM2 switch pusshing down?
shorie 22:dc2cbe8db9d9 104 if ( filter_mode == lpf )
shorie 22:dc2cbe8db9d9 105 {
shorie 22:dc2cbe8db9d9 106 filter_mode = bpf;
shorie 22:dc2cbe8db9d9 107 process->set_filter_mode( filter_mode );
shorie 22:dc2cbe8db9d9 108 ukifune::turn_led_off( ukifune::led2_1 );
shorie 22:dc2cbe8db9d9 109 ukifune::turn_led_on( ukifune::led2_2 );
shorie 22:dc2cbe8db9d9 110 ukifune::turn_led_off( ukifune::led2_3 );
shorie 22:dc2cbe8db9d9 111 ukifune::turn_led_off( ukifune::led2_4 );
shorie 22:dc2cbe8db9d9 112 }
shorie 22:dc2cbe8db9d9 113 else if ( filter_mode == bpf )
shorie 22:dc2cbe8db9d9 114 {
shorie 22:dc2cbe8db9d9 115 filter_mode = hpf;
shorie 22:dc2cbe8db9d9 116 process->set_filter_mode( filter_mode );
shorie 22:dc2cbe8db9d9 117 ukifune::turn_led_off( ukifune::led2_1 );
shorie 22:dc2cbe8db9d9 118 ukifune::turn_led_off( ukifune::led2_2 );
shorie 22:dc2cbe8db9d9 119 ukifune::turn_led_on( ukifune::led2_3 );
shorie 22:dc2cbe8db9d9 120 ukifune::turn_led_off( ukifune::led2_4 );
shorie 22:dc2cbe8db9d9 121 }
shorie 22:dc2cbe8db9d9 122 else // hpf
shorie 22:dc2cbe8db9d9 123 {
shorie 22:dc2cbe8db9d9 124 filter_mode = lpf;
shorie 22:dc2cbe8db9d9 125 process->set_filter_mode( filter_mode );
shorie 22:dc2cbe8db9d9 126 ukifune::turn_led_on( ukifune::led2_1 );
shorie 22:dc2cbe8db9d9 127 ukifune::turn_led_off( ukifune::led2_2 );
shorie 22:dc2cbe8db9d9 128 ukifune::turn_led_off( ukifune::led2_3 );
shorie 22:dc2cbe8db9d9 129 ukifune::turn_led_off( ukifune::led2_4 );
shorie 22:dc2cbe8db9d9 130 }
shorie 11:7d8740437e6a 131
shorie 11:7d8740437e6a 132
shorie 11:7d8740437e6a 133
shorie 6:486b1cb03e61 134 // you have to call tick() every 20mS-50mS if you need get_volume()
shorie 6:486b1cb03e61 135 wait(0.05);
shorie 6:486b1cb03e61 136 ukifune::tick();
shorie 6:486b1cb03e61 137 }
shorie 7:e86c645231ff 138 } // End of main
shorie 7:e86c645231ff 139
shorie 7:e86c645231ff 140
shorie 8:d8d1776e865b 141 /************************* Unzen Dependent Callbacks **************************/
shorie 7:e86c645231ff 142 // customer signal processing initialization call back.
shorie 7:e86c645231ff 143 void init_callback(
shorie 7:e86c645231ff 144 unsigned int block_size // block size [sample]
shorie 7:e86c645231ff 145 )
shorie 7:e86c645231ff 146 {
shorie 7:e86c645231ff 147 // place initialization code here
shorie 7:e86c645231ff 148 process = new SignalProcessing( block_size );
shorie 7:e86c645231ff 149 } // end of init_callback
shorie 7:e86c645231ff 150
shorie 7:e86c645231ff 151
shorie 7:e86c645231ff 152 // customer signal processing call back.
shorie 7:e86c645231ff 153 void process_callback(
shorie 7:e86c645231ff 154 float rx_left_buffer[], // array of the left input samples
shorie 7:e86c645231ff 155 float rx_right_buffer[], // array of the right input samples
shorie 7:e86c645231ff 156 float tx_left_buffer[], // place to write the left output samples
shorie 13:b33cb5925113 157 float tx_right_buffer[], // place to write the right output samples
shorie 7:e86c645231ff 158 unsigned int block_size // block size [sample]
shorie 7:e86c645231ff 159 )
shorie 7:e86c645231ff 160 {
shorie 7:e86c645231ff 161 // place signal processing code here
shorie 7:e86c645231ff 162 process->run( rx_left_buffer, rx_right_buffer, tx_left_buffer, tx_right_buffer, block_size );
shorie 7:e86c645231ff 163 } // End of process_callback
shorie 2:d5028a37f17b 164
shorie 6:486b1cb03e61 165
shorie 6:486b1cb03e61 166 /************************* Unzen Dependent Function implementation ************/
shorie 6:486b1cb03e61 167 void initialize_system(void)
shorie 2:d5028a37f17b 168 {
shorie 6:486b1cb03e61 169 // Set I3C clock to 100kHz
shorie 6:486b1cb03e61 170 i2c.frequency( 100000 );
shorie 6:486b1cb03e61 171
shorie 6:486b1cb03e61 172 // Configure the optional block size of signal processing. By default, it is 1[Sample]
shorie 6:486b1cb03e61 173 audio.set_block_size(BLOCKSIZE);
shorie 6:486b1cb03e61 174
shorie 6:486b1cb03e61 175 // Start UI module.
shorie 6:486b1cb03e61 176 ukifune::init( & audio );
shorie 6:486b1cb03e61 177
shorie 6:486b1cb03e61 178 // Start the ADAU1361. Audio codec starts to generate the I2C signals
shorie 6:486b1cb03e61 179 codec.start();
shorie 6:486b1cb03e61 180 // Start the audio framework on ARM processor.
shorie 6:486b1cb03e61 181 audio.start( init_callback, process_callback); // path the initializaiton and process call back to framework
shorie 6:486b1cb03e61 182
shorie 6:486b1cb03e61 183 // Setup initial analog gain
shorie 6:486b1cb03e61 184 codec.set_hp_output_gain( 0, 0 );
shorie 6:486b1cb03e61 185 codec.set_line_output_gain( 0, 0 );
shorie 6:486b1cb03e61 186 }