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:
- 9:4d6b9a554550
- Parent:
- 8:40f37287589a
--- a/wolfson_3_wav.cpp Sun Oct 28 22:01:16 2018 +0000 +++ b/wolfson_3_wav.cpp Sun Nov 25 16:41:04 2018 +0000 @@ -8,7 +8,7 @@ #include "mbed.h" #include "sinelookup.h" #include "I2S.h" -#define sample_freq 8000 +#define sample_freq 32000 DigitalOut myled(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); @@ -53,8 +53,9 @@ long slice, num_slices; int verbosity = 0; int verbosity2 = 0; +int verbosity3 = 0; int interrupt_condition = 1; -int sampling_freq = 8000; +int sampling_freq = 32000; short Buffer1[8]; short Buffer2[8]; short place_hold1 = 0; @@ -90,9 +91,7 @@ } //t.start(); - //t.stop(); - //printf("The time taken was %f seconds\n", t.read()); - //t.reset(); + //myled = 0; if(flag1 == 0) { @@ -102,6 +101,10 @@ place_hold1 = place_hold1 + 1; if(place_hold1 == 8) { + if(verbosity3 == 1) + { + printf("value flag1: %d\n\r",flag1); + } place_hold1 = 0; place_hold2 = 0; flag1 = 1; @@ -110,17 +113,24 @@ } if(verbosity2 == 1) { - printf("value Buffer1: %d\n\r",value[0]); + //printf("value Buffer1: %d\n\r",value[0]); + printf("value placehold1: %d\n\r",place_hold1); } } else if(flag2 == 0) { //access double buffer pt2 - value[0] = Buffer1[place_hold2]; + value[0] = Buffer2[place_hold2];//just chsnged this from BUFFER1. + //so perhaps we wont be trying to access the same thing and therefore crashing. i2s.write(value,1);//Send next PWM value to amp place_hold2 = place_hold2 + 1; if(place_hold2 == 8) { + if(verbosity3 == 1) + { + printf("value flag2: %d\n\r",flag2); + } + printf("value flag2: %d\n\r",flag2); place_hold1 = 0; place_hold2 = 0; flag1 = 0; @@ -129,10 +139,13 @@ } if(verbosity2 == 1) { - printf("value Buffer2: %d\n\r",value[0]); + //printf("value Buffer2: %d\n\r",value[0]); + printf("value placehold2: %d\n\r",place_hold2); } } - + //t.stop(); + //printf("The time taken was %f seconds\n", t.read()); + //t.reset(); } @@ -315,7 +328,8 @@ //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/gp40_8K_2018.wav","rb"); + //my_wav = fopen("/sd/mydir/gp40_8K_2018.wav","rb"); + my_wav = fopen("/sd/mydir/gp40_32K.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 @@ -379,11 +393,12 @@ printf("do we egt to this point:\n\r"); if (interrupt_condition == 1) { - sampletick.attach(&isr,1.0/16000); //1/16000 + sampletick.attach(&isr,1.0/32000); //1/16000 } slice_buf=(char *)malloc(wav_format.block_align); slice = 0; - while(1){ + while (!feof(my_wav)){ + //while(1){ while(flag3 == 1) { @@ -485,7 +500,7 @@ { flag4 = 0; break; - } + } slice_value[1]/=wav_format.num_channels; // slice_value is now averaged. Next it needs to be scaled to an unsigned 16 bit value @@ -510,7 +525,7 @@ //printf("The time taken was %f seconds\n", t2.read()); //t2.reset(); } - printf("we must have filled the buffer"); + //printf("we must have filled the buffer"); } }