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

Revision:
3:6fba0a044d85
Parent:
2:05b426733282
Child:
4:1a9482a07ee2
--- a/wolfson_3_wav.cpp	Mon Oct 01 20:33:33 2018 +0000
+++ b/wolfson_3_wav.cpp	Sat Oct 06 11:34:37 2018 +0000
@@ -45,7 +45,12 @@
 int AudioFormat, NumChannels, SampleRate, BitsPerSample ; 
 char *slice_buf;
 int *data_sptr;
+unsigned char *data_bptr;
+int *data_wptr;
+unsigned channel;
 int newvar;
+long slice, num_slices;
+int verbosity = 0;
 //long long slice_value;
 int slice_value;
 FILE *my_wav;
@@ -61,13 +66,19 @@
 
 void isr()
 {
-
+    buffer[0] = (*data_sptr)>>1;
+    myled = 1;
+    int bufflen = sizeof(buffer);
+    //t.start();
     //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
+    i2s.write(buffer, bufflen);//Send next PWM value to amp
+    //t.stop();
+    //printf("The time taken was %f seconds\n", t.read());
+    myled = 0;
     }
 
     
@@ -281,7 +292,10 @@
     long j = 0;
     
     printf("set up the codec\n\r");
+    while(j <1000){
     wm8731_configTEST();
+    j = j + 1;
+    }
     //i2s audio data transfer code??
     i2s.stereomono(I2S_STEREO);
     i2s.masterslave(I2S_MASTER);//MASTER definitely works!
@@ -311,9 +325,10 @@
     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("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);
+    printf("do we egt to this point:\n\r");
+    sampletick.attach(&isr,1/96000);
     //while(!feof(my_wav)){
     //while(1){
         //if (wav_data.subchunk2_size > sizeof(wav_format)){
@@ -328,16 +343,16 @@
             break;
             }*/
             
-//    slice_buf=(char *)malloc(wav_format.block_align);
-
+    slice_buf=(char *)malloc(wav_format.block_align);
               for (slice=0;slice<num_slices;slice+=1) {
-          fread(slice_buf,wav_format.block_align,1,wavefile);//THIS IS WHERE HE READS IN THE DATA, TO SLICE_BUF.  BUT USES WAV_FORMAT.BLOCKALIGN AS HIS SIZE GUIDE
+                  //t.start();
+          fread(slice_buf,wav_format.block_align,1,my_wav);//THIS IS WHERE HE READS IN THE DATA, TO SLICE_BUF.  BUT USES WAV_FORMAT.BLOCKALIGN AS HIS SIZE GUIDE
           //I do not understand why he is not "seeking" through the file first though...
-          if (feof(wavefile)) {
+          if (feof(my_wav)){
             printf("Oops -- not enough slices in the wave file\n");
             exit(1);
           }
-          data_sptr=(short *)slice_buf;     // 16 bit samples
+          data_sptr=(int *)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;
@@ -373,32 +388,18 @@
                         slice_value+=32768;
                         break;
           }
-          dac_data=(short unsigned)slice_value;
+          //t.stop();
+          //printf("The time taken was %f seconds\n", t.read());
+    }
+ /*         dac_data=(short unsigned)slice_value;
           if (verbosity)
             printf("sample %d wptr %d slice_value %d dac_data %u\n",slice,DAC_wptr,(int)slice_value,dac_data);
           DAC_fifo[DAC_wptr]=dac_data;
           DAC_wptr=(DAC_wptr+1) & 0xff;
           while (DAC_wptr==DAC_rptr) {
           }
-        }
-        DAC_on=0;
-        tick.detach();
-        free(slice_buf);
-        break;
-      case 0x5453494c:
-        if (verbosity)
-          printf("INFO chunk, size %d\n",chunk_size);
-        fseek(wavefile,chunk_size,SEEK_CUR);
-        break;
-      default:
-        printf("unknown chunk type 0x%x, size %d\n",chunk_id,chunk_size);
-        data=fseek(wavefile,chunk_size,SEEK_CUR);
-        break;
-    }
-    fread(&chunk_id,4,1,wavefile);
-    fread(&chunk_size,4,1,wavefile);
-  }
-}
+        }*/
+
 
     
         sampletick.detach();