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空挺団の「シンセサイザー」カテゴリーを参照してください。初回は「ドッグフードを食べる」です。
Diff: main.cpp
- Revision:
- 6:486b1cb03e61
- Parent:
- 3:1b420050bdda
- Child:
- 7:e86c645231ff
--- a/main.cpp Wed Jan 25 22:45:43 2017 +0000 +++ b/main.cpp Fri Jan 27 01:53:43 2017 +0000 @@ -1,39 +1,59 @@ #include "mbed.h" +// Note : Do not touch the "unzen dependent" part. +// Configure the "project dependent" part. + + +/************************** unzen dependent constants. ************************/ +#define CODEC_I2C_ADDR 0x38 // Address of the ADAU-1361A + + +/*========================= Project Dependent Constants ======================*/ +#define BLOCKSIZE 16 // number of the sample to be processed at once. +#define FS shimabara::Fs_48 // Fs can be Fs_32, Fs_441, Fs_48, Fs_96 + + +/************************** unzen dependent include. **************************/ #include "unzen.h" // audio framework include file #include "umb_adau1361a.h" // audio codec contoler include file #include "amakusa.h" // audio signal processing class library. #include "ukifune.h" // UI board support routines -#define BLOCKSIZE 1 -#define TAPS 200 - -#define CODEC_I2C_ADDR 0x38 // Address of the ADAU-1361A -#define AD7999 (0x29<<1) -#define ADCBUFSIZE 8 + +/*========================= project dependent include. =======================*/ +#include "signal_processing.h" -DigitalOut myled1(LED1); -float gain = 1.0; +/************************* Unzen Dependent Global Variables *******************/ + // I2C is essential to talk with ADAU1361 +I2C i2c(D14, D15); + // create an audio codec contoler +shimabara::UMB_ADAU1361A codec(FS, i2c, CODEC_I2C_ADDR ); + // create an audio framework by singlton pattern +unzen::Framework audio; + + +/*========================= project dependent Global Variable. ===============*/ + // create a pointer to the signal processing object. +SignalProcessing * process; + + + +/************************* Unzen Dependent Function Prototype *****************/ + // for system usage. Do not care. +void initialize_system(void); -amakusa::OSCSinCos *osc; -amakusa::FIRFilter *filter; -float coeff[TAPS]; -void parse_adc( char * buf, int &ch, int &data ); - + /*========================= project dependent Signal Processing. ============*/ // customer signal processing initialization call back. void init_callback( unsigned int block_size // block size [sample] ) { // place initialization code here - osc = new amakusa::OSCSinCos( 440.0, 48000, block_size ); // freq=440Hz, Fs=48kHz. - - filter = new amakusa::FIRFilter( TAPS, coeff, block_size ); // + process = new SignalProcessing( block_size ); } - // customer signal processing call back. void process_callback( float rx_left_buffer[], // array of the left input samples @@ -43,86 +63,47 @@ unsigned int block_size // block size [sample] ) { -#if 0 - // generate tone. - osc->run( tx_left_buffer ); -#elif 0 - filter->run( rx_left_buffer, tx_left_buffer ); -#else - for ( int i=0; i<block_size; i++) // for all sample - { - tx_right_buffer[i] = atan2( rx_right_buffer[i], rx_left_buffer[i] ); - - } - -#endif - - // copy left to right - for ( int i=0; i<block_size; i++) // for all sample - { - tx_right_buffer[i] = tx_left_buffer[i] *= 0.5F * gain; - - } + // place signal processing code here + process->run( rx_left_buffer, rx_right_buffer, tx_left_buffer, tx_right_buffer, block_size ); } - + int main() { - char adcbuf[ADCBUFSIZE]; - int dacch, dacdata; - - // I2C is essential to talk with ADAU1361 - I2C i2c(D14, D15); - - // create an audio codec contoler - shimabara::UMB_ADAU1361A codec(shimabara::Fs_48, i2c, CODEC_I2C_ADDR ); // Fs can be Fs_32, Fs_441, Fs_48, Fs_96 - - // create an audio framework by singlton pattern - unzen::Framework audio; - - // Set I3C clock to 100kHz - i2c.frequency( 100000 ); - - - // Configure the optional block size of signal processing. By default, it is 1[Sample] -// audio.set_block_size(16); - - - // Start the ADAU1361. Audio codec starts to generate the I2C signals - codec.start(); + // start audio. Do not touch + initialize_system(); - ukifune::init( & audio ); - - audio.set_block_size(BLOCKSIZE); - - // Start the audio framework on ARM processor. - audio.start( init_callback, process_callback); // path the initializaiton and process call back to framework - - codec.set_hp_output_gain( -3, -3 ); - codec.set_line_output_gain( -3, -3 ); - - // periodically changing gain for test - while(1) - { + // main loop. Signal processing is done in background. + while(1) + { // place your foreground program here. + process->set_volume( ukifune::get_volume(0) ); - i2c.read( AD7999, adcbuf, ADCBUFSIZE); - parse_adc( &adcbuf[0],dacch, dacdata ); - gain = dacdata / 255.0; - /* - myled1 = 1; - wait(0.2); - myled1 = 0; - wait(0.2); - */ - } + // you have to call tick() every 20mS-50mS if you need get_volume() + wait(0.05); + ukifune::tick(); + } } -void parse_adc( char * buf, int &ch, int &data ) + +/************************* Unzen Dependent Function implementation ************/ +void initialize_system(void) { - ch = ( buf[0] & 0x30 ) >> 4; - data = - ( buf[0] & 0x0F ) << 4 | - ( buf[1] & 0xF0 ) >> 4; - -} \ No newline at end of file + // Set I3C clock to 100kHz + i2c.frequency( 100000 ); + + // Configure the optional block size of signal processing. By default, it is 1[Sample] + audio.set_block_size(BLOCKSIZE); + + // Start UI module. + ukifune::init( & audio ); + + // Start the ADAU1361. Audio codec starts to generate the I2C signals + codec.start(); + // Start the audio framework on ARM processor. + audio.start( init_callback, process_callback); // path the initializaiton and process call back to framework + + // Setup initial analog gain + codec.set_hp_output_gain( 0, 0 ); + codec.set_line_output_gain( 0, 0 ); +}