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:
Tue Oct 23 19:02:45 2018 +0000
Parent:
4:1a9482a07ee2
Child:
6:fd6ae534d120
Commit message:
chsnged to work with 8khz file (does not work yet)

Changed in this revision

I2S.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
wolfson_3_wav.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/I2S.lib	Sat Oct 06 11:51:23 2018 +0000
+++ b/I2S.lib	Tue Oct 23 19:02:45 2018 +0000
@@ -1,1 +1,1 @@
-http://os.mbed.com/users/p07gbar/code/I2S/#455d5826751b
+http://os.mbed.com/users/p07gbar/code/I2S/#9dd9537d8ab6
--- a/WOLFSON_config.h	Sat Oct 06 11:51:23 2018 +0000
+++ b/WOLFSON_config.h	Tue Oct 23 19:02:45 2018 +0000
@@ -27,11 +27,15 @@
 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_LEFT_HP            = 0X00E1;     // HEADPHONE SETTINGS : -6?DB
+//const int _WM8731_RIGHT_HP           = 0X00E1;     // HEADPHONE SETTINGS : -6?DB
 const int _WM8731_ANALOGAUDIO        = 0XD0;       // DAC SELECT
-const int _WM8731_DIGITALAUDIO       = 0X00;
+const int _WM8731_DIGITALAUDIO       = 0X00;        //11011
 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_SAMPLING           = 0X00;       // 48000HZ,12.288MHz oscillator.
+//const int _WM8731_SAMPLING           = 0X2E;       // 8000HZ,12.288MHz oscillator.
+const int _WM8731_SAMPLING           = 0X18;       // 8000HZ,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
--- a/wolfson_3_wav.cpp	Sat Oct 06 11:51:23 2018 +0000
+++ b/wolfson_3_wav.cpp	Tue Oct 23 19:02:45 2018 +0000
@@ -44,7 +44,7 @@
 int buffer[1];
 int AudioFormat, NumChannels, SampleRate, BitsPerSample ; 
 char *slice_buf;
-int *data_sptr;
+short *data_sptr;
 unsigned char *data_bptr;
 int *data_wptr;
 unsigned channel;
@@ -52,7 +52,7 @@
 long slice, num_slices;
 int verbosity = 0;
 //long long slice_value;
-int slice_value;
+int slice_value[1];
 FILE *my_wav;
 FMT_STRUCT wav_format;
 DATA_STRUCT wav_data;
@@ -69,8 +69,10 @@
     buffer[0] = (*data_sptr)>>1;
     myled = 1;
     int bufflen = sizeof(buffer);
+    if(verbosity){
     printf("buffer data:  %d \n\r",buffer);
     printf("data_sptr data:  %d \n\r",data_sptr);
+    }
     //t.start();
     //buffer[0] = (int*)data_sptr;
     //buffer[0] = newvar;
@@ -261,7 +263,10 @@
     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.    
+    //my_wav = fopen("/sd/mydir/gp40_48K.wav", "rb");//i think that it is "w" for write, "r"  for read.    
+    //my_wav = fopen("/sd/mydir/gp40_48K_quieter.wav", "rb");//i think that it is "w" for write, "r"  for read.    
+    my_wav = fopen("/sd/mydir/gp40_8K.wav","rb");
+    //my_wav = fopen("/sd/mydir/emd_645.wav", "rb");
     fseek(my_wav, 20, SEEK_SET); // set pointer to byte 20
     fread(&AudioFormat, 2, 1, my_wav); // check file is PCM
     if (AudioFormat==0x01) {
@@ -331,6 +336,7 @@
     printf("sizeof(wav_format): %d\n\r",sizeof(wav_format));
     printf("do we egt to this point:\n\r");
     //sampletick.attach(&isr,1/96000);
+    //sampletick.attach(&isr,1000000/48000);
     //while(!feof(my_wav)){
     //while(1){
         //if (wav_data.subchunk2_size > sizeof(wav_format)){
@@ -354,43 +360,53 @@
             printf("Oops -- not enough slices in the wave file\n");
             exit(1);
           }
-          data_sptr=(int *)slice_buf;     // 16 bit samples
+          data_sptr=(short *)slice_buf;     // 16 bit samples
           data_bptr=(unsigned char *)slice_buf;     // 8 bit samples
           data_wptr=(int *)slice_buf;     // 32 bit samples
-          slice_value=0;
+          slice_value[1]=0;
           for (channel=0;channel<wav_format.num_channels;channel++) {
             switch (wav_format.sig_bps) {
               case 16:
+                int mybuffer[1];
+                mybuffer[0] = data_sptr[channel];// - 32768;
+                i2s.write(data_sptr,2);
+                wait_us(0.1);
                 if (verbosity)
-                  printf("16 bit channel %d data=%d ",channel,data_sptr[channel]);
-                slice_value+=data_sptr[channel];
+                  printf("16 bit channel %d data=%d\n\r ",channel,data_sptr[channel]);
+                slice_value[1]+=data_sptr[channel];
                 break;
               case 32:
                 if (verbosity)
                   printf("32 bit channel %d data=%d ",channel,data_wptr[channel]);
-                slice_value+=data_wptr[channel];
+                slice_value[1]+=data_wptr[channel];
                 break;
               case 8:
                 if (verbosity)
                   printf("8 bit channel %d data=%d ",channel,(int)data_bptr[channel]);
-                slice_value+=data_bptr[channel];
+                slice_value[1]+=data_bptr[channel];
                 break;
             }
           }
-          slice_value/=wav_format.num_channels;
+          slice_value[1]/=wav_format.num_channels;
           
 // slice_value is now averaged.  Next it needs to be scaled to an unsigned 16 bit value
 // with DC offset so it can be written to the DAC.
           switch (wav_format.sig_bps) {
-            case 8:     slice_value<<=8;
+            case 8:     slice_value[1]<<=8;
                         break;
-            case 16:    slice_value+=32768;
+            case 16:    slice_value[1]+=32768;
                         break;
-            case 32:    slice_value>>=16;
-                        slice_value+=32768;
+            case 32:    slice_value[1]>>=16;
+                        slice_value[1]+=32768;
                         break;
           }
-          i2s.write(data_sptr,2);
+          if (verbosity)
+          {
+          printf("data_sptr data:  %d \n\r",data_sptr);
+          printf("slice_value data:  %d \n\r",slice_value);
+          }
+          int mynewvar[1];
+          //i2s.write(data_sptr,2);
           //t.stop();
           //printf("The time taken was %f seconds\n", t.read());
     }
@@ -405,7 +421,7 @@
 
 
     
-        sampletick.detach();
+        //sampletick.detach();
     i2s.stop();
     
     fclose(my_wav);