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 29 20:53:01 2019 +0000
Branch:
LargeFile_Tests
Parent:
66:edf370edd21c
Child:
68:55e26c5e837b
Commit message:
WIP - Now contains Nothching up ISR and some other things. The main WaveFileLoop code can now be modified!

Changed in this revision

NotchingDemo.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/NotchingDemo.cpp	Sun Sep 29 20:00:41 2019 +0000
+++ b/NotchingDemo.cpp	Sun Sep 29 20:53:01 2019 +0000
@@ -55,7 +55,16 @@
     float Natural_Exp;
     int LengthSecs;
     int Length;
-
+    void FadeDataInitialise()
+    {
+        DecayFactor = 1.3;
+        FadeIteration = 1;
+        //FadeData.Denom = 11025*FadeData.DecayFactor;
+        Denom = 11025*DecayFactor;
+        Natural_Exp = 2.7183;
+        Length = 11025*LengthSecs;
+        //FadeData.Natural_Exp = 2.7;
+    }
     //member Functions
     float FadeOut(void)
     {
@@ -87,6 +96,36 @@
 };
 
 
+//Do these variables have to be global??  Find out - may be better (safer) to make them local.
+classFade NotchFadeIn;
+classFade NotchFadeOut;
+
+
+//Dont require the class below.  Turns out I had already made a Structure to hold the same information.
+//If in the futre I need to embed functions then I will switch to using this class
+/*
+class classNotchingValue{
+   public:
+
+   int Notch, Previous_Notch;
+   int NotchDirection;
+   int NotchTransUp;
+    classNotchingValue()
+    {
+        Notch = 1;
+        Previous_Notch = 0;
+        NotchDirection = 1;
+        NotchTransUp = 0;
+    }
+
+};
+
+
+
+classNotchingValue NotchingSet;
+
+*/
+
 typedef struct uFMT_STRUCT {
     short comp_code;
     short num_channels;
@@ -103,6 +142,9 @@
     short NotchDirection;
 } Notch_STRUCT;
 
+Notch_STRUCT NotchingSet;
+
+
 typedef struct uDATA_STRUCT {
     unsigned subchunk2_ID;
     unsigned subchunk2_size;
@@ -149,7 +191,7 @@
     int N1N2_start_pt, N2N3_start_pt, N3N4_start_pt, N4N5_start_pt, N5N6_start_pt;
     int N6N7_start_pt, N7N8_start_pt, N8N7_start_pt, N7N6_start_pt, N6N5_start_pt;
     int N5N4_start_pt, N4N3_start_pt, N3N2_start_pt, N2N1_start_pt;
-    
+
     int notch_start_pts [9];
     int notch_position_indicators[9];
     int notch_transitions_start_pts[15];
@@ -190,7 +232,7 @@
         notch_position_indicators[6] = notch6_indicator;
         notch_position_indicators[7] = notch7_indicator;
         notch_position_indicators[8] = notch8_indicator;
-        
+
         N1N2_start_pt = 44;
         N2N3_start_pt = N1N2_start_pt + 73220;
         N3N4_start_pt = N2N3_start_pt + 78164;
@@ -205,8 +247,8 @@
         N4N3_start_pt = N5N4_start_pt + 49692;
         N3N2_start_pt = N4N3_start_pt + 44100;
         N2N1_start_pt = N3N2_start_pt + 58346;
-        
-        
+
+
         notch_transitions_start_pts[1] = N1N2_start_pt;
         notch_transitions_start_pts[2] = N2N3_start_pt;
         notch_transitions_start_pts[3] = N3N4_start_pt;
@@ -221,8 +263,8 @@
         notch_transitions_start_pts[12] = N4N3_start_pt;
         notch_transitions_start_pts[13] = N3N2_start_pt;
         notch_transitions_start_pts[14] = N2N1_start_pt;
-        
-        
+
+
         notch_transitions_position_indicators[1] = N1N2_start_pt;
         notch_transitions_position_indicators[2] = N2N3_start_pt;
         notch_transitions_position_indicators[3] = N3N4_start_pt;
@@ -248,8 +290,9 @@
         NotchingSet.Notch = NotchingSet.Notch + 1;
         NotchingSet.NotchTransUp = NotchingSet.Notch + 7;
         NotchingSet.NotchDirection = 1;
-        FadeDataInitialise(NotchFadeIn);
-        FadeDataInitialise(NotchFadeOut);
+        NotchFadeIn.FadeDataInitialise();
+        NotchFadeOut.FadeDataInitialise();
+        //NotchFadeOut.FadeDataInitialise;
     }
 }
 
@@ -257,12 +300,14 @@
 {
     if(1 < NotchingSet.Notch <= 8) {
         NotchingSet.Notch = NotchingSet.Notch - 1;
-        NotchingSet.NotchTransDown = NotchingSet.Notch + 15;;
+        NotchingSet.NotchTransDown = NotchingSet.Notch + 15;
         NotchingSet.NotchDirection = 0;
-        FadeDataInitialise(NotchFadeIn);
-        FadeDataInitialise(NotchFadeOut);
+        NotchFadeIn.FadeDataInitialise();
+        NotchFadeOut.FadeDataInitialise();
     }
 }
+
+
 int OneOff = 0;
 int notch_flag = 0;
 int i = 0;
@@ -376,6 +421,7 @@
 
 
 //function prototypes
+//classFade FadeDataInitialise(classFade FadeData);
 classSoundFile ReadFileInfo(classSoundFile Sound, FILE * wav_file);
 classSoundFile LoadFileStream(classSoundFile FileInfo, string filename);
 void Play_WaveFile(FILE * my_wav, WAV_FILE_STRUCT FileInfo);
@@ -408,7 +454,14 @@
     printf("Hello i2s has started!");
     i2s.start();
     sampletick.attach(&isr,1.0/sampling_freq);  //1/16000
-    
+
+
+    NotchFadeIn.LengthSecs = 2;
+    NotchFadeOut.LengthSecs = 2;
+
+    NotchFadeIn.FadeDataInitialise();
+    NotchFadeOut.FadeDataInitialise();
+
     classPositionIndicators Positions;
     slice1 = Positions.notch7_start_pt;
     FILE* wavfile1 = fopen("/sd/mydir/SoundDecoder_second/All_eight_notches.wav","rb");
@@ -462,6 +515,7 @@
 
 
 //Function to initialise Data for classFade objects.  Perhaps move this into a constructor for the class?  (class still to be added)
+/*
 classFade FadeDataInitialise(classFade FadeData)
 {
     FadeData.DecayFactor = 1.3;
@@ -473,6 +527,7 @@
     //FadeData.Natural_Exp = 2.7;
     return FadeData;
 }
+*/
 
 
 
@@ -537,16 +592,16 @@
 
 
 //Sound1=======================================================================================
-            if( slice1 == (Positions.notch8_start_pt) ) {
-                slice1 = Positions.notch7_start_pt;
-                fseek(wavfile1,Positions.notch7_start_pt,SEEK_SET);
-            }
+        if( slice1 == (Positions.notch8_start_pt) ) {
+            slice1 = Positions.notch7_start_pt;
+            fseek(wavfile1,Positions.notch7_start_pt,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
+        fread(Sound1.FileInfo.slice_buf,Sound1.FileInfo.FileFormat.block_align,1,wavfile1);
+        Sound1.data_sptr=(short *)Sound1.FileInfo.slice_buf;     // 16 bit samples
 //=============================================================================================
 
-            
+