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:
Mon Jan 02 11:05:36 2017 +0000
Revision:
2:d5028a37f17b
Parent:
1:98ddcbbe10ba
Child:
3:1b420050bdda
Temporary commit.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shorie 1:98ddcbbe10ba 1 #include "mbed.h"
shorie 1:98ddcbbe10ba 2
shorie 1:98ddcbbe10ba 3
shorie 0:a837eeab3ca6 4 #include "unzen.h" // audio framework include file
shorie 1:98ddcbbe10ba 5 #include "umb_adau1361a.h" // audio codec contoler include file
shorie 1:98ddcbbe10ba 6 #include "amakusa.h" // audio signal processing class library.
shorie 0:a837eeab3ca6 7
shorie 1:98ddcbbe10ba 8 #define CODEC_I2C_ADDR 0x38 // Address of the ADAU-1361A
shorie 2:d5028a37f17b 9 #define AD7999 (0x29<<1)
shorie 2:d5028a37f17b 10 #define ADCBUFSIZE 8
shorie 2:d5028a37f17b 11
shorie 0:a837eeab3ca6 12 DigitalOut myled1(LED1);
shorie 2:d5028a37f17b 13 float gain = 1.0;
shorie 0:a837eeab3ca6 14
shorie 1:98ddcbbe10ba 15 amakusa::OSCSinCos osc( 440.0, 48000 ); // freq=440Hz, Fs=48kHz.
shorie 2:d5028a37f17b 16
shorie 2:d5028a37f17b 17 void parse_adc( char * buf, int &ch, int &data );
shorie 0:a837eeab3ca6 18
shorie 0:a837eeab3ca6 19 // customer signal processing initialization call back.
shorie 0:a837eeab3ca6 20 void init_callback(
shorie 0:a837eeab3ca6 21 unsigned int block_size // block size [sample]
shorie 0:a837eeab3ca6 22 )
shorie 0:a837eeab3ca6 23 {
shorie 0:a837eeab3ca6 24 // place initialization code here
shorie 0:a837eeab3ca6 25 }
shorie 0:a837eeab3ca6 26
shorie 0:a837eeab3ca6 27
shorie 0:a837eeab3ca6 28 // customer signal processing call back.
shorie 0:a837eeab3ca6 29 void process_callback(
shorie 0:a837eeab3ca6 30 float rx_left_buffer[], // array of the left input samples
shorie 0:a837eeab3ca6 31 float rx_right_buffer[], // array of the right input samples
shorie 0:a837eeab3ca6 32 float tx_left_buffer[], // place to write the left output samples
shorie 0:a837eeab3ca6 33 float tx_right_buffer[], // place to write the left output samples
shorie 0:a837eeab3ca6 34 unsigned int block_size // block size [sample]
shorie 0:a837eeab3ca6 35 )
shorie 0:a837eeab3ca6 36 {
shorie 1:98ddcbbe10ba 37 // generate tone.
shorie 1:98ddcbbe10ba 38 osc.run( tx_left_buffer, block_size );
shorie 1:98ddcbbe10ba 39
shorie 1:98ddcbbe10ba 40 // copy left to right
shorie 0:a837eeab3ca6 41 for ( int i=0; i<block_size; i++) // for all sample
shorie 0:a837eeab3ca6 42 {
shorie 2:d5028a37f17b 43 tx_right_buffer[i] = tx_left_buffer[i] *= 0.5F * gain;
shorie 0:a837eeab3ca6 44
shorie 0:a837eeab3ca6 45 }
shorie 0:a837eeab3ca6 46 }
shorie 0:a837eeab3ca6 47
shorie 0:a837eeab3ca6 48
shorie 0:a837eeab3ca6 49
shorie 0:a837eeab3ca6 50 int main()
shorie 0:a837eeab3ca6 51 {
shorie 2:d5028a37f17b 52 char adcbuf[ADCBUFSIZE];
shorie 2:d5028a37f17b 53 int dacch, dacdata;
shorie 2:d5028a37f17b 54
shorie 0:a837eeab3ca6 55 // I2C is essential to talk with ADAU1361
shorie 0:a837eeab3ca6 56 I2C i2c(D14, D15);
shorie 0:a837eeab3ca6 57
shorie 0:a837eeab3ca6 58 // create an audio codec contoler
shorie 1:98ddcbbe10ba 59 shimabara::UMB_ADAU1361A codec(shimabara::Fs_48, i2c, CODEC_I2C_ADDR ); // Fs can be Fs_32, Fs_441, Fs_48, Fs_96
shorie 0:a837eeab3ca6 60
shorie 0:a837eeab3ca6 61 // create an audio framework by singlton pattern
shorie 0:a837eeab3ca6 62 unzen::Framework audio;
shorie 0:a837eeab3ca6 63
shorie 0:a837eeab3ca6 64 // Set I3C clock to 100kHz
shorie 0:a837eeab3ca6 65 i2c.frequency( 100000 );
shorie 0:a837eeab3ca6 66
shorie 0:a837eeab3ca6 67
shorie 0:a837eeab3ca6 68 // Configure the optional block size of signal processing. By default, it is 1[Sample]
shorie 0:a837eeab3ca6 69 // audio.set_block_size(16);
shorie 0:a837eeab3ca6 70
shorie 0:a837eeab3ca6 71
shorie 0:a837eeab3ca6 72 // Start the ADAU1361. Audio codec starts to generate the I2C signals
shorie 0:a837eeab3ca6 73 codec.start();
shorie 0:a837eeab3ca6 74
shorie 0:a837eeab3ca6 75 // Start the audio framework on ARM processor.
shorie 0:a837eeab3ca6 76 audio.start( init_callback, process_callback); // path the initializaiton and process call back to framework
shorie 0:a837eeab3ca6 77
shorie 1:98ddcbbe10ba 78 codec.set_hp_output_gain( -3, -3 );
shorie 1:98ddcbbe10ba 79 codec.set_line_output_gain( -3, -3 );
shorie 0:a837eeab3ca6 80
shorie 0:a837eeab3ca6 81 // periodically changing gain for test
shorie 0:a837eeab3ca6 82 while(1)
shorie 0:a837eeab3ca6 83 {
shorie 2:d5028a37f17b 84
shorie 2:d5028a37f17b 85 i2c.read( AD7999, adcbuf, ADCBUFSIZE);
shorie 2:d5028a37f17b 86 parse_adc( &adcbuf[0],dacch, dacdata );
shorie 2:d5028a37f17b 87 gain = dacdata / 255.0;
shorie 1:98ddcbbe10ba 88 /*
shorie 1:98ddcbbe10ba 89 myled1 = 1;
shorie 1:98ddcbbe10ba 90 wait(0.2);
shorie 1:98ddcbbe10ba 91 myled1 = 0;
shorie 1:98ddcbbe10ba 92 wait(0.2);
shorie 1:98ddcbbe10ba 93 */
shorie 0:a837eeab3ca6 94 }
shorie 2:d5028a37f17b 95 }
shorie 2:d5028a37f17b 96
shorie 2:d5028a37f17b 97 void parse_adc( char * buf, int &ch, int &data )
shorie 2:d5028a37f17b 98 {
shorie 2:d5028a37f17b 99 ch = ( buf[0] & 0x30 ) >> 4;
shorie 2:d5028a37f17b 100 data =
shorie 2:d5028a37f17b 101 ( buf[0] & 0x0F ) << 4 |
shorie 2:d5028a37f17b 102 ( buf[1] & 0xF0 ) >> 4;
shorie 2:d5028a37f17b 103
shorie 0:a837eeab3ca6 104 }