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
Diff: wolfson_3_wav.cpp
- Revision:
- 6:fd6ae534d120
- Parent:
- 5:5b120a2d9249
- Child:
- 7:fb47ff047ac7
--- a/wolfson_3_wav.cpp Tue Oct 23 19:02:45 2018 +0000
+++ b/wolfson_3_wav.cpp Sun Oct 28 16:44:14 2018 +0000
@@ -14,6 +14,7 @@
DigitalOut led3(LED3);
Ticker sampletick;
Timer t;
+Timer t2;
#include "SDFileSystem.h"
#include "WOLFSON_config.h"
Serial pc(USBTX, USBRX); // tx, rx //FOR DEBUGGING PROGRAM USING GNU SCREEN
@@ -51,6 +52,12 @@
int newvar;
long slice, num_slices;
int verbosity = 0;
+int interrupt_condition = 0;
+int sampling_freq = 48000;
+int Buffer1[512];
+int Buffer2[512];
+int place_hold1;
+int place_hold2;
//long long slice_value;
int slice_value[1];
FILE *my_wav;
@@ -73,15 +80,17 @@
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;
//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);
+ t.start();
i2s.write(data_sptr, bufflen);//Send next PWM value to amp
- //t.stop();
- //printf("The time taken was %f seconds\n", t.read());
+ t.stop();
+ printf("The time taken was %f seconds\n", t.read());
+ t.reset();
myled = 0;
}
@@ -335,7 +344,11 @@
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));
printf("do we egt to this point:\n\r");
- //sampletick.attach(&isr,1/96000);
+ if (interrupt_condition == 1)
+ {
+ sampletick.attach(&isr,10.0);
+ }
+
//sampletick.attach(&isr,1000000/48000);
//while(!feof(my_wav)){
//while(1){
@@ -353,7 +366,7 @@
slice_buf=(char *)malloc(wav_format.block_align);
for (slice=0;slice<num_slices;slice+=1) {
- //t.start();
+ t2.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(my_wav)){
@@ -369,8 +382,43 @@
case 16:
int mybuffer[1];
mybuffer[0] = data_sptr[channel];// - 32768;
- i2s.write(data_sptr,2);
- wait_us(0.1);
+ if(interrupt_condition==1)
+ {
+
+
+ }
+ else
+ {
+ if(verbosity == 1)
+ {
+ t.start();
+ i2s.write(data_sptr,2);
+ t.stop();
+ printf("The time taken was %f seconds\n", t.read());
+ t.reset();
+ }
+
+ else
+ {
+
+ i2s.write(data_sptr,2);
+
+ }
+
+ if(sampling_freq == 48000)
+ {
+ wait_us(0.1);
+ }
+ else if(sampling_freq == 8000)
+ {
+ wait_us(2);
+ }
+ }
+
+
+
+
+
if (verbosity)
printf("16 bit channel %d data=%d\n\r ",channel,data_sptr[channel]);
slice_value[1]+=data_sptr[channel];
@@ -407,8 +455,9 @@
}
int mynewvar[1];
//i2s.write(data_sptr,2);
- //t.stop();
- //printf("The time taken was %f seconds\n", t.read());
+ t2.stop();
+ printf("The time taken was %f seconds\n", t2.read());
+ t2.reset();
}
/* dac_data=(short unsigned)slice_value;
if (verbosity)
@@ -420,8 +469,12 @@
}*/
-
- //sampletick.detach();
+ if(interrupt_condition == 1)
+ {
+
+ sampletick.detach();
+ }
+
i2s.stop();
fclose(my_wav);