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:
Tue Oct 01 20:05:29 2019 +0000
Branch:
LargeFile_Tests
Parent:
76:9535aedba4da
Child:
78:69a0c7a5fbdf
Commit message:
WIP - there is a bug which makes NO SENSE. If i assign data to data_sptr2, then we only hear file 2. But if we dont have this then we only hear file 1.

Changed in this revision

NotchingDemo.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/NotchingDemo.cpp	Tue Oct 01 19:11:57 2019 +0000
+++ b/NotchingDemo.cpp	Tue Oct 01 20:05:29 2019 +0000
@@ -436,7 +436,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, FILE* wavfile2,classPositionIndicators Positions);
+void Play_WaveFileLoop(classSoundFile Sound1, classSoundFile Sound2, FILE* wavfile1, FILE* wavfile2,classPositionIndicators Positions);
 
 int main()
 {
@@ -493,11 +493,11 @@
     Sound2 = ReadFileInfo(Sound2, wavfile2);
     Sound1 = ReadFileInfo(Sound1, wavfile1);
     NotchingSet.Notch = 1;
-    Positions.notch_position_indicators[1] = 44;
+    //Positions.notch_position_indicators[1] = 44;
     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,wavfile2, Positions);
+    Play_WaveFileLoop(Sound1,Sound2, wavfile1,wavfile2, Positions);
     printf("finished playing Wav file\n\r");
 
 
@@ -611,7 +611,7 @@
 
 
 
