old demo that i want to try in mbed studio

Dependencies:   mbed SDFileSystem_Copy_of_mbed_version I2S

Branch:
LargeFile_Tests
Revision:
57:0c76b15cabaf
Parent:
56:3755c53ac4c6
Child:
58:a174e7a8f5f2
--- a/NotchingDemo.cpp	Fri Sep 27 17:02:21 2019 +0000
+++ b/NotchingDemo.cpp	Fri Sep 27 19:15:46 2019 +0000
@@ -141,6 +141,38 @@
 
 
 }WAV_FILE_STRUCT;*/
+class PositionIndicators
+{
+public:
+    int notch1_indicator, notch2_indicator, notch3_indicator, notch4_indicator;
+    int notch5_indicator, notch6_indicator, notch7_indicator, notch8_indicator;
+    int notch1_start_pt, notch2_start_pt, notch3_start_pt, notch4_start_pt;
+    int notch5_start_pt, notch6_start_pt, notch7_start_pt, notch8_start_pt;
+    PositionIndicators()
+    {
+        notch1_start_pt = 44;
+        notch2_start_pt = 220884+44;
+        notch3_start_pt = notch2_start_pt+217698;
+        notch4_start_pt = notch3_start_pt + 193060;
+        notch5_start_pt = notch4_start_pt + 92010;
+        notch6_start_pt = notch5_start_pt + 216642;
+        notch7_start_pt = notch6_start_pt + 250316;
+        notch8_start_pt = notch7_start_pt + 165084;
+        notch1_indicator = notch1_start_pt;
+        notch2_indicator = notch2_start_pt;
+        notch3_indicator = notch3_start_pt;
+        notch4_indicator = notch4_start_pt;
+        notch5_indicator = notch5_start_pt;
+        notch6_indicator = notch6_start_pt;
+        notch7_indicator = notch7_start_pt;
+        notch8_indicator = notch8_start_pt;
+
+    }
+};
+
+
+
+
 class classSoundFile
 {
 public:
@@ -437,317 +469,13 @@
     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) {
-        printf("Cannot Open wavfile1\n\r");
-    }
-    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/02.wav","rb");
-    if(wavfile2 == NULL) {
-        printf("Cannot Open wavfile2\n\r");
-    }
-    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/03.wav","rb");
-    if(wavfile3 == NULL) {
-        printf("Cannot Open wavfile3\n\r");
-    }
-    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");
-    }
-    classSoundFile Sound4;
-    Sound4 = ReadFileInfo(Sound4,wavfile4);
-    fclose(wavfile4);
-    
-        FILE* wavfile5 = fopen("/sd/mydir/SoundDecoder_second/05.wav","rb");
-    if(wavfile5 == NULL) {
-        printf("Cannot Open wavfile5\n\r");
-    }
-    classSoundFile Sound5;
-    Sound5 = ReadFileInfo(Sound5,wavfile5);
-    fclose(wavfile5);
-    
-    
-        FILE* wavfile6 = fopen("/sd/mydir/SoundDecoder_second/06.wav","rb");
-    if(wavfile6 == NULL) {
-        printf("Cannot Open wavfile6\n\r");
-    }
-    classSoundFile Sound6;
-    Sound6 = ReadFileInfo(Sound6,wavfile6);
-    fclose(wavfile6);    
-    
-    
-        FILE* wavfile7 = fopen("/sd/mydir/SoundDecoder_second/07.wav","rb");
-    if(wavfile7 == NULL) {
-        printf("Cannot Open wavfile7\n\r");
-    }
-    classSoundFile Sound7;
-    Sound7 = ReadFileInfo(Sound7,wavfile7);
-    fclose(wavfile7);    
-    
-    
-            FILE* wavfile8 = fopen("/sd/mydir/SoundDecoder_second/08.wav","rb");
-    if(wavfile8 == NULL) {
-        printf("Cannot Open wavfile8\n\r");
-    }
-    classSoundFile Sound8;
-    Sound8 = ReadFileInfo(Sound8,wavfile8);
-    fclose(wavfile8);     
-    
-  /*  
-    
-            FILE* wavfile9 = fopen("/sd/mydir/SoundDecoder_second/09.wav","rb");
-    if(wavfile9 == NULL) {
-        printf("Cannot Open wavfile9\n\r");
-    }
-    classSoundFile Sound9;
-    Sound9 = ReadFileInfo(Sound9,wavfile9);
-    fclose(wavfile9);      
-    
-    
-            FILE* wavfile10 = fopen("/sd/mydir/SoundDecoder_second/10.wav","rb");
-    if(wavfile10 == NULL) {
-        printf("Cannot Open wavfile10\n\r");
-    }
-    classSoundFile Sound10;
-    Sound10 = ReadFileInfo(Sound10,wavfile10);
-    fclose(wavfile10);
-    
-    
-            FILE* wavfile11 = fopen("/sd/mydir/SoundDecoder_second/11.wav","rb");
-    if(wavfile11 == NULL) {
-        printf("Cannot Open wavfile11\n\r");
-    }
-    classSoundFile Sound11;
-    Sound11 = ReadFileInfo(Sound11,wavfile11);
-    fclose(wavfile11);  
-    
-    
-            FILE* wavfile12 = fopen("/sd/mydir/SoundDecoder_second/12.wav","rb");
-    if(wavfile12 == NULL) {
-        printf("Cannot Open wavfile12\n\r");
-    }
-    classSoundFile Sound12;
-    Sound12 = ReadFileInfo(Sound12,wavfile12);
-    fclose(wavfile12);  
-    
-            FILE* wavfile13 = fopen("/sd/mydir/SoundDecoder_second/13.wav","rb");
-    if(wavfile13 == NULL) {
-        printf("Cannot Open wavfile13\n\r");
-    }
-    classSoundFile Sound13;
-    Sound13 = ReadFileInfo(Sound13,wavfile13);
-    fclose(wavfile13);  
-    
-    
-            FILE* wavfile14 = fopen("/sd/mydir/SoundDecoder_second/14.wav","rb");
-    if(wavfile14 == NULL) {
-        printf("Cannot Open wavfile14\n\r");
-    }
-    classSoundFile Sound14;
-    Sound14 = ReadFileInfo(Sound14,wavfile14);
-    fclose(wavfile14);  
-    
-    
-            FILE* wavfile15 = fopen("/sd/mydir/SoundDecoder_second/15.wav","rb");
-    if(wavfile15 == NULL) {
-        printf("Cannot Open wavfile15\n\r");
-    }
-    classSoundFile Sound15;
-    Sound15 = ReadFileInfo(Sound15,wavfile15);
-    fclose(wavfile15);  
-    
-    
-            FILE* wavfile16 = fopen("/sd/mydir/SoundDecoder_second/16.wav","rb");
-    if(wavfile16 == NULL) {
-        printf("Cannot Open wavfile16\n\r");
-    }
-    classSoundFile Sound16;
-    Sound16 = ReadFileInfo(Sound16,wavfile16);
-    fclose(wavfile16);  
-    
-    
-            FILE* wavfile17 = fopen("/sd/mydir/SoundDecoder_second/17.wav","rb");
-    if(wavfile17 == NULL) {
-        printf("Cannot Open wavfile17\n\r");
-    }
-    classSoundFile Sound17;
-    Sound17 = ReadFileInfo(Sound17,wavfile17);
-    fclose(wavfile17);  
-    
-    
-            FILE* wavfile18 = fopen("/sd/mydir/SoundDecoder_second/18.wav","rb");
-    if(wavfile18 == NULL) {
-        printf("Cannot Open wavfile18\n\r");
-    }
-    classSoundFile Sound18;
-    Sound18 = ReadFileInfo(Sound18,wavfile18);
-    fclose(wavfile18);  
-    
-    
-            FILE* wavfile19 = fopen("/sd/mydir/SoundDecoder_second/19.wav","rb");
-    if(wavfile19 == NULL) {
-        printf("Cannot Open wavfile19\n\r");
-    }
-    classSoundFile Sound19;
-    Sound19 = ReadFileInfo(Sound19,wavfile19);
-    fclose(wavfile19);  
-    */
-    
-    //FILE* f1 = fopen("/sd/mydir/SoundDecoder_second/01.txt","rb");
-    
-    //fprintf(f1, Sound1.FileInfo.FileData.subchunk2_size);
-    
-    
-            
-    
+
 
