![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
old demo that i want to try in mbed studio
Dependencies: mbed SDFileSystem_Copy_of_mbed_version I2S
Diff: NotchingDemo.cpp
- Revision:
- 3:6169aeeaeeb4
- Parent:
- 2:957d3b2afff4
- Child:
- 4:55fbbb049bae
--- a/NotchingDemo.cpp Thu Feb 28 21:53:28 2019 +0000 +++ b/NotchingDemo.cpp Sat Mar 16 21:51:10 2019 +0000 @@ -25,8 +25,10 @@ Ticker BellTick; Ticker EdTick; Ticker TickFadeOut; +Ticker TestTick; Timer t; Timer t2; +Timer NotchTimer; Serial pc(USBTX, USBRX); // tx, rx //FOR DEBUGGING PROGRAM USING GNU SCREEN DigitalOut cs(p8); @@ -136,7 +138,6 @@ public: //add a class constructor - WAV_FILE_STRUCT FileInfo; short * data_sptr; //classSoundFile(string filename);//this is the constructor @@ -190,6 +191,12 @@ short place_hold1 = 0; short place_hold2 = 0; + +string FOLDER; +string RootFolder = "/sd/mydir/SoundDecoder/"; +string filename[25]; +classSoundFile Sound[22]; + volatile int flag1 = 1; volatile int flag2 = 0; volatile int flag3 = 1; @@ -292,15 +299,72 @@ } +classFade FadeDataInitialise(classFade FadeData); + + + + + +//function prototypes +WAV_FILE_STRUCT ReadFileInfo(WAV_FILE_STRUCT FileInfo, FILE * wav_file); +classSoundFile LoadFileStream(classSoundFile FileInfo, string filename); + +float FadeOut(void); +void Play_WaveFile(FILE * my_wav, WAV_FILE_STRUCT FileInfo); +//void Play_WaveFileLoop(FILE * my_wav, WAV_FILE_STRUCT FileInfo); +//*********************INTERRUPT ROUTINE FOR NOTCHING*************************** void NotchUpIsr() { if(1 <= NotchingSet.Notch < 8) { + NotchTimer.start(); +const char* FOLDER; +string Folderint; + if(NotchingSet.Notch == 1) { + Folderint = RootFolder + filename[NotchingSet.Notch + 1]; + FOLDER = Folderint.c_str(); + Sound[NotchingSet.Notch + 1].FileInfo.WavFile = fopen(FOLDER,"rb"); + fseek(Sound[NotchingSet.Notch + 1].FileInfo.WavFile,44,SEEK_SET); + + Folderint = RootFolder + filename[NotchingSet.Notch + 8]; + FOLDER = Folderint.c_str(); + Sound[NotchingSet.Notch + 8].FileInfo.WavFile = fopen(FOLDER,"rb"); + fseek(Sound[NotchingSet.Notch + 8].FileInfo.WavFile,44,SEEK_SET); + + //Have Reset the file position indicators + + } else { + Folderint = RootFolder + filename[NotchingSet.Notch + 1]; + FOLDER = Folderint.c_str(); + Sound[NotchingSet.Notch + 1].FileInfo.WavFile = fopen(FOLDER,"rb"); + fseek(Sound[NotchingSet.Notch + 1].FileInfo.WavFile,44,SEEK_SET); + + + Folderint = RootFolder + filename[NotchingSet.Notch + 8]; + FOLDER = Folderint.c_str(); + Sound[NotchingSet.Notch + 8].FileInfo.WavFile = fopen(FOLDER,"rb"); + fseek(Sound[NotchingSet.Notch + 8].FileInfo.WavFile,44,SEEK_SET); + + fclose(Sound[NotchingSet.Notch].FileInfo.WavFile); + + } + + + + NotchingSet.Notch = NotchingSet.Notch + 1; NotchingSet.NotchTransUp = NotchingSet.Notch + 7; NotchingSet.NotchDirection = 1; + + + FadeDataInitialise(NotchFadeIn); + FadeDataInitialise(NotchFadeOut); + NotchTimer.stop(); + printf("NotchTimer ReadOut: %d\n\r",NotchTimer.read_ms()); + NotchTimer.reset(); + } } @@ -310,19 +374,19 @@ NotchingSet.Notch = NotchingSet.Notch - 1; NotchingSet.NotchTransDown = NotchingSet.Notch + 15;; NotchingSet.NotchDirection = 0; + FadeDataInitialise(NotchFadeIn); + FadeDataInitialise(NotchFadeOut); } } +/**********************END OF INTERRUPT ROUTINE FOR NOTCHING*******************/ + + -//function prototypes -WAV_FILE_STRUCT ReadFileInfo(WAV_FILE_STRUCT FileInfo, FILE * wav_file); -classSoundFile LoadFileStream(classSoundFile FileInfo, string filename); -classFade FadeDataInitialise(classFade FadeData); -float FadeOut(void); -void Play_WaveFile(FILE * my_wav, WAV_FILE_STRUCT FileInfo); -//void Play_WaveFileLoop(FILE * my_wav, WAV_FILE_STRUCT FileInfo); + + void Play_WaveFileLoop(classSoundFile Sounds, Notch_STRUCT NotchingSet); int main() { @@ -342,18 +406,23 @@ FILE *StartupWav; FILE *IdleWav; - char * RootFolder = "/sd/mydir/SoundDecoder/"; + DIR *dir; dirent *ent; int iterator = 0; - string filename[10]; - if ((dir = opendir ("/sd/mydir/SoundDecoder")) != NULL) { + + + /* + + printf("Directory is about to be opened? Still dont really Get this concept\n\r"); + //if i try to open folder SoundDecoder2, it gets stuck after file 13... WHY + if ((dir = opendir ("/sd/mydir/SoundDecoder_second")) != NULL) { // print all the files and directories within directory while ((ent = readdir (dir)) != NULL) { - printf("%s\r\n",string(ent->d_name)); - filename[iterator] = string(ent->d_name); - + //printf("%s\r\n",string(ent->d_name)); + filename[iterator] = (ent->d_name); + printf("Filename: %s\n\r",filename[iterator]); //printf("%s\r\n",filename[iterator]); iterator = iterator + 1; //printf("%s\r\n", ent->d_name); @@ -361,30 +430,42 @@ } closedir (dir); } - for(iterator = 0; iterator < 10; iterator ++) { + + printf("Now printing all the files"); + for(iterator = 0; iterator < 21; iterator ++) { printf("All the Files: %s\r\n",filename[iterator]); //printf("All the Files: %s\r\n",ent[iterator]); } + + */ //strcat(RootFolder,qdfilename[0]); - string folder = RootFolder + filename[9]; - printf("Folder: %s\n\r",folder); + //string folder = RootFolder + filename[9]; + //printf("Folder: %s\n\r",folder); //printf("Files and Folders contained here: %d\n\r",readdir(dp)); //StartupWav = fopen("/sd/mydir/Startup.wav","rb"); - const char* folder2 = folder.c_str(); + //const char* folder2 = folder.c_str(); string FileName; //vector <classSoundFile> Sound (27); - classSoundFile Sound[22]; + const char* FOLDER; + /* for(int iii = 0; iii < 21; iii++) { //Sound[0].FileInfo; - string folder = RootFolder + filename[3]; + string folder = RootFolder + filename[iii]; printf("Whole File Thing: %s\n\r",folder); - Sound[iii].FileInfo.WavFile = fopen("/sd/mydir/645Engine/Startup.wav","rb"); + t.reset(); + t.start(); + FOLDER = folder.c_str(); + Sound[iii].FileInfo.WavFile = fopen(FOLDER,"rb"); + t.stop(); + printf("The time taken was %f seconds\n\r", t.read()); + t.reset(); + printf("Size of FILE* %d\n\r ",sizeof(Sound[iii].FileInfo.WavFile)); fseek(Sound[iii].FileInfo.WavFile,20,SEEK_SET); fread(&Sound[iii].FileInfo.FileFormat,sizeof(Sound[iii].FileInfo.FileFormat),1,Sound[iii].FileInfo.WavFile); @@ -395,11 +476,11 @@ fread(Sound[iii].FileInfo.slice_buf,Sound[iii].FileInfo.FileFormat.block_align,1,Sound[iii].FileInfo.WavFile); //This isnt actually required, its just a test Sound[iii].FileInfo.num_slices = Sound[iii].FileInfo.FileData.subchunk2_size/Sound[iii].FileInfo.FileFormat.block_align; //printf("Number of Slices: %d\n\r",Sound[iii].FileInfo.num_slices); - + fread(Sound[iii].FileInfo.slice_buf,Sound[iii].FileInfo.FileFormat.block_align,1,Sound[iii].FileInfo.WavFile); Sound[iii].data_sptr = (short *)Sound[iii].FileInfo.slice_buf; printf("data_sptr: %d\n\r",*Sound[iii].data_sptr); - + printf("Iteration: %d\n\r",iii); printf("SizeOf Sound[iii] %d\n\r",sizeof(Sound[iii])); printf("SizeOf Sound[iii].FileInfo.FileFormat %d\n\r",sizeof(Sound[iii].FileInfo.FileFormat)); @@ -408,8 +489,8 @@ printf("SizeOf Sound[iii].FileInfo.FileFormat %d\n\r",sizeof(Sound[iii].FileInfo.id_number)); printf("SizeOf Sound[iii].FileInfo.FileFormat %d\n\r",sizeof(Sound[iii].FileInfo.slice_buf)); printf("SizeOf Sound[iii].FileInfo.FileFormat %d\n\r",sizeof(Sound[iii].FileInfo.num_slices)); - fclose(Sound[iii].FileInfo.WavFile);//close the file stream. We will only reopen the file when we need to do it. Hopefully this should also free the memory... - + //fclose(Sound[iii].FileInfo.WavFile);//close the file stream. We will only reopen the file when we need to do it. Hopefully this should also free the memory... + /* FILE *WavFile; int id_number; @@ -417,7 +498,132 @@ int num_slices; */ //Sounds[iii] = LoadFileStream(Sounds[iii],FileName); - } + //} + /* + int aaa = 0; + string folder = RootFolder + filename[0]; + FOLDER = folder.c_str(); + FILE* mywav0 = fopen(FOLDER,"rb"); + printf("we opened This file %d\n\r",aaa); + aaa = aaa+1; + + folder = RootFolder + filename[1]; + FOLDER = folder.c_str(); + FILE* mywav1 = fopen(FOLDER,"rb"); + printf("we opened This file %d\n\r",aaa); + aaa = aaa+1; + + folder = RootFolder + filename[2]; + FOLDER = folder.c_str(); + FILE* mywav2 = fopen(FOLDER,"rb"); + printf("we opened This file %d\n\r",aaa); + aaa = aaa+1; + + folder = RootFolder + filename[3]; + FOLDER = folder.c_str(); + FILE* mywav3 = fopen(FOLDER,"rb"); + printf("we opened This file %d\n\r",aaa); + aaa = aaa+1; + + folder = RootFolder + filename[4]; + FOLDER = folder.c_str(); + FILE* mywav4 = fopen(FOLDER,"rb"); + printf("we opened This file %d\n\r",aaa); + aaa = aaa+1; + + folder = RootFolder + filename[5]; + FOLDER = folder.c_str(); + FILE* mywav5 = fopen(FOLDER,"rb"); + printf("we opened This file %d\n\r",aaa); + aaa = aaa+1; + + folder = RootFolder + filename[6]; + FOLDER = folder.c_str(); + FILE* mywav6 = fopen(FOLDER,"rb"); + printf("we opened This file %d\n\r",aaa); + aaa = aaa+1; + + folder = RootFolder + filename[7]; + FOLDER = folder.c_str(); + FILE* mywav7 = fopen(FOLDER,"rb"); + printf("we opened This file %d\n\r",aaa); + aaa = aaa+1; + + folder = RootFolder + filename[8]; + FOLDER = folder.c_str(); + FILE* mywav8 = fopen(FOLDER,"rb"); + printf("we opened This file %d\n\r",aaa); + aaa = aaa+1; + + folder = RootFolder + filename[9]; + FOLDER = folder.c_str(); + FILE* mywav9 = fopen(FOLDER,"rb"); + printf("we opened This file %d\n\r",aaa); + aaa = aaa+1; + + folder = RootFolder + filename[10]; + FOLDER = folder.c_str(); + FILE* mywav10 = fopen(FOLDER,"rb"); + printf("we opened This file %d\n\r",aaa); + aaa = aaa+1; + + folder = RootFolder + filename[11]; + FOLDER = folder.c_str(); + FILE* mywav11 = fopen(FOLDER,"rb"); + printf("we opened This file %d\n\r",aaa); + aaa = aaa+1; + + folder = RootFolder + filename[12]; + FOLDER = folder.c_str(); + FILE* mywav12 = fopen(FOLDER,"rb"); + printf("we opened This file %d\n\r",aaa); + aaa = aaa+1; + + folder = RootFolder + filename[13]; + FOLDER = folder.c_str(); + FILE* mywav13 = fopen(FOLDER,"rb"); + printf("we opened This file %d\n\r",aaa); + aaa = aaa+1; + + folder = RootFolder + filename[14]; + FOLDER = folder.c_str(); + FILE* mywav14 = fopen(FOLDER,"rb"); + printf("we opened This file %d\n\r",aaa); + aaa = aaa+1; + + folder = RootFolder + filename[15]; + FOLDER = folder.c_str(); + FILE* mywav15 = fopen(FOLDER,"rb"); + printf("we opened This file %d\n\r",aaa); + aaa = aaa+1; + + folder = RootFolder + filename[16]; + FOLDER = folder.c_str(); + FILE* mywav16 = fopen(FOLDER,"rb"); + printf("we opened This file %d\n\r",aaa); + aaa = aaa+1; + + folder = RootFolder + filename[17]; + FOLDER = folder.c_str(); + FILE* mywav17 = fopen(FOLDER,"rb"); + printf("we opened This file %d\n\r",aaa); + aaa = aaa+1; + + folder = RootFolder + filename[18]; + FOLDER = folder.c_str(); + FILE* mywav18 = fopen(FOLDER,"rb"); + printf("we opened This file %d\n\r",aaa); + aaa = aaa+1; + */ + + /* + FILE* SoundWav[27]; + for(int iii = 0; iii < 26; iii++) { + //SoundWav[iii] = fopen("/sd/mydir/645Engine/Startup.wav","rb"); + printf("We just printed a file!: %d\n\r",iii+1); + } + printf("Do we get past this point?? are we able to do ANYTHING?? \n\r"); + */ //We still experience the exact same memory issue //classSoundFile Sounds[10] = {classSoundFile(FileName),classSoundFile(FileName), classSoundFile(FileName),classSoundFile(FileName),classSoundFile(FileName),classSoundFile(FileName),classSoundFile(FileName), classSoundFile(FileName),classSoundFile(FileName),classSoundFile(FileName)}; @@ -437,7 +643,7 @@ - +/* StartupWav = fopen("/sd/mydir/645Engine/Startup.wav","rb"); IdleWav = fopen("/sd/mydir/645Engine/N2_11k_minus10dB.wav","rb"); IdleN2Wav = fopen("/sd/mydir/645Engine/N2N3_11k_minus10dB.wav","rb"); @@ -445,7 +651,7 @@ N2Wav = fopen("/sd/mydir/645Engine/N3_11k_minus11dB.wav","rb"); BellWav = fopen("/sd/mydir/645Engine/EMD_BRONZE_BELL_1_11k_minus10dB.wav","rb"); FlangeWav = fopen("/sd/mydir/645Engine/EX_FlangeJoint1_11k_minus12dB.wav","rb"); - + WavInfo_Startup = ReadFileInfo(WavInfo_Startup, StartupWav); printf("WavInfo_Startup Size: %d\n\r",sizeof(WavInfo_Startup)); @@ -455,7 +661,7 @@ WavInfo_N2 = ReadFileInfo(WavInfo_N2, N2Wav); WavInfo_Bell = ReadFileInfo(WavInfo_Bell, BellWav); WavInfo_Flange = ReadFileInfo(WavInfo_Flange, FlangeWav); - +*/ //Populate our class instances with some data (is there an implicit way to do this?) N2FadeIn.LengthSecs = 4; @@ -463,7 +669,7 @@ N2FadeIn = FadeDataInitialise(N2FadeIn); IdleFadeOut = FadeDataInitialise(IdleFadeOut); - + printf("hello\n\r"); //Set up the wolfson Audio Codec board wm8731_Config_setup(); //i2s audio data transfer code?? @@ -471,9 +677,12 @@ i2s.masterslave(I2S_MASTER); led3 = 1; led2 = 1; + sampletick.attach(&isr,1.0/sampling_freq); //1/16000 //TickFadeOut.attach(&FadeOutIsr,10.0); + printf("SamplingFreq: %d\n\r",sampling_freq); i2s.start(); + printf("Hello i2s has starrted!!"); Horn.rise(&FadeOutIsr); slice = 0; fseek(IdleN2Wav,44,SEEK_SET); @@ -499,9 +708,11 @@ fseek(FlangeWav,44,SEEK_SET); Play_WaveFile(StartupWav,WavInfo_Startup); + fseek(IdleN2Wav,44,SEEK_SET);//reset for use in the Loop code slice = 0; fseek(IdleWav,44,SEEK_SET); + NotchingSet.Notch = 1; //Play_WaveFileLoop(IdleWav, WavInfo_Idle); i2s.stop(); @@ -509,6 +720,10 @@ } + + + + WAV_FILE_STRUCT ReadFileInfo(WAV_FILE_STRUCT FileInfo, FILE * wav_file) { fseek(wav_file,20,SEEK_SET); @@ -623,6 +838,7 @@ //void Play_WaveFileLoop(FILE * my_wav, WAV_FILE_STRUCT FileInfo)//(classSoundFile Sounds) +/* void Play_WaveFileLoop(classSoundFile Sounds[27], Notch_STRUCT NotchingSet) { while(1) { //might have to change this to a while(1) loop? @@ -644,30 +860,30 @@ if(feof(Sounds[NotchingSet.Notch].FileInfo.WavFile)) { fseek(Sounds[NotchingSet.Notch].FileInfo.WavFile,44,SEEK_SET); } - + //Read in data for current (i.e. now the previous notch, according to the index!!) //We might not need this code here...as its probably done somewhere else?? fread(Sounds[NotchingSet.Notch-1].FileInfo.slice_buf,Sounds[NotchingSet.Notch-1].FileInfo.FileFormat.block_align,1,Sounds[NotchingSet.Notch-1].FileInfo.WavFile); Sounds[NotchingSet.Notch-1].data_sptr = (short *)Sounds[NotchingSet.Notch-1].FileInfo.slice_buf; - + NotchFadeOut.FadeCoeff = NotchFadeOut.FadeOut();//compute new FadeOut Coeff value //Read in the notch transition file for transitioning up fread(Sounds[NotchingSet.NotchTransUp].FileInfo.slice_buf,Sounds[NotchingSet.NotchTransUp].FileInfo.FileFormat.block_align,1,Sounds[NotchingSet.NotchTransUp].FileInfo.WavFile); Sounds[NotchingSet.NotchTransUp].data_sptr = (short*)Sounds[NotchingSet.NotchTransUp].FileInfo.slice_buf; - + if( ((Sounds[NotchingSet.NotchTransUp].FileInfo.FileData.subchunk2_size) - NotchFadeIn.Length - 2*11025) <= (ftell(Sounds[NotchingSet.NotchTransUp].FileInfo.WavFile) + 44)) //if( (WavInfo_IdleN2.FileData.subchunk2_size)/8 <=ftell(IdleN2Wav) ) { NotchFadeIn.FadeCoeff = NotchFadeIn.FadeIn(); - + //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; if( (ftell(Sounds[NotchingSet.NotchTransUp].FileInfo.WavFile) + 44) >= Sounds[NotchingSet.NotchTransUp].FileInfo.FileData.subchunk2_size ) { - + //need to explicitly test if this notation/syntax works for pointers.... *Sounds[NotchingSet.Notch].data_sptr = *Sounds[NotchingSet.Notch].data_sptr*NotchFadeIn.FadeCoeff; } else { @@ -681,8 +897,8 @@ } -/********************END OF DATA ASSIGNMENT SECTION*************************************************/ - + /********************END OF DATA ASSIGNMENT SECTION*************************************************/ +/* for (channel=0; channel<Sounds[NotchingSet.Notch].FileInfo.FileFormat.num_channels; channel++) { switch (Sounds[NotchingSet.Notch].FileInfo.FileFormat.sig_bps) { case 16: @@ -717,6 +933,7 @@ slice = slice + 1; } } +*/