-void Play_WaveFileLoop(classSoundFile Sound1, FILE *wavfile1, FILE* wavfile2, classPositionIndicators Positions)
+void Play_WaveFileLoop(classSoundFile Sound1, classSoundFile Sound2, FILE *wavfile1, FILE* wavfile2, classPositionIndicators Positions)
 {
     while(1) { //might have to change this to a while(1) loop?
 
@@ -631,57 +631,77 @@
             //NOTCH 1
             //OperationsTimer.reset();
             //OperationsTimer.start();
-            fseek(wavfile1,Positions.notch_position_indicators[NotchingSet.Notch],SEEK_SET);
+            //fpos_t position;
+            //fgetpos(wavfile1,&position);
+            //printf("Positions.notch_position_indicators[NotchingSet.Notch]: %d\n\r",Positions.notch_position_indicators[NotchingSet.Notch]);
+            fseek(wavfile1,Positions.notch_position_indicators[NotchingSet.Notch-1],Positions.notch_position_indicators[NotchingSet.Notch-1]);
+            ////fsetpos(wavfile1, &position);
             //OperationsTimer.stop();
             //printf("It took %d useconds to perform fseek operation.\n\r",OperationsTimer.read_us());
             //printf("We have seeked through the file\n\r");
             
             
-            printf("Size of Sound1.FileInfo.FileFormat.block_align: %d\n\r",Sound1.FileInfo.FileFormat.block_align);
+            //printf("Size of Sound1.FileInfo.FileFormat.block_align: %d\n\r",Sound1.FileInfo.FileFormat.block_align);
             
+            /*
             OperationsTimer.reset();
             OperationsTimer.start();
+            */
             fread(Sound1.FileInfo.slice_buf, Sound1.FileInfo.FileFormat.block_align,1,wavfile1);
+            
+            /*
             OperationsTimer.stop();
             printf("It took %d useconds to perform fread operation.\n\r",OperationsTimer.read_us());
+            */
             //printf("We have now read in 2 bytes of data (i.e. 1 sample)\n\r");
             data_sptr1=(short *)Sound1.FileInfo.slice_buf;
             //printf("We have now cast this data to a short data type\n\r");
-            Positions.notch_position_indicators[NotchingSet.Notch] = Positions.notch_position_indicators[NotchingSet.Notch] + 2;
+            Positions.notch_position_indicators[NotchingSet.Notch-1] = Positions.notch_position_indicators[NotchingSet.Notch-1] + 2;
+            
+            
+            fseek(wavfile2,Positions.notch_transitions_position_indicators[NotchingSet.NotchTransUp],Positions.notch_transitions_position_indicators[NotchingSet.NotchTransUp]);
+            fread(Sound1.FileInfo.slice_buf, Sound1.FileInfo.FileFormat.block_align,1,wavfile2);
+            data_sptr2=(short *)Sound2.FileInfo.slice_buf; 
+            
+            
             //printf("We have incremented up the Positions.notch_position_indicator");
             //increment up the position indicator!
             
             //NOTCH 2
-            fseek(wavfile1,Positions.notch_position_indicators[NotchingSet.Notch - 1],SEEK_SET);
+            /*
+            fseek(wavfile1,Positions.notch_position_indicators[NotchingSet.Notch],Positions.notch_position_indicators[NotchingSet.Notch]);
             fread(Sound1.FileInfo.slice_buf, Sound1.FileInfo.FileFormat.block_align,1,wavfile1);
             data_sptr3=(short *)Sound1.FileInfo.slice_buf;
-            Positions.notch_position_indicators[NotchingSet.Notch - 1] = Positions.notch_position_indicators[NotchingSet.Notch - 1] + 2;
+            Positions.notch_position_indicators[NotchingSet.Notch] = Positions.notch_position_indicators[NotchingSet.Notch] + 2;
+            */
             //increment up the position indicator!
             
-            
+            /*
             if(NotchingSet.NotchDirection)
 
             {
                 //printf("Reached if(NotchingSet.NotchDirection)\n\r");
 
                 //N1 N2 Transition
-                fseek(wavfile2,Positions.notch_position_indicators[NotchingSet.NotchTransUp],SEEK_SET);
+                fseek(wavfile2,Positions.notch_transitions_position_indicators[NotchingSet.NotchTransUp],Positions.notch_transitions_position_indicators[NotchingSet.NotchTransUp]);
                 fread(Sound1.FileInfo.slice_buf, Sound1.FileInfo.FileFormat.block_align,1,wavfile2);
-                data_sptr2=(short *)Sound1.FileInfo.slice_buf;                
+                data_sptr2=(short *)Sound2.FileInfo.slice_buf;                
                 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);
+                fseek(wavfile2,Positions.notch_transitions_position_indicators[NotchingSet.NotchTransDown],Positions.notch_position_indicators[NotchingSet.NotchTransDown]);
                 fread(Sound1.FileInfo.slice_buf, Sound1.FileInfo.FileFormat.block_align,1,wavfile2);
-                data_sptr2=(short *)Sound1.FileInfo.slice_buf;
+                data_sptr2=(short *)Sound2.FileInfo.slice_buf;
                 Positions.notch_transitions_position_indicators[NotchingSet.NotchTransUp] = Positions.notch_transitions_position_indicators[NotchingSet.NotchTransUp] + 2;
 
             }
+            */
+            
             
             
             NotchFadeOut.FadeOut();
-            
+            /*
             if(Positions.notch_transitions_position_indicators[NotchingSet.NotchTransUp] >= (Positions.notch_transitions_start_pts[NotchingSet.NotchTransUp+1] - NotchFadeIn.Length))
             {
                 NotchFadeIn.FadeIn();
@@ -689,7 +709,7 @@
                 {
                     *Sound1.data_sptr = *data_sptr2*NotchFadeIn.FadeCoeff;
                     TransitionFlag = 0;
-                    fseek(wavfile1,Positions.notch_position_indicators[NotchingSet.Notch],SEEK_SET);
+                    fseek(wavfile1,Positions.notch_position_indicators[NotchingSet.Notch],Positions.notch_position_indicators[NotchingSet.Notch]);
                     
                 }    
                 else
@@ -699,12 +719,13 @@
                 
                 
             }
-            else
-            {
-                *Sound1.data_sptr = *data_sptr1*NotchFadeOut.FadeCoeff + *data_sptr2;
-
+            */
+            //else
+            //{
+                //*Sound1.data_sptr = *data_sptr1*NotchFadeOut.FadeCoeff + *data_sptr2;
+                *Sound1.data_sptr = *data_sptr1;// + *data_sptr2;
                 //include a flag here, to hand over control.  Going to get a bit complicated!!!    
-            }
+            //}
             
             
 
@@ -715,14 +736,15 @@
     else
     {
             
-            fseek(wavfile1,Positions.notch_position_indicators[1],SEEK_SET);
+            /*fseek(wavfile1,Positions.notch_position_indicators[1],SEEK_SET);
             OperationsTimer.reset();
             OperationsTimer.start();
+            */
             fread(Sound1.FileInfo.slice_buf,Sound1.FileInfo.FileFormat.block_align,1,wavfile1);
-            OperationsTimer.stop();
+            /*OperationsTimer.stop();
             printf("It took %d useconds to perform fread operation.\n\r",OperationsTimer.read_us());
             Positions.notch_position_indicators[1] = Positions.notch_position_indicators[1] + 2;//i.e. 2 bytes, per sample, for 2-byte (16-bit) data
-            
+            */
             Sound1.data_sptr=(short *)Sound1.FileInfo.slice_buf;     // 16 bit samples
         
     }