old demo that i want to try in mbed studio

Dependencies:   mbed SDFileSystem_Copy_of_mbed_version I2S

Branch:
LargeFile_Tests
Revision:
59:8e7c25a915a0
Parent:
58:a174e7a8f5f2
Child:
60:36df2997de3d
--- a/NotchingDemo.cpp	Fri Sep 27 19:30:06 2019 +0000
+++ b/NotchingDemo.cpp	Fri Sep 27 19:51:29 2019 +0000
@@ -43,68 +43,6 @@
 I2S i2s(I2S_TRANSMIT, p5, p6, p7);
 SDFileSystem sd(p11, p12, p13, p8, "sd"); // the new pinout that i am using
 
-
-/*struct A {
-  int data;
-  B b;
-};*/
-
-
-
-
-class classFade
-{
-public:
-
-    float powerval;
-    float FadeIteration;
-    float DecayFactor;
-    float Denom;
-    float FadeCoeff;
-    float Natural_Exp;
-    int LengthSecs;
-    int Length;
-
-    //member Functions
-    float FadeOut(void)
-    {
-        powerval = -FadeIteration/Denom;
-        if (FadeIteration >=Length) {
-            FadeCoeff = 0;
-
-        } else {
-            FadeCoeff = (Length - FadeIteration)/Length;
-        }
-        FadeIteration = FadeIteration + 1;
-        return FadeCoeff;
-
-    }
-    float FadeIn(void)
-    {
-        powerval = FadeIteration/Denom;
-        if (FadeIteration >=Length) {
-            FadeCoeff = 1;
-
-        } else {
-            FadeCoeff = FadeIteration/Length;
-        }
-
-        FadeIteration = FadeIteration + 1;
-        return FadeCoeff;
-
-    }
-};
-
-classFade  IdleFadeOut;
-classFade  N2FadeIn;
-
-classFade   NotchFadeOut;
-classFade   NotchFadeIn;
-
-
-
-
-
 typedef struct uFMT_STRUCT {
     short comp_code;
     short num_channels;
@@ -141,6 +79,22 @@
 
 
 }WAV_FILE_STRUCT;*/
+
+
+
+
+
+class classSoundFile
+{
+public:
+
+//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;
+    //classSoundFile(string filename);//this is the constructor
+    //string filename;
+};
 class classPositionIndicators
 {
 public:
@@ -170,37 +124,6 @@
     }
 };
 
-
-
-
-class classSoundFile
-{
-public:
-
-//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;
-    //classSoundFile(string filename);//this is the constructor
-    //string filename;
-};
-
-//class constructor;
-/*classSoundFile::classSoundFile(string filename)
-{
-    //Declare RootFolder and the directory for the appropriate file.
-    //How we index into filename[] from the outside of this class is another
-    //issue...
-    FileInfo.WavFile = fopen("/sd/mydir/645Engine/Startup.wav","rb");
-    fseek(FileInfo.WavFile,20,SEEK_SET);
-    fread(&FileInfo.FileFormat,sizeof(FileInfo.FileFormat),1,FileInfo.WavFile);
-    printf("wav_format.sample_rate: %d\n\r",FileInfo.FileFormat.sample_rate);
-    fread(&FileInfo.FileData,sizeof(FileInfo.FileData),1,FileInfo.WavFile);
-    printf("wav_data.subchunk2_size: %d\n\r",FileInfo.FileData.subchunk2_size);
-    FileInfo.slice_buf = ( char *)malloc(FileInfo.FileFormat.block_align);
-    fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,FileInfo.WavFile);   //This isnt actually required, its just a test
-    FileInfo.num_slices = FileInfo.FileData.subchunk2_size/FileInfo.FileFormat.block_align;
-}*/
 int OneOff = 0;
 int notch_flag = 0;
 int i = 0;
@@ -252,14 +175,7 @@
 
 
 short value[1];
-FILE *HornWav;
-FILE *edsheeran_wav;
-FILE *Startup_wav;
-FILE *IdleN2Wav;
-FILE *N2Wav;
-FILE *BellWav;
-FILE *FlangeWav;
-FILE *HeyWav;
+
 //long long slice_value;
 int slice_value[1];
 
@@ -272,32 +188,6 @@
 classSoundFile Sound2;
 classSoundFile Sound3;
 
-WAV_FILE_STRUCT WavInfo_Horn;
-WAV_FILE_STRUCT WavInfo_IdleN2;
-WAV_FILE_STRUCT WavInfo_N2;
-WAV_FILE_STRUCT WavInfo_Bell;
-WAV_FILE_STRUCT WavInfo_Flange;
-WAV_FILE_STRUCT WavInfo_Hey;
-WAV_FILE_STRUCT WavInfo_N3;
-WAV_FILE_STRUCT WavInfo_Frustration;
-Ticker flipper;
-char * slice_buf_bell;
-char * slice_buf_ed;
-char * slice_buf_startup;
-char * slice_buf_N2;
-Notch_STRUCT NotchingSet;
-//test
-//short *data_sptr_bell = 0;
-short *data_sptr_ed = 0;
-short *data_sptr_startup = 0;
-FILE *StartupWav;
-FILE *N3Wav;
-int temp = 0;
-void flip()
-{
-    led2  = !led2;
-}
-
 
 void isr()
 {
@@ -331,69 +221,16 @@
 
 }
 
