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を基本にしています。

Revision:
2:d5028a37f17b
Parent:
1:98ddcbbe10ba
Child:
3:1b420050bdda
--- a/main.cpp	Sun Dec 11 21:05:20 2016 +0000
+++ b/main.cpp	Mon Jan 02 11:05:36 2017 +0000
@@ -6,10 +6,15 @@
 #include "amakusa.h"   // audio signal processing class library.
  
 #define CODEC_I2C_ADDR 0x38 // Address of the ADAU-1361A
- 
+#define AD7999 (0x29<<1)   
+#define ADCBUFSIZE 8
+
 DigitalOut myled1(LED1);
+float gain = 1.0;
  
 amakusa::OSCSinCos osc( 440.0, 48000 );    // freq=440Hz, Fs=48kHz.
+
+void parse_adc( char * buf, int &ch, int &data );
  
    // customer signal processing initialization call back.
 void init_callback(
@@ -35,7 +40,7 @@
         // 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;
+       tx_right_buffer[i] = tx_left_buffer[i] *= 0.5F * gain;
        
    }
 }
@@ -44,6 +49,9 @@
  
 int main() 
 {    
+    char adcbuf[ADCBUFSIZE];
+    int dacch, dacdata;
+
        // I2C is essential to talk with ADAU1361
    I2C i2c(D14, D15);
  
@@ -73,6 +81,10 @@
        // periodically changing gain for test
    while(1)     
    {
+       
+        i2c.read( AD7999, adcbuf, ADCBUFSIZE);       
+        parse_adc( &adcbuf[0],dacch, dacdata );
+        gain = dacdata / 255.0;
        /*
        myled1 = 1;
        wait(0.2);
@@ -80,4 +92,13 @@
        wait(0.2);
        */
    }
+}
+
+void parse_adc( char * buf, int &ch, int &data )
+{
+    ch = ( buf[0] & 0x30 ) >> 4;
+    data = 
+        ( buf[0] & 0x0F ) << 4 |
+        ( buf[1] & 0xF0 ) >> 4;
+    
 }
\ No newline at end of file