old demo that i want to try in mbed studio
Dependencies: mbed SDFileSystem_Copy_of_mbed_version I2S
Revision 54:606a83fff291, committed 2019-09-23
- Comitter:
- roryhand
- Date:
- Mon Sep 23 20:23:20 2019 +0000
- Parent:
- 47:9334a8f54997
- Child:
- 55:5a441d3b0d57
- Commit message:
- WIP - version before seeing data sizes
Changed in this revision
| NotchingDemo.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/NotchingDemo.cpp Sun Sep 08 20:33:59 2019 +0000
+++ b/NotchingDemo.cpp Mon Sep 23 20:23:20 2019 +0000
@@ -11,6 +11,7 @@
#include "SDFileSystem.h"
#include "wm8731_Config_setup.h"
#include "WOLFSON_config_consts.h"
+//#include "BlockDevice.h"
#include <string>
#include <stdlib.h>
#include <fstream>
@@ -19,6 +20,10 @@
#include <string>
#define sample_freq 11025
#pragma import __use_two_region_memory
+//BlockDevice *bd = BlockDevice::get_default_instance();
+//#include "LittleFileSystem.h"
+//LittleFileSystem fs("fs");
+
DigitalOut myled(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
@@ -164,7 +169,7 @@
fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,FileInfo.WavFile); //This isnt actually required, its just a test
FileInfo.num_slices = FileInfo.FileData.subchunk2_size/FileInfo.FileFormat.block_align;
}*/
-
+int OneOff = 0;
int notch_flag = 0;
int i = 0;
int h = 0;
@@ -210,6 +215,7 @@
int BellFlag = 0;
int BellFlag2 = 0;
int FadeFlag = 0;
+int BlockFlag = 0;
int FileSwitchFlag = 0;
@@ -263,6 +269,7 @@
void isr()
{
+ //timer_interrupt.start();
if(flag1 == 0) {
value[0] = Buffer1[place_hold1]>>4;
i2s.write(value,1);//Send next PWM value to amp
@@ -287,6 +294,9 @@
FLAGBUFF2 = 0;
}
}
+
+ //timer_interrupt.stop();
+
}
void horn_sound()
@@ -316,8 +326,33 @@
void FadeOutIsr()
{
FadeFlag = 1;
- fseek(wavfile2,44,SEEK_SET);
- fseek(wavfile3,44,SEEK_SET);
+ OneOff = 1;
+ /*
+ wavfile2 = fopen("/sd/mydir/SoundDecoder_second/09.wav","rb");
+ if(wavfile2 == NULL) {
+ printf("Cannot Open wavfile2\n\r");
+ }
+ */
+
+
+
+ /*
+ wavfile3 = fopen("/sd/mydir/SoundDecoder_second/02.wav","rb");
+ if(wavfile3 == NULL) {
+ printf("Cannot Open wavfile3\n\r");
+ }
+ */
+ /*
+ FILE* wavfile4 = fopen("/sd/mydir/SoundDecoder_second/04.wav","rb");
+ if(wavfile4 == NULL) {
+ printf("Cannot Open wavfile3\n\r");
+ }
+ */
+ //fseek(wavfile2,44,SEEK_SET);
+ //fseek(wavfile3,44,SEEK_SET);
+ slice2 = 0;
+ slice3 = 0;
+ BlockFlag = 1;
//printf("We are inside the FadeOut interrupt routine\n\r");
}
@@ -402,40 +437,167 @@
sampletick.attach(&isr,1.0/sampling_freq); //1/16000
//fileswitch_tick.attach(&FileSwitch_isr,6.0);//So we can switch between playing file 1 and file 2, including opening and closing
//not convinced we need this above line at the moment!!
+ /*
+FILE* f1 = fopen("/sd/mydir/SoundDecoder_second/01.wav","rb");
+
+
+ if(f1 == NULL) {
+ printf("Cannot Open f1\n\r");
+ }
+printf("size of file pointer: %d\n\r",sizeof(f1));
+FILE* f2 = fopen("/sd/mydir/SoundDecoder_second/02.wav","rb");
+ if(f2 == NULL) {
+ printf("Cannot Open f2\n\r");
+ }
+printf("size of file pointer: %d\n\r",sizeof(f2));
+FILE* f3 = fopen("/sd/mydir/SoundDecoder_second/03.wav","rb");
+ if(f3 == NULL) {
+ printf("Cannot Open f3\n\r");
+ }
+printf("size of file pointer: %d\n\r",sizeof(f3));
+
+FILE* f4 = fopen("/sd/mydir/SoundDecoder_second/04.wav","rb");
+ if(f4 == NULL) {
+ printf("Cannot Open f4\n\r");
+ }
+printf("size of file pointer: %d\n\r",sizeof(f4));
+FILE* f5 = fopen("/sd/mydir/SoundDecoder_second/05.wav","rb");
+ if(f5 == NULL) {
+ printf("Cannot Open f5\n\r");
+ }
+printf("size of file pointer: %d\n\r",sizeof(f5));
+FILE* f6 = fopen("/sd/mydir/SoundDecoder_second/06.wav","rb");
+ if(f6 == NULL) {
+ printf("Cannot Open f6\n\r");
+ }
+printf("size of file pointer: %d\n\r",sizeof(f6));
+FILE* f7 = fopen("/sd/mydir/SoundDecoder_second/07.wav","rb");
+ if(f7 == NULL) {
+ printf("Cannot Open f7\n\r");
+ }
+printf("size of file pointer: %d\n\r",sizeof(f7));
+FILE* f8 = fopen("/sd/mydir/SoundDecoder_second/08.wav","rb");
+ if(f8 == NULL) {
+ printf("Cannot Open f8\n\r");
+ }
+printf("size of file pointer: %d\n\r",sizeof(f8));
+FILE* f9 = fopen("/sd/mydir/SoundDecoder_second/09.wav","rb");
+ if(f9 == NULL) {
+ printf("Cannot Open f9\n\r");
+ }
+printf("size of file pointer: %d\n\r",sizeof(f9));
+FILE* f10 = fopen("/sd/mydir/SoundDecoder_second/10.wav","rb");
+ if(f10 == NULL) {
+ printf("Cannot Open f10\n\r");
+ }
+printf("size of file pointer: %d\n\r",sizeof(f10));
+FILE* f11 = fopen("/sd/mydir/SoundDecoder_second/11.wav","rb");
+ if(f11 == NULL) {
+ printf("Cannot Open f11\n\r");
+ }
+printf("size of file pointer: %d\n\r",sizeof(f11));
+FILE* f12 = fopen("/sd/mydir/SoundDecoder_second/12.wav","rb");
+ if(f12 == NULL) {
+ printf("Cannot Open f12\n\r");
+ }
+printf("size of file pointer: %d\n\r",sizeof(f12));
+FILE* f13 = fopen("/sd/mydir/SoundDecoder_second/13.wav","rb");
+ if(f13 == NULL) {
+ printf("Cannot Open f13\n\r");
+ }
+printf("size of file pointer: %d\n\r",sizeof(f13));
+FILE* f14 = fopen("/sd/mydir/SoundDecoder_second/14.wav","rb");
+ if(f14 == NULL) {
+ printf("Cannot Open f14\n\r");
+ }
+printf("size of file pointer: %d\n\r",sizeof(f14));
+FILE* f15 = fopen("/sd/mydir/SoundDecoder_second/15.wav","rb");
+ if(f15 == NULL) {
+ printf("Cannot Open f15\n\r");
+ }
+printf("size of file pointer: %d\n\r",sizeof(f15));
+FILE* f16 = fopen("/sd/mydir/SoundDecoder_second/16.wav","rb");
+ if(f16 == NULL) {
+ printf("Cannot Open f16\n\r");
+ }
+printf("size of file pointer: %d\n\r",sizeof(f16));
+FILE* f17 = fopen("/sd/mydir/SoundDecoder_second/17.wav","rb");
+ if(f17 == NULL) {
+ printf("Cannot Open f17\n\r");
+ }
+printf("size of file pointer: %d\n\r",sizeof(f17));
+FILE* f18 = fopen("/sd/mydir/SoundDecoder_second/18.wav","rb");
+ if(f18 == NULL) {
+ printf("Cannot Open f18\n\r");
+ }
+printf("size of file pointer: %d\n\r",sizeof(f18));
+FILE* f19 = fopen("/sd/mydir/SoundDecoder_second/19.wav","rb");
+ if(f19 == NULL) {
+ printf("Cannot Open f19\n\r");
+ }
+printf("size of file pointer: %d\n\r",sizeof(f19));
+FILE* f20 = fopen("/sd/mydir/SoundDecoder_second/20.wav","rb");
+ if(f20 == NULL) {
+ printf("Cannot Open f20\n\r");
+ }
+printf("size of file pointer: %d\n\r",sizeof(f20));
+FILE* f21 = fopen("/sd/mydir/SoundDecoder_second/21.wav","rb");
+ if(f21 == NULL) {
+ printf("Cannot Open f21\n\r");
+ }
+printf("size of file pointer: %d\n\r",sizeof(f21));
+FILE* f22 = fopen("/sd/mydir/SoundDecoder_second/22.wav","rb");
+ if(f22 == NULL) {
+ printf("Cannot Open f22\n\r");
+ }
+printf("size of file pointer: %d\n\r",sizeof(f22));
+*/
timer_open.reset();
timer_open.start();
- wavfile1 = fopen("/sd/mydir/SoundDecoder_second/01.wav","rb");
- if(wavfile1 == NULL) {
+ wavfile1 = sd.open("/sd/mydir/SoundDecoder_second/01.wav","rb");
+ if(wavfile1 == NULL) {
printf("Cannot Open wavfile1\n\r");
}
-
- timer_open.reset();
+ printf("size of wavfile1 %d\n\r",sizeof(wavfile1));
+ timer_open.stop();
printf("It took %d useconds to open file\n\r",timer_open.read_us());
-
-
+ timer_open.reset();
+
+
+printf("Size of wavfile 1: %d bytes\n\r",sizeof(wavfile1));
timer_open.start();
wavfile2 = fopen("/sd/mydir/SoundDecoder_second/09.wav","rb");
- if(wavfile2 == NULL) {
+ if(wavfile2 == NULL) {
printf("Cannot Open wavfile2\n\r");
}
- timer_open.reset();
+ timer_open.stop();
printf("It took %d useconds to open file\n\r",timer_open.read_us());
-
+ timer_open.reset();
+
timer_open.start();
wavfile3 = fopen("/sd/mydir/SoundDecoder_second/02.wav","rb");
- if(wavfile3 == NULL) {
+ if(wavfile3 == NULL) {
printf("Cannot Open wavfile3\n\r");
}
- timer_open.reset();
+ timer_open.stop();
printf("It took %d useconds to open file\n\r",timer_open.read_us());
-
-
+ timer_open.reset();
+
+
Sound1 = ReadFileInfo(Sound1,wavfile1);
Sound2 = ReadFileInfo(Sound2,wavfile2);
Sound3 = ReadFileInfo(Sound3,wavfile3);
+ /*
+ FILE* wavfile4 = fopen("/sd/mydir/SoundDecoder_second/04.wav","rb");
+ if(wavfile4 == NULL) {
+ printf("Cannot Open wavfile4\n\r");
+ }
+ Sound4 = ReadFileInfo(Sound4,wavfile4);
+ */
-
+ fclose(wavfile2);
+ fclose(wavfile3);
NotchFadeIn.LengthSecs = 2;
NotchFadeOut.LengthSecs = 2;
NotchFadeIn = FadeDataInitialise(NotchFadeIn);
@@ -445,33 +607,36 @@
TickFadeOut.attach(&FadeOutIsr,10.0);
+
+//timer_interrupt.reset();
+
printf("about to play wav file\n\r");
Play_WaveFileLoop(Sound1,Sound2,Sound3,wavfile1,wavfile2,wavfile3);
//Play_WaveFileDual(StartupWav,WavInfo_Startup);
printf("finished playing Wav file\n\r");
-
-
+
+
timer_open.reset();
timer_open.start();
fclose(wavfile1);
timer_open.stop();
printf("It took %d useconds to close file\n\r",timer_open.read_us());
-
+
timer_open.reset();
- timer_open.start();
+ timer_open.start();
fclose(wavfile2);
timer_open.stop();
- printf("It took %d useconds to close file\n\r",timer_open.read_us());
-
-
+ printf("It took %d useconds to close file\n\r",timer_open.read_us());
+
+
timer_open.reset();
- timer_open.start();
+ timer_open.start();
fclose(wavfile3);
timer_open.stop();
printf("It took %d useconds to close file\n\r",timer_open.read_us());
-
-
-
+
+
+
/************************************PLAY WAV FILE LOOP*******************/
//Play_WaveFileLoop(Sound, NotchingSet);
/************************************END OF PLAY WAV FILE LOOP*************/
@@ -494,7 +659,7 @@
//printf("wav_format.sample_rate: %d\n\r",FileInfo.FileFormat.sample_rate);
fread(&Sound.FileInfo.FileData,sizeof(Sound.FileInfo.FileData),1,wav_file);
- //printf("wav_data.subchunk2_size: %d\n\r",FileInfo.FileData.subchunk2_size);
+ printf("wav_data.subchunk2_size: %d\n\r",FileInfo.FileData.subchunk2_size);
Sound.FileInfo.slice_buf = ( char *)malloc(Sound.FileInfo.FileFormat.block_align);
fread(Sound.FileInfo.slice_buf,Sound.FileInfo.FileFormat.block_align,1,wav_file); //This isnt actually required, its just a test
Sound.FileInfo.num_slices = Sound.FileInfo.FileData.subchunk2_size/Sound.FileInfo.FileFormat.block_align;
@@ -676,10 +841,13 @@
- /*Block1*/
- /*Read in data for current sound files. We only have 3 active engine noises at a time.
- When it becomes time to transition up again, we then flip to the opposite block, and perform
- the opposite operation.*/
+ /*Block1*/
+ /*Read in data for current sound files. We only have 3 active engine noises at a time.
+ When it becomes time to transition up again, we then flip to the opposite block, and perform
+ the opposite operation.*/
+
+
+ if(BlockFlag == 0) {
//Sound1=======================================================================================
if( slice1 == (Sound1.FileInfo.num_slices-1) ) {
slice1 = 0;
@@ -691,19 +859,10 @@
fread(Sound1.FileInfo.slice_buf,Sound1.FileInfo.FileFormat.block_align,1,wavfile1);
Sound1.data_sptr=(short *)Sound1.FileInfo.slice_buf; // 16 bit samples
//=============================================================================================
-
-
-//Sound2=======================================================================================
- fread(Sound2.FileInfo.slice_buf,Sound2.FileInfo.FileFormat.block_align,1,wavfile2);
- Sound2.data_sptr=(short *)Sound2.FileInfo.slice_buf; // 16 bit samples
-//=============================================================================================
+ }
-
+ else if(BlockFlag == 1) {
-//Sound3=======================================================================================
- fread(Sound3.FileInfo.slice_buf,Sound3.FileInfo.FileFormat.block_align,1,wavfile3);
- Sound3.data_sptr=(short *)Sound3.FileInfo.slice_buf; // 16 bit samples
-//=============================================================================================
@@ -716,56 +875,94 @@
//We are now performing this section above.
- if(FadeFlag) {
- if(feof(wavfile1)) {
- fseek(wavfile1,44,SEEK_SET);
- }
+ if(FadeFlag) {
+ if( slice1 == (Sound1.FileInfo.num_slices-1) ) {
+ slice1 = 0;
+ fseek(wavfile1,44,SEEK_SET);
+ }
+ if(OneOff == 1) {
- //require this to get the fadeout coefficient for Sound1.
- NotchFadeOut.FadeCoeff = NotchFadeOut.FadeOut();//compute new FadeOut Coeff value
+ wavfile2 = fopen("/sd/mydir/SoundDecoder_second/09.wav","rb");
+ if(wavfile2 == NULL) {
+ printf("Cannot Open wavfile2\n\r");
+ }
+
+ wavfile3 = fopen("/sd/mydir/SoundDecoder_second/02.wav","rb");
+ if(wavfile3 == NULL) {
+ printf("Cannot Open wavfile3\n\r");
+ }
+ fseek(wavfile2,44,SEEK_SET);
+ fseek(wavfile3,44,SEEK_SET);
+ /*
+ FILE* wavfile4 = fopen("/sd/mydir/SoundDecoder_second/04.wav","rb");
+ if(wavfile4 == NULL) {
+ printf("Cannot Open wavfile3\n\r");
+ }
+ */
+ OneOff = 0;
+ }
+
+ fread(Sound1.FileInfo.slice_buf,Sound1.FileInfo.FileFormat.block_align,1,wavfile1);
+ Sound1.data_sptr=(short *)Sound1.FileInfo.slice_buf; // 16 bit samples
+
+//Sound2=======================================================================================
+ fread(Sound2.FileInfo.slice_buf,Sound2.FileInfo.FileFormat.block_align,1,wavfile2);
+ Sound2.data_sptr=(short *)Sound2.FileInfo.slice_buf; // 16 bit samples
+//=============================================================================================
- if( ((Sound2.FileInfo.FileData.subchunk2_size) - NotchFadeIn.Length - 2*11025) <= (ftell(wavfile2) + 44))
- {
+//Sound3=======================================================================================
+ fread(Sound3.FileInfo.slice_buf,Sound3.FileInfo.FileFormat.block_align,1,wavfile3);
+ Sound3.data_sptr=(short *)Sound3.FileInfo.slice_buf; // 16 bit samples
+//=============================================================================================
+
+ //require this to get the fadeout coefficient for Sound1.
+ NotchFadeOut.FadeCoeff = NotchFadeOut.FadeOut();//compute new FadeOut Coeff value
+
+
+
+ if( ((Sound2.FileInfo.FileData.subchunk2_size) - NotchFadeIn.Length - 2*11025) <= (ftell(wavfile2) + 44)) {
- //required for calculating the fade In coefficient for Sound3
- NotchFadeIn.FadeCoeff = NotchFadeIn.FadeIn();
+ //required for calculating the fade In coefficient for Sound3
+ NotchFadeIn.FadeCoeff = NotchFadeIn.FadeIn();
- //Read In the next Notch
+ //Read In the next Notch
- /*
- fread(Sounds[NotchingSet.Notch].FileInfo.slice_buf,Sounds[NotchingSet.Notch].FileInfo.FileFormat.block_align,1,Sounds[NotchingSet.Notch].FileInfo.WavFile);
- Sounds[NotchingSet.Notch].data_sptr = (short *)Sounds[NotchingSet.Notch].FileInfo.slice_buf;
- */
- //no longer require the above section as we are reading in data for Sound3 (above, at beginning of function).
+ /*
+ fread(Sounds[NotchingSet.Notch].FileInfo.slice_buf,Sounds[NotchingSet.Notch].FileInfo.FileFormat.block_align,1,Sounds[NotchingSet.Notch].FileInfo.WavFile);
+ Sounds[NotchingSet.Notch].data_sptr = (short *)Sounds[NotchingSet.Notch].FileInfo.slice_buf;
+ */
+ //no longer require the above section as we are reading in data for Sound3 (above, at beginning of function).
+
+ if( (ftell(wavfile2) + 44) >= Sound2.FileInfo.FileData.subchunk2_size ) {
- if( (ftell(wavfile2) + 44) >= Sound2.FileInfo.FileData.subchunk2_size ) {
+ //need to explicitly test if this notation/syntax works for pointers....
+ /*Was this ever tested?? no idea...
+ If not then we need to pass in the 3 different "data_sptr" variables in separately, and not tied to a specific class
+ or structure.*/
+ *Sound1.data_sptr = *Sound3.data_sptr*NotchFadeIn.FadeCoeff;//Sound 3 by itself.
+ //fclose(wavfile2);
+ //fclose(wavfile1);
+ } else {
+ *Sound1.data_sptr = *Sound1.data_sptr*NotchFadeOut.FadeCoeff + *Sound2.data_sptr + *Sound3.data_sptr*NotchFadeIn.FadeCoeff;//Sounds 1, 2 and 3 Cross-fade.
+ //probably later on redesign this to work with flags - that way it may be a little easier to debug any issues.
+ }
- //need to explicitly test if this notation/syntax works for pointers....
- /*Was this ever tested?? no idea...
- If not then we need to pass in the 3 different "data_sptr" variables in separately, and not tied to a specific class
- or structure.*/
- *Sound1.data_sptr = *Sound3.data_sptr*NotchFadeIn.FadeCoeff;//Sound 3 by itself.
} else {
- *Sound1.data_sptr = *Sound1.data_sptr*NotchFadeOut.FadeCoeff + *Sound2.data_sptr + *Sound3.data_sptr*NotchFadeIn.FadeCoeff;//Sounds 1, 2 and 3 Cross-fade.
- //probably later on redesign this to work with flags - that way it may be a little easier to debug any issues.
+ *Sound1.data_sptr = *Sound1.data_sptr*NotchFadeOut.FadeCoeff + *Sound2.data_sptr;//Sound1 and Sound 2 cross fade
}
- } else {
- *Sound1.data_sptr = *Sound1.data_sptr*NotchFadeOut.FadeCoeff + *Sound2.data_sptr;//Sound1 and Sound 2 cross fade
}
+
+ /********************END OF DATA ASSIGNMENT SECTION*************************************************/
+
}
- /********************END OF DATA ASSIGNMENT SECTION*************************************************/
-
-
-
-
/**********************************************************************************************************/
/****************************DATA OUTPUT SECTION***********************************************************/