old demo that i want to try in mbed studio

Dependencies:   mbed SDFileSystem_Copy_of_mbed_version I2S

Files at this revision

API Documentation at this revision

Comitter:
roryhand
Date:
Sun Sep 08 19:23:09 2019 +0000
Parent:
43:890d76ffe627
Child:
45:0e8e1f2ec5d2
Commit message:
WIP - Adding in appropriate info to use new method of sharing objects, Tristan and Rory idea

Changed in this revision

NotchingDemo.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/NotchingDemo.cpp	Sat Sep 07 15:07:10 2019 +0000
+++ b/NotchingDemo.cpp	Sun Sep 08 19:23:09 2019 +0000
@@ -143,7 +143,7 @@
 {
 public:
 
-//add a class constructor
+//add a class constructor at some point in the future (perform tests in visual studio)
     WAV_FILE_STRUCT FileInfo;
     short * data_sptr;
     string file_location;
@@ -384,10 +384,10 @@
 
 
 
-void Play_WaveFileLoop(classSoundFile Sounds[], Notch_STRUCT NotchingSet);
+void Play_WaveFileLoop(classSoundFile Sound1, classSoundFile Sound2, classSoundFile Sound3, FILE* wavfile1,FILE* wavfile2, FILE* wavfile3);
 int main()
 {
- 
+
     NotchUp.mode(PullUp);
     NotchDown.mode(PullUp);
 
@@ -431,13 +431,13 @@
         }
         */
 
-        /*
-        printf("FileName: %s\n\r",Sound[aaa].file_location);
-        fclose(Sound[aaa].FileInfo.WavFile);
-        free(Sound[aaa].FileInfo.WavFile);
-        */
-        //wait(1);
-  //  }
+    /*
+    printf("FileName: %s\n\r",Sound[aaa].file_location);
+    fclose(Sound[aaa].FileInfo.WavFile);
+    free(Sound[aaa].FileInfo.WavFile);
+    */
+    //wait(1);
+    //  }
 
     /*
     string RootFolder = "sd/mydir/SoundDecoder_second/";
@@ -876,59 +876,109 @@
 
 //void Play_WaveFileLoop(FILE * my_wav, WAV_FILE_STRUCT FileInfo)//(classSoundFile Sounds)
 
-void Play_WaveFileLoop(classSoundFile Sounds[], Notch_STRUCT NotchingSet)
+//void Play_WaveFileLoop(classSoundFile Sounds[], Notch_STRUCT NotchingSet)
+void Play_WaveFileLoop(classSoundFile Sound1, classSoundFile Sound2, classSoundFile Sound3, FIlE *wavfile1, FILE *wavfile2, FILE *wavfile3, FILE_NAME_STRUCT, filenames)
 {
     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
         ////fread(Sound[Notch].FileData.slice_buf,Sound[Notch].FileFormat.block_align,1,Sound[notch].WavFile);
         //data_sptr=(short *)Sound[Notch].FileInfo.slice_buf;
+//Block 1 of code.  We need to pass in 3x classSoundFile objects, and 3x FILE* pointer objects.
+//This will allow us to switch between the 3 different files (using "cross-fades") as needed.
+        /*Remember that these will need to be global varaibles to work properly*/
+
 
 
-        if( slice == (Sounds[NotchingSet.Notch].FileInfo.num_slices-1) ) {
-            slice = 0;
-            fseek(Sounds[NotchingSet.Notch].FileInfo.WavFile,44,SEEK_SET);
-        }
+
+
 
-        //fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,my_wav);
-        data_sptr=(short *)Sounds[NotchingSet.Notch].FileInfo.slice_buf;     // 16 bit samples
+
+
+        //data_sptr=(short *)Sounds[NotchingSet.Notch].FileInfo.slice_buf;     // 16 bit samples
         //make sure we are reading in the correct "notch" here
 
         if(FadeFlag) {
-            if(feof(Sounds[NotchingSet.Notch].FileInfo.WavFile)) {
-                fseek(Sounds[NotchingSet.Notch].FileInfo.WavFile,44,SEEK_SET);
+            if(feof(wavfile1)) {
+                fseek(wavfile1,44,SEEK_SET);
+            }
+
+
+            /*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.*/
+//Sound1=======================================================================================
+            if( slice1 == (Sound1.FileInfo.num_slices-1) ) {
+                slice1 = 0;
+                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
+//=============================================================================================
+
+
+//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
+//=============================================================================================
+
+
+
+            /*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;
+            //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.
 
+            //require this to get the fadeout coefficient for Sound1.
             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;
+            */
+            //No longer need the above section as we are doing it above, for Sound2
 
-            if( ((Sounds[NotchingSet.NotchTransUp].FileInfo.FileData.subchunk2_size) - NotchFadeIn.Length - 2*11025) <= (ftell(Sounds[NotchingSet.NotchTransUp].FileInfo.WavFile) + 44))
+            if( ((Sound2.FileInfo.FileData.subchunk2_size) - NotchFadeIn.Length - 2*11025) <= (ftell(wavfile2) + 44))
                 //if( (WavInfo_IdleN2.FileData.subchunk2_size)/8 <=ftell(IdleN2Wav) )
             {
 
+
+                //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(Sounds[NotchingSet.NotchTransUp].FileInfo.WavFile) + 44) >= Sounds[NotchingSet.NotchTransUp].FileInfo.FileData.subchunk2_size ) {
+                if( (ftell(wavfile2) + 44) >= Sound2.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;
+                    /*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.*/
+                    *Sound3.data_sptr = *Sound3.data_sptr*NotchFadeIn.FadeCoeff;//Sound 3 by itself.
                 } else {
-                    *Sounds[NotchingSet.Notch-1].data_sptr = *Sounds[NotchingSet.Notch - 1].data_sptr*NotchFadeOut.FadeCoeff + *Sounds[NotchingSet.NotchTransUp].data_sptr + *Sounds[NotchingSet.Notch].data_sptr*NotchFadeIn.FadeCoeff;// + *data_sptr_N2;
+                    *Sound1.data_sptr = *Sound1.data_sptr*NotchFadeOut.FadeCoeff + *Sound2.data_sptr + *Sounds[NotchingSet.Notch].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 {
-                *Sounds[NotchingSet.Notch-1].data_sptr = *Sounds[NotchingSet.Notch-1].data_sptr*NotchFadeOut.FadeCoeff + *Sounds[NotchingSet.NotchTransUp].data_sptr;
+                *Sound1.data_sptr = *Sound1.data_sptr*NotchFadeOut.FadeCoeff + *Sound2.data_sptr;//Sound1 and Sound 2 cross fade
             }
 
         }
@@ -936,6 +986,13 @@
 
         /********************END OF DATA ASSIGNMENT SECTION*************************************************/
 
+
+
+
+
+        /**********************************************************************************************************/
+        /****************************DATA OUTPUT SECTION***********************************************************/
+        /**********************************************************************************************************/
         for (channel=0; channel<Sounds[NotchingSet.Notch].FileInfo.FileFormat.num_channels; channel++) {
             switch (Sounds[NotchingSet.Notch].FileInfo.FileFormat.sig_bps) {
                 case 16: