does not work yet. Sound starts but then stops after a few seconds, whole thing hangs. Published so as I can import through mbed CLI.

Dependencies:   mbed sinelookup SDFileSystem_Copy_of_mbed_version I2S

Files at this revision

API Documentation at this revision

Comitter:
roryhand
Date:
Mon Oct 01 18:58:35 2018 +0000
Child:
1:ec4e2020522c
Commit message:
current version does not print everything due to weird error

Changed in this revision

I2S.lib Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
WOLFSON_config.h Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
sinelookup.lib Show annotated file Show diff for this revision Revisions of this file
wolfson_3_wav.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/I2S.lib	Mon Oct 01 18:58:35 2018 +0000
@@ -0,0 +1,1 @@
+http://os.mbed.com/users/p07gbar/code/I2S/#455d5826751b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Mon Oct 01 18:58:35 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/SDFileSystem/#7ba9d50020de
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WOLFSON_config.h	Mon Oct 01 18:58:35 2018 +0000
@@ -0,0 +1,43 @@
+#ifndef WOLFSON_config
+#define WOLFSON_config
+// WM8731 Drivers - from MIKROE LIBSTOCK: https://libstock.mikroe.com/projects/view/304/wm8731-example
+/**************************************************************************************************
+* WM8731 sound chip register addresses
+**************************************************************************************************/
+const int WM8731_ADDRESS = 0x34;       // WM8731 chip address on I2C bus
+/**************************************************************************************************
+* WM8731 sound chip register addresses
+**************************************************************************************************/
+const int WM8731_REG_LLINE_IN        = 0x00;       // Left Channel Line Input Volume Control
+const int WM8731_REG_RLINE_IN        = 0x01;       // Right Channel Line Input Volume Control
+const int WM8731_REG_LHPHONE_OUT     = 0x02;       // Left Channel Headphone Output Volume Control
+const int WM8731_REG_RHPHONE_OUT     = 0x03;       // Right Channel Headphone Output Volume Control
+const int WM8731_REG_ANALOG_PATH     = 0x04;       // Analog Audio Path Control
+const int WM8731_REG_DIGITAL_PATH    = 0x05;       // Digital Audio Path Control
+const int WM8731_REG_PDOWN_CTRL      = 0x06;       // Power Down Control Register
+const int WM8731_REG_DIGITAL_IF      = 0x07;       // Digital Audio Interface Format
+const int WM8731_REG_SAMPLING_CTRL   = 0x08;       // Sampling Control Register
+const int WM8731_REG_ACTIVE_CTRL     = 0x09;       // Active Control
+const int WM8731_REG_RESET           = 0x0F;       // Reset register
+
+/**************************************************************************************************
+* WM8731 sound chip constants (for default set up)
+**************************************************************************************************/
+const int _WM8731_LEFT_LINEIN        = 0X0180;     // MIC SETTINGS: ENABLE MUTE, ENABLE SIMULTANEOUS LOAD TO LEFT AND RIGHT CHANNELS
+const int _WM8731_RIGHT_LINEIN       = 0X0180;     // MIC SETTINGS: ENABLE MUTE, ENABLE SIMULTANEOUS LOAD TO LEFT AND RIGHT CHANNELS
+const int _WM8731_LEFT_HP            = 0X00F9;     // HEADPHONE SETTINGS : 0DB
+const int _WM8731_RIGHT_HP           = 0X00F9;     // HEADPHONE SETTINGS : 0DB
+const int _WM8731_ANALOGAUDIO        = 0XD0;       // DAC SELECT
+const int _WM8731_DIGITALAUDIO       = 0X00;
+const int _WM8731_POWER              = 0X00;       // DISABLE POWER DOWN
+const int _WM8731_DAIF               = 0X02;       // ENABLE SLAVE MODE, 16BIT DATA AND I2S DATA
+const int _WM8731_SAMPLING           = 0X00;       // 48000HZ,12.288MHz oscillator.
+const int _WM8731_ACTIVATE           = 0X01;       // MODULE IS ON
+const int _WM8731_DEACTIVATE         = 0X00;       // MODULE IS OFF
+const int _WM8731_RESET              = 0X00;       // RESET VALUE
+
+//do I need to delete these highlighted ones? (ie unused ones?) I think maybe theyre duplicates
+/**************************************************************************************************/
+
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Oct 01 18:58:35 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/a7c7b631e539
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sinelookup.lib	Mon Oct 01 18:58:35 2018 +0000
@@ -0,0 +1,1 @@
+http://os.mbed.com/users/p07gbar/code/sinelookup/#9099a1ada151
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wolfson_3_wav.cpp	Mon Oct 01 18:58:35 2018 +0000
@@ -0,0 +1,772 @@
+
+//  24/03/2018  update - I appear to be able to address the device and write something, as I am getting an ACK returned from the i2c write() function.
+//however if i use the write function with 4 arguments (as opposed to just 1 argument) then it doesnt work
+//only works with the 1 argument version!!!
+
+
+//THIS VERSION WORKED, CHANGED SOME THINGS, THEN CHANGED THEM BACK.  NOW IT NO LONGER WORKS!!!!
+#include "mbed.h"
+#include "sinelookup.h" 
+#include "I2S.h"   
+#define sample_freq 48000
+DigitalOut myled(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+Ticker sampletick;
+Timer t;
+#include "SDFileSystem.h"     
+#include "WOLFSON_config.h"  
+Serial pc(USBTX, USBRX); // tx, rx //FOR DEBUGGING PROGRAM USING GNU SCREEN
+DigitalOut cs(p8);
+I2S i2s(I2S_TRANSMIT,p5,p6,p7);
+I2C i2c(p9, p10);
+ 
+SDFileSystem sd(p11, p12, p13, p8, "sd"); // the new pinout that i am using
+
+typedef struct uFMT_STRUCT{
+  short comp_code;
+  short num_channels;
+  unsigned sample_rate;
+  unsigned avg_Bps;
+  short block_align;
+  short sig_bps;
+} FMT_STRUCT;
+
+typedef struct uDATA_STRUCT {
+  unsigned subchunk2_ID;
+  unsigned subchunk2_size;
+  char * data_buf;
+}DATA_STRUCT;
+short hello;
+int i = 0;
+int h = 0;
+int bufflen = 1;
+int buffer[1];
+int AudioFormat, NumChannels, SampleRate, BitsPerSample ; 
+char *slice_buf;
+int *data_sptr;
+int newvar;
+//long long slice_value;
+int slice_value;
+FILE *my_wav;
+FMT_STRUCT wav_format;
+DATA_STRUCT wav_data;
+
+Ticker flipper;
+//test
+void flip() {
+    led2  = !led2;
+}
+
+
+void isr()
+{
+
+    //buffer[0] = (int*)data_sptr;
+    //buffer[0] = newvar;
+    //buffer[0] = sine16lookup[i];//>>1;//sine16lookup[i];//scale down volume a bit on amp//how would this scale down the volume a bit??
+    //buffer[0] = *fp;
+    //printf("value: %d",data_sptr);
+    //i2s.write(buffer, 2);//Send next PWM value to amp
+    }
+    //i++;
+    //int hi =i2s.read(buffer[0], bufflen);
+    //i2s.stop();
+    //pc.printf("%d", buffer[0]);
+    
+    //pc.printf("Playing Sound!!\n");//0  = ack, 1 = Nack
+    //if (i>= SINE16LENGTH) {//SINE16LENGTH) {
+    /*if (i>= wav_format.block_align){
+        i = 0;
+        i2s.stop();
+        sampletick.detach();
+    
+        //pc.printf("Sound ended!!");
+        myled = 0;
+        CE
+    }
+    
+}*/
+
+void wm8731_setup(int chip_addr, int addr, int cmd){
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 ))& 0x01;//mess around with order of operations
+    cmd = cmd&0xFF;
+    i2c.start();
+    i2c.write( chip_addr );
+    i2c.write( addr  );
+    i2c.write( cmd );
+    i2c.stop(); 
+    }
+    
+
+void wm8731_config(void){
+    wm8731_setup( WM8731_ADDRESS, WM8731_REG_RESET, _WM8731_RESET );//1
+    wm8731_setup( WM8731_ADDRESS, WM8731_REG_LLINE_IN, _WM8731_LEFT_LINEIN );//2
+    wm8731_setup( WM8731_ADDRESS, WM8731_REG_RLINE_IN, _WM8731_RIGHT_LINEIN );//3
+    wm8731_setup( WM8731_ADDRESS, WM8731_REG_LHPHONE_OUT, _WM8731_LEFT_HP );//4 
+    wm8731_setup( WM8731_ADDRESS, WM8731_REG_RHPHONE_OUT, _WM8731_RIGHT_HP );//5   
+    wm8731_setup( WM8731_ADDRESS, WM8731_REG_ANALOG_PATH, _WM8731_ANALOGAUDIO );//6   
+    wm8731_setup( WM8731_ADDRESS, WM8731_REG_DIGITAL_PATH, _WM8731_DIGITALAUDIO );//7   
+    wm8731_setup( WM8731_ADDRESS, WM8731_REG_PDOWN_CTRL, _WM8731_POWER );//8   
+    wm8731_setup( WM8731_ADDRESS, WM8731_REG_DIGITAL_IF, _WM8731_DAIF );//9   
+    wm8731_setup( WM8731_ADDRESS, WM8731_REG_SAMPLING_CTRL, _WM8731_SAMPLING );//10
+    }    
+    
+void wm8731_configTEST(void){
+    int addr = WM8731_REG_RESET;
+    int cmd = _WM8731_RESET;
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 ))& 0x01;//mess around with order of operations
+    cmd = cmd&0xFF;
+    i2c.start();
+    i2c.write( WM8731_ADDRESS );
+    i2c.write( addr  );
+    i2c.write( cmd );
+    i2c.stop();
+
+    addr = WM8731_REG_LLINE_IN;
+    cmd = _WM8731_LEFT_LINEIN;
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 )) & 0x01;
+    cmd = cmd&0xFF;
+    i2c.start();
+    i2c.write( WM8731_ADDRESS );//take Fergus' suggestion and declare these to known values EARLIER in program
+    i2c.write( addr );
+    i2c.write( cmd );
+    i2c.stop();
+    
+    
+    addr = WM8731_REG_RLINE_IN;
+    cmd = _WM8731_RIGHT_LINEIN;
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 )) & 0x01;
+    cmd = cmd&0xFF;
+    i2c.start();
+    i2c.write( WM8731_ADDRESS );//take Fergus' suggestion and declare these to known values EARLIER in program
+    i2c.write( addr );
+    i2c.write( cmd );
+    i2c.stop();
+    
+       
+    //4
+    addr = WM8731_REG_LHPHONE_OUT;
+    cmd = _WM8731_LEFT_HP;
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 )) & 0x01;
+    cmd = cmd&0xFF;
+    i2c.start();
+    i2c.write( WM8731_ADDRESS );
+    i2c.write( addr );//WM8731_REG_LHPHONE_OUT, _WM8731_LEFT_HP   
+    i2c.write(cmd);   
+    i2c.stop();
+      
+    //5
+    addr = WM8731_REG_RHPHONE_OUT;
+    cmd = _WM8731_RIGHT_HP;
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 )) & 0x01;
+    cmd = cmd&0xFF;
+    i2c.start();
+    i2c.write( WM8731_ADDRESS );//WM8731_REG_RHPHONE_OUT, _WM8731_RIGHT_HP 
+    i2c.write( addr );
+    i2c.write( cmd );
+    i2c.stop();
+  
+    
+    //6
+    addr = WM8731_REG_ANALOG_PATH;
+    cmd = _WM8731_ANALOGAUDIO;
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 )) & 0x01;
+    cmd = cmd&0xFF;
+    i2c.start();
+    i2c.write( WM8731_ADDRESS );//WM8731_REG_ANALOG_PATH, _WM8731_ANALOGAUDIO
+    i2c.write( addr );
+    i2c.write( cmd );
+    i2c.stop();
+    
+    //7
+    addr = WM8731_REG_DIGITAL_PATH;
+    cmd = _WM8731_DIGITALAUDIO;
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 )) & 0x01;
+    cmd = cmd&0xFF;
+    i2c.start();
+    i2c.write( WM8731_ADDRESS );//WM8731_REG_DIGITAL_PATH, _WM8731_DIGITALAUDIO
+    i2c.write( addr  );
+    i2c.write( cmd );
+    i2c.stop();
+    
+    //8
+    addr = WM8731_REG_PDOWN_CTRL;
+    cmd = _WM8731_POWER;
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 )) & 0x01;
+    cmd = cmd&0xFF;
+    i2c.start();
+    i2c.write( WM8731_ADDRESS );//WM8731_REG_PDOWN_CTRL, _WM8731_POWER)
+    i2c.write( addr  );
+    i2c.write( cmd );
+    i2c.stop();
+    
+    
+    //9
+    addr = WM8731_REG_DIGITAL_IF;
+    cmd = _WM8731_DAIF;
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 )) & 0x01;
+    cmd = cmd&0xFF;
+    i2c.start();
+    i2c.write( WM8731_ADDRESS );
+    i2c.write( addr  );//WM8731_REG_DIGITAL_IF, _WM8731_DAIF
+    i2c.write( cmd );
+    i2c.stop();
+
+   
+    //10
+    addr = WM8731_REG_SAMPLING_CTRL;
+    cmd = _WM8731_SAMPLING;
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 )) & 0x01;
+    cmd = cmd&0xFF;
+    i2c.start();
+    i2c.write( WM8731_ADDRESS );//WM8731_REG_SAMPLING_CTRL, _WM8731_SAMPLING
+    i2c.write( addr  );
+    i2c.write( cmd );
+    i2c.stop();
+    
+    
+   
+    
+    //11
+    addr = WM8731_REG_ACTIVE_CTRL;
+    cmd = _WM8731_ACTIVATE;
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 )) & 0x01;
+    cmd = cmd&0xFF;    
+    i2c.start();
+    i2c.write( WM8731_ADDRESS );//WM8731_REG_SAMPLING_CTRL, _WM8731_SAMPLING
+    i2c.write( addr  );
+    i2c.write( cmd );//there is also a deactive version!!
+    i2c.stop();
+    
+    
+    
+    }
+
+int main() {
+    FMT_STRUCT wav_format;
+    char data[2];
+    pc.printf("Beginning of program\n");
+    data[0] = 0x0F;
+    data[1] = 0x00;
+    FILE *my_wav;
+    //my_wav = fopen("/sd/mydir/gp40.wav", "rb");//i think that it is "w" for write, "r"  for read.    
+    my_wav = fopen("/sd/mydir/gp40_48K.wav", "rb");//i think that it is "w" for write, "r"  for read.    
+    fseek(my_wav, 20, SEEK_SET); // set pointer to byte 20
+    fread(&AudioFormat, 2, 1, my_wav); // check file is PCM
+    if (AudioFormat==0x01) {
+    printf("Wav file is PCM data\n\r");
+    }
+    else {
+    printf("Wav file is not PCM data\n\r");
+    }
+    
+    fseek  (my_wav,20,SEEK_SET);
+    fread(&wav_format,sizeof(wav_format),1,my_wav);
+    printf("%d  block align\n",wav_format.block_align);
+    printf("  %d channels\n",wav_format.num_channels);
+    
+    
+    fseek(my_wav, 36, SEEK_SET);
+    fread(&wav_data.subchunk2_ID,4,1,my_wav);
+    fseek(my_wav, 40, SEEK_SET);
+    fread(&wav_data.subchunk2_size,4,1,my_wav);
+    printf("DATA chunck\n");
+    printf("  %d subchunk 2 ID\n",wav_data.subchunk2_ID);
+    printf("  %d subchunk 2 size\n",wav_data.subchunk2_size);
+    
+    
+    fseek(my_wav,36,SEEK_SET);
+    fread(&wav_format.sig_bps,2,1,my_wav);
+    printf("%d bits per sample\n",wav_format.sig_bps);//check how many bits per sample we have
+    
+    
+    
+
+    
+
+
+    i2c.frequency(100000);
+    long j = 0;
+    /*while(j<1000){
+        j=j+1;
+    wm8731_configTEST();
+    }*/
+    
+        /*while(j<1000){
+        j=j+1;
+    int addr = WM8731_REG_RESET;
+    int cmd = _WM8731_RESET;
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 ))& 0x01;//mess around with order of operations
+    cmd = cmd&0xFF;
+    i2c.start();
+    i2c.write( WM8731_ADDRESS );
+    i2c.write( addr  );
+    i2c.write( cmd );
+    //wait(1);
+    i2c.stop();
+    //}//am receiving ack = 0 i.e. an anknowledgment!!! when I loop round this section. 14/06/18
+    //}
+    //i2c.stop();
+    //while(1){}
+    //wait(3);
+    ///try not using the int ack stuff
+    
+    //pc.printf("Decimals1: %d", ack1);//0  = ack, 1 = Nack
+    //int ack12 = 
+    //pc.printf("Decimals12: %d", ack12);//0  = ack, 1 = Nack
+    //int ack13 = i2c.write( cmd );
+    //pc.printf("Decimals13: %d", ack13);//0  = ack, 1 = Nack
+    //i2c.stop();
+    
+    //2
+          
+    //while(1){
+     //   }
+    
+    
+    //while(1){
+    addr = WM8731_REG_LLINE_IN;
+    cmd = _WM8731_LEFT_LINEIN;
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 )) & 0x01;
+    cmd = cmd&0xFF;
+    i2c.start();
+    i2c.write( WM8731_ADDRESS );//take Fergus' suggestion and declare these to known values EARLIER in program
+    i2c.write( addr );
+    i2c.write( cmd );
+    i2c.stop();
+    
+    
+        addr = WM8731_REG_RLINE_IN;
+    cmd = _WM8731_RIGHT_LINEIN;
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 )) & 0x01;
+    cmd = cmd&0xFF;
+    i2c.start();
+    i2c.write( WM8731_ADDRESS );//take Fergus' suggestion and declare these to known values EARLIER in program
+    i2c.write( addr );
+    i2c.write( cmd );
+    i2c.stop();
+    
+       
+    //4
+    addr = WM8731_REG_LHPHONE_OUT;
+    cmd = _WM8731_LEFT_HP;
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 )) & 0x01;
+    cmd = cmd&0xFF;
+    i2c.start();
+    i2c.write( WM8731_ADDRESS );
+    i2c.write( addr );//WM8731_REG_LHPHONE_OUT, _WM8731_LEFT_HP   
+    i2c.write(cmd);   
+    i2c.stop();
+      
+    //5
+    addr = WM8731_REG_RHPHONE_OUT;
+    cmd = _WM8731_RIGHT_HP;
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 )) & 0x01;
+    cmd = cmd&0xFF;
+    i2c.start();
+    i2c.write( WM8731_ADDRESS );//WM8731_REG_RHPHONE_OUT, _WM8731_RIGHT_HP 
+    i2c.write( addr );
+    i2c.write( cmd );
+    i2c.stop();
+  
+    
+    //6
+    addr = WM8731_REG_ANALOG_PATH;
+    cmd = _WM8731_ANALOGAUDIO;
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 )) & 0x01;
+    cmd = cmd&0xFF;
+    i2c.start();
+    i2c.write( WM8731_ADDRESS );//WM8731_REG_ANALOG_PATH, _WM8731_ANALOGAUDIO
+    i2c.write( addr );
+    i2c.write( cmd );
+    i2c.stop();
+    
+    //7
+    addr = WM8731_REG_DIGITAL_PATH;
+    cmd = _WM8731_DIGITALAUDIO;
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 )) & 0x01;
+    cmd = cmd&0xFF;
+    i2c.start();
+    i2c.write( WM8731_ADDRESS );//WM8731_REG_DIGITAL_PATH, _WM8731_DIGITALAUDIO
+    i2c.write( addr  );
+    i2c.write( cmd );
+    i2c.stop();
+    
+    //8
+    addr = WM8731_REG_PDOWN_CTRL;
+    cmd = _WM8731_POWER;
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 )) & 0x01;
+    cmd = cmd&0xFF;
+    i2c.start();
+    i2c.write( WM8731_ADDRESS );//WM8731_REG_PDOWN_CTRL, _WM8731_POWER)
+    i2c.write( addr  );
+    i2c.write( cmd );
+    i2c.stop();
+    
+    
+    //9
+    addr = WM8731_REG_DIGITAL_IF;
+    cmd = _WM8731_DAIF;
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 )) & 0x01;
+    cmd = cmd&0xFF;
+    i2c.start();
+    i2c.write( WM8731_ADDRESS );
+    i2c.write( addr  );//WM8731_REG_DIGITAL_IF, _WM8731_DAIF
+    i2c.write( cmd );
+    i2c.stop();
+
+   
+    //10
+    addr = WM8731_REG_SAMPLING_CTRL;
+    cmd = _WM8731_SAMPLING;
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 )) & 0x01;
+    cmd = cmd&0xFF;
+    i2c.start();
+    i2c.write( WM8731_ADDRESS );//WM8731_REG_SAMPLING_CTRL, _WM8731_SAMPLING
+    i2c.write( addr  );
+    i2c.write( cmd );
+    i2c.stop();
+    
+    
+   
+    
+    //11
+    addr = WM8731_REG_ACTIVE_CTRL;
+    cmd = _WM8731_ACTIVATE;
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 )) & 0x01;
+    cmd = cmd&0xFF;    
+    i2c.start();
+    i2c.write( WM8731_ADDRESS );//WM8731_REG_SAMPLING_CTRL, _WM8731_SAMPLING
+    i2c.write( addr  );
+    i2c.write( cmd );//there is also a deactive version!!
+    /*(from data sheet) - To prevent any comms problems from arising across te DAI the audio interface (AI) is disabled
+    (tristate with weak 100k pulldown).  ONce the audio interface and the sampling scontrol has been programmed its 
+    activated by setting the ACTIVE bit under software control.*/
+    //i2c.stop();
+    //}
+    printf("set up the codec\n\r");
+    wm8731_configTEST();
+    //i2s audio data transfer code??
+    i2s.stereomono(I2S_STEREO);
+    i2s.masterslave(I2S_MASTER);//MASTER definitely works!
+    i2s.frequency(sample_freq);
+    int yes = i2s.setup_ok();
+    pc.printf("Setup went ok?: %d\n", yes);//0  = ack, 1 = Nack*/
+    printf("can we get to this point?   1\n\r");
+    led3 = 1;
+    //myled = 1;
+    led2 = 1;
+    printf("can we get to this point?   2\n\r");
+
+    /*fseek(my_wav, 40, SEEK_SET);
+    fread(&wav_data.subchunk2_size,4,1,my_wav);
+    printf("subchunk2 size: %d",wav_data.subchunk2_size);*/
+    int num_slices = wav_data.subchunk2_size/wav_format.block_align;
+    printf("block align is:%d\n\r",wav_format.block_align);
+    int a = 44;
+    //sampletick.attach(&isr,1.0/sample_freq);
+
+    myled = 1;
+    i2s.start();
+    //while (1) {
+    fread(&wav_format,sizeof(wav_format),1,my_wav);
+    printf("wav_format %d\n\r",wav_format);
+    //sampletick.attach(&isr,1/96000);
+    /*if (wav_data.subchunk2_size > sizeof(wav_format)){
+          fseek(my_wav,wav_data.subchunk2_size-sizeof(wav_format),SEEK_CUR);
+          printf("chunk_size - sizeof(wav_format) %d",wav_data.subchunk2_size-sizeof(wav_format));
+        }
+        else {
+            
+            break;
+            }*/
+            
+    fseek(my_wav,20,SEEK_SET);
+    fread(&wav_format,sizeof(wav_format),1,my_wav);
+    fseek(my_wav,36,SEEK_SET);
+    fread(&wav_data,sizeof(wav_data),1,my_wav);
+    num_slices = wav_data.subchunk2_size/wav_format.block_align;
+    printf("wav_data.subchunk2_size: %d\n\r",wav_data.subchunk2_size);
+    printf("wav_format.block_align: %d\n\r",wav_format.block_align);
+    printf("num_slices: %d\n\r",num_slices);
+    printf("num_slices*wav_format.block_align %d\n\r",num_slices*wav_format.block_align);
+    printf("wav_format.num_channels*wav_format.sig_bps/8: %d\n\r",wav_format.num_channels*wav_format.sig_bps/8);
+              printf("chunk_size - sizeof(wav_format) %d\n\r",wav_data.subchunk2_size-sizeof(wav_format));
+    printf("sizeof(wav_format): %d\n\r",sizeof(wav_format));
+    //sampletick.attach(&isr,1/96000);
+    //while(!feof(my_wav)){
+    //while(1){
+        //if (wav_data.subchunk2_size > sizeof(wav_format)){
+          //fseek(my_wav,wav_data.subchunk2_size-sizeof(wav_format),SEEK_CUR);
+        /*if(wav_data.subchunk2_size > (num_slices*wav_format.block_align)){
+          fseek(my_wav,wav_data.subchunk2_size - (num_slices*wav_format.block_align),SEEK_CUR);
+          printf("chunk_size - sizeof(wav_format) %d\n\r",wav_data.subchunk2_size-sizeof(wav_format));
+          printf("sizeof(wav_format): %d\n\r",sizeof(wav_format));
+        }
+        else {
+            
+            break;
+            }*/
+            
+    slice_buf=(char *)malloc(wav_format.block_align);
+    for(int slice = 0; slice<num_slices; slice+=1)
+    {       
+        //printf("slice: %d\n\r",slice);
+      fread(&slice_buf,wav_format.block_align,1,my_wav);
+      //int filePositionIndicator=ftell(my_wav);
+      //printf("filePositionIndicator: %d\n\r",filePositionIndicator);
+      //printf("slice: %d\n\r",slice);
+      //printf("num_slices: %d\n\r",num_slices);
+      data_sptr=(int *)slice_buf;  
+      //printf("data_sptr:%d\n\r",data_sptr);
+      //printf("wav_format.num_channels: %d\n\r",wav_format.num_channels);
+      //}
+      slice_value = 0;
+
+                //for (int channel=0;channel<wav_format.num_channels;channel++) 
+               // {
+                    int channel = 0;
+                    //printf("channel: %d\n\r",channel);
+                    //printf("wav_format.num_channels: %d\n\r",wav_format.num_channels);
+                    int var = 1;//data_sptr[channel];
+                    printf("var: %d\n\r", var);
+                    //slice_value+=data_sptr[channel];
+                    //printf("slice_value %d\n\r",slice_value);
+                    //printf("data_sptr[channel] %d\n\r",data_sptr[channel] );
+                    //slice_value = 21;//
+                    //malloc(sizeof(data_sptr[channel]));
+                    //printf("SIZEOF DATASPTR %d:\n\r",sizeof(data_sptr[channel]));
+                    //newvar = data_sptr[channel];
+                    //printf("newvar %d\n\r",newvar);
+                    channel = channel + 1;
+                    newvar = data_sptr[channel];
+                    //printf("newvar %d\n\r",newvar);
+                    //printf("channel: %d\n\r",channel);
+                    //slice_value+=data_sptr[channel];
+                  
+                    //printf("did it get to this point\n\r");
+                
+                
+                //printf("channel: %d  data %d\n\r",channel,data_sptr[channel]);
+                //printf("slice_value: %d\n\r",slice_value);
+                //}
+      
+     }
+      
+      
+      
+      //a = a + wav_format.block_align;
+    //} 
+//}
+    //}
+        sampletick.detach();
+    i2s.stop();
+    
+    fclose(my_wav);
+    printf("File is now closed.");
+    return 0;
+    }
+    /*while(1){
+    sampletick.attach(&isr,1.0/sample_freq);
+    led3 = !led3;
+    wait(1.0);
+    
+    //COMMENTS BELOW ARE OUT OF DATE
+    //The code above is IDENTICAL!!! to code run in TickerHello World.
+    //However, the 2nd led doesn't even light up and start "flipping" until led 1 has flipped....
+    //Looks as if it cannot attach.
+    //sampletick.attach_us(&isr, 20.833);//try using attach_us instead.
+    //Not sure why the osther guy just didn't use this in the first place
+    //sampletick.attach(&isr,1/sample_freq);
+    //if myled is assigned AFTER the tick is attached, it never switches on if sound does not come on.
+    }
+    //sampletick.attach(&isr, 2.0);
+    }
+    */
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    //old LEGACY code!!!
+    /*int addr = WM8731_REG_RESET;
+    int cmd = _WM8731_RESET;
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 ))& 0x01;//mess around with order of operations
+    cmd = cmd&0xFF;
+    i2c.start();
+    i2c.write( WM8731_ADDRESS );
+    i2c.write( addr  );
+    i2c.write( cmd );
+    i2c.stop();
+
+    addr = WM8731_REG_LLINE_IN;
+    cmd = _WM8731_LEFT_LINEIN;
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 )) & 0x01;
+    cmd = cmd&0xFF;
+    i2c.start();
+    i2c.write( WM8731_ADDRESS );//take Fergus' suggestion and declare these to known values EARLIER in program
+    i2c.write( addr );
+    i2c.write( cmd );
+    i2c.stop();
+    
+    
+    addr = WM8731_REG_RLINE_IN;
+    cmd = _WM8731_RIGHT_LINEIN;
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 )) & 0x01;
+    cmd = cmd&0xFF;
+    i2c.start();
+    i2c.write( WM8731_ADDRESS );//take Fergus' suggestion and declare these to known values EARLIER in program
+    i2c.write( addr );
+    i2c.write( cmd );
+    i2c.stop();
+    
+       
+    //4
+    addr = WM8731_REG_LHPHONE_OUT;
+    cmd = _WM8731_LEFT_HP;
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 )) & 0x01;
+    cmd = cmd&0xFF;
+    i2c.start();
+    i2c.write( WM8731_ADDRESS );
+    i2c.write( addr );//WM8731_REG_LHPHONE_OUT, _WM8731_LEFT_HP   
+    i2c.write(cmd);   
+    i2c.stop();
+      
+    //5
+    addr = WM8731_REG_RHPHONE_OUT;
+    cmd = _WM8731_RIGHT_HP;
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 )) & 0x01;
+    cmd = cmd&0xFF;
+    i2c.start();
+    i2c.write( WM8731_ADDRESS );//WM8731_REG_RHPHONE_OUT, _WM8731_RIGHT_HP 
+    i2c.write( addr );
+    i2c.write( cmd );
+    i2c.stop();
+  
+    
+    //6
+    addr = WM8731_REG_ANALOG_PATH;
+    cmd = _WM8731_ANALOGAUDIO;
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 )) & 0x01;
+    cmd = cmd&0xFF;
+    i2c.start();
+    i2c.write( WM8731_ADDRESS );//WM8731_REG_ANALOG_PATH, _WM8731_ANALOGAUDIO
+    i2c.write( addr );
+    i2c.write( cmd );
+    i2c.stop();
+    
+    //7
+    addr = WM8731_REG_DIGITAL_PATH;
+    cmd = _WM8731_DIGITALAUDIO;
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 )) & 0x01;
+    cmd = cmd&0xFF;
+    i2c.start();
+    i2c.write( WM8731_ADDRESS );//WM8731_REG_DIGITAL_PATH, _WM8731_DIGITALAUDIO
+    i2c.write( addr  );
+    i2c.write( cmd );
+    i2c.stop();
+    
+    //8
+    addr = WM8731_REG_PDOWN_CTRL;
+    cmd = _WM8731_POWER;
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 )) & 0x01;
+    cmd = cmd&0xFF;
+    i2c.start();
+    i2c.write( WM8731_ADDRESS );//WM8731_REG_PDOWN_CTRL, _WM8731_POWER)
+    i2c.write( addr  );
+    i2c.write( cmd );
+    i2c.stop();
+    
+    
+    //9
+    addr = WM8731_REG_DIGITAL_IF;
+    cmd = _WM8731_DAIF;
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 )) & 0x01;
+    cmd = cmd&0xFF;
+    i2c.start();
+    i2c.write( WM8731_ADDRESS );
+    i2c.write( addr  );//WM8731_REG_DIGITAL_IF, _WM8731_DAIF
+    i2c.write( cmd );
+    i2c.stop();
+
+   
+    //10
+    addr = WM8731_REG_SAMPLING_CTRL;
+    cmd = _WM8731_SAMPLING;
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 )) & 0x01;
+    cmd = cmd&0xFF;
+    i2c.start();
+    i2c.write( WM8731_ADDRESS );//WM8731_REG_SAMPLING_CTRL, _WM8731_SAMPLING
+    i2c.write( addr  );
+    i2c.write( cmd );
+    i2c.stop();
+    
+    
+   
+    
+    //11
+    addr = WM8731_REG_ACTIVE_CTRL;
+    cmd = _WM8731_ACTIVATE;
+    addr = addr << 1;
+    addr = addr|((cmd >> 8 )) & 0x01;
+    cmd = cmd&0xFF;    
+    i2c.start();
+    i2c.write( WM8731_ADDRESS );//WM8731_REG_SAMPLING_CTRL, _WM8731_SAMPLING
+    i2c.write( addr  );
+    i2c.write( cmd );//there is also a deactive version!!
+    i2c.stop();*/
+
+    
\ No newline at end of file