old demo that i want to try in mbed studio

Dependencies:   mbed SDFileSystem_Copy_of_mbed_version I2S

Branch:
LargeFile_Tests
Revision:
73:a5ab93214728
Parent:
72:599068243a0f
Child:
74:e71a7815f63d
--- a/NotchingDemo.cpp	Mon Sep 30 20:11:15 2019 +0000
+++ b/NotchingDemo.cpp	Mon Sep 30 20:54:14 2019 +0000
@@ -31,6 +31,7 @@
 DigitalIn  NotchDown(p17);//check the pin!!! Dont know if this will actually work...
 InterruptIn Horn(p16);
 Ticker sampletick;
+Ticker NotchUpTick;
 
 Ticker TickFadeOut;
 Timer t;
@@ -282,7 +283,7 @@
     }
 };
 
-
+int TransitionFlag;
 void NotchUpIsr()
 {
     if(1 <= NotchingSet.Notch < 8) {
@@ -292,6 +293,7 @@
         NotchingSet.NotchDirection = 1;
         NotchFadeIn.FadeDataInitialise();
         NotchFadeOut.FadeDataInitialise();
+        TransitionFlag = 1;
         //NotchFadeOut.FadeDataInitialise;
     }
 }
@@ -306,7 +308,9 @@
         NotchFadeOut.FadeDataInitialise();
     }
 }
-
+short * data_sptr1;
+short * data_sptr2;
+short * data_sptr3;
 char *slice_buf1;
 char *slice_buf2;
 char *slice_buf3;
@@ -429,7 +433,7 @@
 classSoundFile LoadFileStream(classSoundFile FileInfo, string filename);
 void Play_WaveFile(FILE * my_wav, WAV_FILE_STRUCT FileInfo);
 void Play_WaveFileDual(FILE * my_wav, WAV_FILE_STRUCT FileInfo);