-    fclose(wavfile2);
-    fclose(wavfile3);
-    NotchFadeIn.LengthSecs = 2;
-    NotchFadeOut.LengthSecs = 2;
-    NotchFadeIn = FadeDataInitialise(NotchFadeIn);
-    NotchFadeOut = FadeDataInitialise(NotchFadeOut);
+
 
 
 
@@ -755,9 +483,9 @@
 
 
 //timer_interrupt.reset();
-
+    fopen("/sd/);
     printf("about to play wav file\n\r");
-    Play_WaveFileLoop(Sound1,Sound2,Sound3,wavfile1,wavfile2,wavfile3);
+    Play_WaveFileLoop(Sound1,wavfile1,PositionIndicators);
     //Play_WaveFileDual(StartupWav,WavInfo_Startup);
     printf("finished playing Wav file\n\r");
 
@@ -768,18 +496,6 @@
     timer_open.stop();
     printf("It took %d useconds to close file\n\r",timer_open.read_us());
 
-    timer_open.reset();
-    timer_open.start();
-    fclose(wavfile2);
-    timer_open.stop();
-    printf("It took %d useconds to close file\n\r",timer_open.read_us());
-
-
-    timer_open.reset();
-    timer_open.start();
-    fclose(wavfile3);
-    timer_open.stop();
-    printf("It took %d useconds to close file\n\r",timer_open.read_us());
 
 
 
@@ -973,7 +689,7 @@
 
 
 
-void Play_WaveFileLoop(classSoundFile Sound1, classSoundFile Sound2, classSoundFile Sound3, FILE *wavfile1, FILE *wavfile2, FILE *wavfile3)
+void Play_WaveFileLoop(classSoundFile Sound1, FILE *wavfile1, classPositionIndicators Positions)
 {
     while(1) { //might have to change this to a while(1) loop?
         //New format!!  This should be (roughly) the way that this is done, with the new structures and classes
@@ -987,126 +703,18 @@
 
 
 
-        /*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) ) {
+            if( slice == (PositionIndicators.notch2_start_pt) ) {
                 slice1 = 0;
-                fseek(wavfile1,44,SEEK_SET);
+                fseek(Engine,notch1_start_pt,SEEK_SET);
             }
-            if(feof(wavfile1)) {
-                fseek(wavfile1,44,SEEK_SET);
-            }
+
             fread(Sound1.FileInfo.slice_buf,Sound1.FileInfo.FileFormat.block_align,1,wavfile1);
             Sound1.data_sptr=(short *)Sound1.FileInfo.slice_buf;     // 16 bit samples
 //=============================================================================================
-        }
 
-        else if(BlockFlag == 1) {
-
-
-
-
-            /*Block2*/
-
-            //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;
-            //We are now performing this section above.
-
-
-            if(FadeFlag) {
-                if( slice1 == (Sound1.FileInfo.num_slices-1) ) {
-                    slice1 = 0;
-                    fseek(wavfile1,44,SEEK_SET);
-                }
-                if(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");
-                    }
-                    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
-//=============================================================================================
-
-
-
-//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();
-
-                    //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).
-
-                    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.
-                    }
-
-                } 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***********************************************