-void horn_sound()
-{
-    BellFlag = 1;
-    fseek(HornWav,44,SEEK_SET);
-    fseek(BellWav,44,SEEK_SET);
-    fseek(FlangeWav,44,SEEK_SET);
-    fseek(N2Wav,44,SEEK_SET);
-}
-
-
-void FileSwitch_isr()
-{
-    FileSwitchFlag = 1;
-    temp = 1;
-    /*FILE* testwav = fopen("/sd/mydir/SoundDecoder_second/05.wav","rb");
-    if(N3Wav == NULL) {
-        printf("Cannot Open testwav\n\r");
-    }
-    */
-    fseek(N3Wav,44,SEEK_SET);
-//    fclose(StartupWav);
-}
-
-
-void FadeOutIsr()
-{
-    FadeFlag = 1;
-    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");
-        }
-        */
-    /*
-    FILE* wavfile4 = fopen("/sd/mydir/SoundDecoder_second/04.wav","rb");
-    if(wavfile4 == NULL) {
-        printf("Cannot Open wavfile3\n\r");
-    }
-    */
-    //fseek(wavfile2,44,SEEK_SET);
-    //fseek(wavfile3,44,SEEK_SET);
-    slice2 = 0;
-    slice3 = 0;
-    BlockFlag = 1;
-    //printf("We are inside the FadeOut interrupt routine\n\r");
-
-}
 
 
 
 
 
-classFade FadeDataInitialise(classFade FadeData);
+
+
+
+
+
 
 
 
@@ -402,45 +239,10 @@
 //function prototypes
 classSoundFile ReadFileInfo(classSoundFile Sound, FILE * wav_file);
 classSoundFile LoadFileStream(classSoundFile FileInfo, string filename);
-
-float FadeOut(void);
 void Play_WaveFile(FILE * my_wav, WAV_FILE_STRUCT FileInfo);
 void Play_WaveFileDual(FILE * my_wav, WAV_FILE_STRUCT FileInfo);
-//void Play_WaveFileLoop(FILE * my_wav, WAV_FILE_STRUCT FileInfo);
-//*********************INTERRUPT ROUTINE FOR NOTCHING***************************
-
-void NotchUpIsr()
-{
-    if(1 <= NotchingSet.Notch < 8) {
-
-        NotchingSet.Notch = NotchingSet.Notch + 1;
-        NotchingSet.NotchTransUp = NotchingSet.Notch + 7;
-        NotchingSet.NotchDirection = 1;
-        FadeDataInitialise(NotchFadeIn);
-        FadeDataInitialise(NotchFadeOut);
-    }
-}
+void Play_WaveFileLoop(classSoundFile Sound1, FILE* wavfile1,classPositionIndicators Positions);
 
-void NotchDownIsr()
-{
-    if(1 < NotchingSet.Notch <= 8) {
-        NotchingSet.Notch = NotchingSet.Notch - 1;
-        NotchingSet.NotchTransDown = NotchingSet.Notch + 15;;
-        NotchingSet.NotchDirection = 0;
-        FadeDataInitialise(NotchFadeIn);
-        FadeDataInitialise(NotchFadeOut);
-    }
-}
-
-
-/**********************END OF INTERRUPT ROUTINE FOR NOTCHING*******************/
-
-
-
-
-
-
-void Play_WaveFileLoop(classSoundFile Sound1, FILE* wavfile1,classPositionIndicators Positions);
 int main()
 {
 
@@ -467,27 +269,16 @@
     printf("Hello i2s has started!");
     i2s.start();
     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!!
     
-
-
-
-
-
-
-
-
-
-    TickFadeOut.attach(&FadeOutIsr,10.0);
-
     classPositionIndicators Positions;
     slice1 = 0;
-    FILE* wavfile1 = fopen("/sd/mydir/SoundDecoder_second/All_eight_notches.wav","rb");
+    //FILE* wavfile1 = fopen("/sd/mydir/SoundDecoder_second/All_eight_notches.wav","rb");
+    FILE* wavfile1 = fopen("/sd/mydir/SoundDecoder_second/01.wav","rb");
+    fseek(wavfile1,Positions.notch1_start_pt,SEEK_SET);
     classSoundFile Sound1;
     Sound1 = ReadFileInfo(Sound1, wavfile1);
     printf("about to play wav file\n\r");
-    //Play_WaveFileLoop(Sound1,wavfile1,Positions);
+    Play_WaveFileLoop(Sound1,wavfile1,Positions);
     printf("finished playing Wav file\n\r");
 
 
@@ -523,6 +314,7 @@
     fread(&Sound.FileInfo.FileData,sizeof(Sound.FileInfo.FileData),1,wav_file);
     printf("wav_data.subchunk2_size: %d\n\r",Sound.FileInfo.FileData.subchunk2_size);
     Sound.FileInfo.slice_buf = ( char *)malloc(Sound.FileInfo.FileFormat.block_align);
+    printf("Wav File Block Align (number of bytes per sample!!: %d\n\r", Sound.FileInfo.FileFormat.block_align);
     fread(Sound.FileInfo.slice_buf,Sound.FileInfo.FileFormat.block_align,1,wav_file);   //This isnt actually required, its just a test
     Sound.FileInfo.num_slices = Sound.FileInfo.FileData.subchunk2_size/Sound.FileInfo.FileFormat.block_align;
     //printf("Number of Slices: %d\n\r",FileInfo.num_slices);
@@ -583,7 +375,7 @@
 
 
 
-/*
+
 
 void Play_WaveFileLoop(classSoundFile Sound1, FILE *wavfile1, classPositionIndicators Positions)
 {
@@ -638,16 +430,16 @@
                     }
             }
         }
-        slice1 = slice1 + 1;
+        slice1 = slice1 + 2;//increment up by the number of bytes per Audio data sample!  Makes sense it is 2 bytes, as this is 16-bit data.
         slice2 = slice2 + 1;
         slice3 = slice3 + 1;
     }
 }
 
-*/
-
 
 
 
 
 
+
+