-void Play_WaveFileLoop(classSoundFile Sound1, FILE* wavfile1,classPositionIndicators Positions);
+void Play_WaveFileLoop(classSoundFile Sound1, FILE* wavfile1, FILE* wavfile2,classPositionIndicators Positions);
 
 int main()
 {
@@ -457,7 +461,7 @@
     printf("Hello i2s has started!");
     i2s.start();
     sampletick.attach(&isr,1.0/sampling_freq);  //1/16000
-
+    NotchUpTick.attach(&NotchUpIsr,10.0);
 
     NotchFadeIn.LengthSecs = 2;
     NotchFadeOut.LengthSecs = 2;
@@ -467,13 +471,21 @@
 
     classPositionIndicators Positions;
     slice1 = Positions.notch7_start_pt;
+    
+    TransitionFlag = 0;
+    
     FILE* wavfile1 = fopen("/sd/mydir/SoundDecoder_second/All_eight_notches.wav","rb");
+    FILE* wavfile2 = fopen("/sd/mydir/SoundDecoder_second/All_14_Notch_Transitions","rb");
     //FILE* wavfile1 = fopen("/sd/mydir/SoundDecoder_second/01.wav","rb");
     classSoundFile Sound1;
+    classSoundFile Sound2;
+    Sound2 = ReadFileInfo(Sound2, wavfile2);
     Sound1 = ReadFileInfo(Sound1, wavfile1);
-    fseek(wavfile1,Positions.notch7_start_pt,SEEK_SET);
+    NotchingSet.Notch = 1;
+    fseek(wavfile1,Positions.notch_start_pts[1],SEEK_SET);
+    fseek(wavfile2,Positions.notch_transitions_start_pts[1],SEEK_SET);
     printf("about to play wav file\n\r");
-    Play_WaveFileLoop(Sound1,wavfile1,Positions);
+    Play_WaveFileLoop(Sound1,wavfile1,wavfile2, Positions);
     printf("finished playing Wav file\n\r");
 
 
@@ -586,7 +598,7 @@
 
 
 
-void Play_WaveFileLoop(classSoundFile Sound1, FILE *wavfile1, classPositionIndicators Positions)
+void Play_WaveFileLoop(classSoundFile Sound1, FILE *wavfile1, FILE* wavfile2, classPositionIndicators Positions)
 {
     while(1) { //might have to change this to a while(1) loop?
 
@@ -599,19 +611,20 @@
             slice1 = Positions.notch_start_pts[NotchingSet.Notch];
             fseek(wavfile1,Positions.notch_start_pts[NotchingSet.Notch],SEEK_SET);
         }
-
-        if(NotchingSet.Notch > 1) {
-
+    if(TransitionFlag)
+    {
+      
+            //NOTCH 1
             fseek(wavfile1,Positions.notch_position_indicators[NotchingSet.Notch],SEEK_SET);
             fread(slice_buf1, Sound1.FileInfo.FileFormat.block_align,1,wavfile1);
             data_sptr1=(short *)slice_buf1;
             Positions.notch_position_indicators[NotchingSet.Notch] = Positions.notch_position_indicators[NotchingSet.Notch] + 2;
             //increment up the position indicator!
             
-            
+            //NOTCH 2
             fseek(wavfile1,Positions.notch_position_indicators[NotchingSet.Notch - 1],SEEK_SET);
-            fread(slice_buf2, Sound1.FileInfo.FileFormat.block_align,1,wavfile1);
-            data_sptr2=(short *)slice_buf2;
+            fread(slice_buf3, Sound1.FileInfo.FileFormat.block_align,1,wavfile1);
+            data_sptr3=(short *)slice_buf3;
             Positions.notch_position_indicators[NotchingSet.Notch - 1] = Positions.notch_position_indicators[NotchingSet.Notch - 1] + 2;
             //increment up the position indicator!
             
@@ -620,49 +633,60 @@
 
             {
 
-                fseek(wavfile1,Positions.notch_position_indicators[NotchingSet.NotchTransUp],SEEK_SET);
-                fread(slice_buf3, Sound1.FileInfo.FileFormat.block_align,1,wavfile1);
-                data_sptr3=(short *)slice_buf3;                
-
+                //N1 N2 Transition
+                fseek(wavfile2,Positions.notch_position_indicators[NotchingSet.NotchTransUp],SEEK_SET);
+                fread(slice_buf2, Sound1.FileInfo.FileFormat.block_align,1,wavfile2);
+                data_sptr2=(short *)slice_buf2;                
+                Positions.notch_transitions_position_indicators[NotchingSet.NotchTransUp] = Positions.notch_transitions_position_indicators[NotchingSet.NotchTransUp] + 2;
 
             } else {
+                //N1 N2 Transition
+                fseek(wavfile2,Positions.notch_position_indicators[NotchingSet.NotchTransDown],SEEK_SET);
+                fread(slice_buf2, Sound1.FileInfo.FileFormat.block_align,1,wavfile2);
+                data_sptr2=(short *)slice_buf2;
+                Positions.notch_transitions_position_indicators[NotchingSet.NotchTransUp] = Positions.notch_transitions_position_indicators[NotchingSet.NotchTransUp] + 2;
 
-                fseek(wavfile1,Positions.notch_position_indicators[NotchingSet.NotchTransDown],SEEK_SET);
-                fread(slice_buf3, Sound1.FileInfo.FileFormat.block_align,1,wavfile1);
-                data_sptr3=(short *)slice_buf3;
             }
             
             
-            NotchFadeOut.FadeOut;
+            NotchFadeOut.FadeOut();
             
             if(Positions.notch_transitions_position_indicators[NotchingSet.NotchTransUp] >= (Positions.notch_transitions_start_pts[NotchingSet.NotchTransUp+1] - NotchFadeIn.Length))
             {
                 NotchFadeIn.FadeIn();
                 if(Positions.notch_transitions_position_indicators[NotchingSet.NotchTransUp] >= Positions.notch_transitions_start_pts[NotchingSet.NotchTransUp+1])
                 {
-                    *Sound1.data_sptr = *data_sptr3*NotchFadeIn.FadeCoeff;
+                    *Sound1.data_sptr = *data_sptr2*NotchFadeIn.FadeCoeff;
+                    TransitionFlag = 0;
+                    fseek(wavfile1,Positions.notch_position_indicators[NotchingSet.Notch],SEEK_SET);
                     
                 }    
                 else
                 {
-                    *Sound1.data_sptr = *data_sptr1*NotchFadeOut.FadeCoeff + data_sptr2 + data_sptr3*NotchFadeIn.FadeCoeff;    
+                    *Sound1.data_sptr = *data_sptr1*NotchFadeOut.FadeCoeff + *data_sptr2 + *data_sptr3*NotchFadeIn.FadeCoeff;    
                 }
                 
                 
             }
             else
             {
-                *Sound1.data_sptr = *data_sptr3;
+                *Sound1.data_sptr = *data_sptr1*NotchFadeOut.FadeCoeff + *data_sptr2;
+
                 //include a flag here, to hand over control.  Going to get a bit complicated!!!    
             }
             
             
 
-        } else {
+        
+        
 
+    }
+    else
+    {
             fread(Sound1.FileInfo.slice_buf,Sound1.FileInfo.FileFormat.block_align,1,wavfile1);
             Sound1.data_sptr=(short *)Sound1.FileInfo.slice_buf;     // 16 bit samples
-        }
+        
+    }
 //=============================================================================================
 
 
@@ -712,4 +736,3 @@
 
 
 
-