Experimental implementation of the adaptive filter of "Interface" magazine in 2016-2017

Dependencies:   amakusa mbed-dsp mbed shimabara ukifune unzen_nucleo_f746

Fork of skeleton_unzen_nucleo_f746 by seiichi horie

ハードウェアおよびソフトウェアはskelton_unzen_nucleo_f746を基本にしています。

Committer:
shorie
Date:
Fri Jan 27 02:13:43 2017 +0000
Revision:
9:7f521a0b397c
Parent:
8:d8d1776e865b
Child:
11:7d8740437e6a
Comment edited.

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 6:486b1cb03e61 44 // start audio. Do not touch
shorie 6:486b1cb03e61 45 initialize_system();
shorie 0:a837eeab3ca6 46
shorie 6:486b1cb03e61 47 // main loop. Signal processing is done in background.
shorie 6:486b1cb03e61 48 while(1)
shorie 6:486b1cb03e61 49 { // place your foreground program here.
shorie 6:486b1cb03e61 50 process->set_volume( ukifune::get_volume(0) );
shorie 2:d5028a37f17b 51
shorie 6:486b1cb03e61 52 // you have to call tick() every 20mS-50mS if you need get_volume()
shorie 6:486b1cb03e61 53 wait(0.05);
shorie 6:486b1cb03e61 54 ukifune::tick();
shorie 6:486b1cb03e61 55 }
shorie 7:e86c645231ff 56 } // End of main
shorie 7:e86c645231ff 57
shorie 7:e86c645231ff 58
shorie 8:d8d1776e865b 59 /************************* Unzen Dependent Callbacks **************************/
shorie 7:e86c645231ff 60 // customer signal processing initialization call back.
shorie 7:e86c645231ff 61 void init_callback(
shorie 7:e86c645231ff 62 unsigned int block_size // block size [sample]
shorie 7:e86c645231ff 63 )
shorie 7:e86c645231ff 64 {
shorie 7:e86c645231ff 65 // place initialization code here
shorie 7:e86c645231ff 66 process = new SignalProcessing( block_size );
shorie 7:e86c645231ff 67 } // end of init_callback
shorie 7:e86c645231ff 68
shorie 7:e86c645231ff 69
shorie 7:e86c645231ff 70 // customer signal processing call back.
shorie 7:e86c645231ff 71 void process_callback(
shorie 7:e86c645231ff 72 float rx_left_buffer[], // array of the left input samples
shorie 7:e86c645231ff 73 float rx_right_buffer[], // array of the right input samples
shorie 7:e86c645231ff 74 float tx_left_buffer[], // place to write the left output samples
shorie 7:e86c645231ff 75 float tx_right_buffer[], // place to write the left output samples
shorie 7:e86c645231ff 76 unsigned int block_size // block size [sample]
shorie 7:e86c645231ff 77 )
shorie 7:e86c645231ff 78 {
shorie 7:e86c645231ff 79 // place signal processing code here
shorie 7:e86c645231ff 80 process->run( rx_left_buffer, rx_right_buffer, tx_left_buffer, tx_right_buffer, block_size );
shorie 7:e86c645231ff 81 } // End of process_callback
shorie 2:d5028a37f17b 82
shorie 6:486b1cb03e61 83
shorie 6:486b1cb03e61 84 /************************* Unzen Dependent Function implementation ************/
shorie 6:486b1cb03e61 85 void initialize_system(void)
shorie 2:d5028a37f17b 86 {
shorie 6:486b1cb03e61 87 // Set I3C clock to 100kHz
shorie 6:486b1cb03e61 88 i2c.frequency( 100000 );
shorie 6:486b1cb03e61 89
shorie 6:486b1cb03e61 90 // Configure the optional block size of signal processing. By default, it is 1[Sample]
shorie 6:486b1cb03e61 91 audio.set_block_size(BLOCKSIZE);
shorie 6:486b1cb03e61 92
shorie 6:486b1cb03e61 93 // Start UI module.
shorie 6:486b1cb03e61 94 ukifune::init( & audio );
shorie 6:486b1cb03e61 95
shorie 6:486b1cb03e61 96 // Start the ADAU1361. Audio codec starts to generate the I2C signals
shorie 6:486b1cb03e61 97 codec.start();
shorie 6:486b1cb03e61 98 // Start the audio framework on ARM processor.
shorie 6:486b1cb03e61 99 audio.start( init_callback, process_callback); // path the initializaiton and process call back to framework
shorie 6:486b1cb03e61 100
shorie 6:486b1cb03e61 101 // Setup initial analog gain
shorie 6:486b1cb03e61 102 codec.set_hp_output_gain( 0, 0 );
shorie 6:486b1cb03e61 103 codec.set_line_output_gain( 0, 0 );
shorie 6:486b1cb03e61 104 }