old demo that i want to try in mbed studio
Dependencies: mbed SDFileSystem_Copy_of_mbed_version I2S
Diff: NotchingDemo.cpp
- Revision:
- 48:01490448a05a
- Parent:
- 47:9334a8f54997
- Child:
- 49:ce6b36eb0d88
--- a/NotchingDemo.cpp Sun Sep 08 20:33:59 2019 +0000 +++ b/NotchingDemo.cpp Sun Sep 08 20:53:06 2019 +0000 @@ -33,6 +33,8 @@ Timer NotchTimer; Timer timer_open; +int BlockFlag = 0; + Serial pc(USBTX, USBRX); // tx, rx //FOR DEBUGGING PROGRAM USING GNU SCREEN DigitalOut cs(p8); I2S i2s(I2S_TRANSMIT, p5, p6, p7); @@ -315,9 +317,39 @@ void FadeOutIsr() { + if (BlockFlag == 0) { + BlockFlag = 1; + fseek(wavfile2,44,SEEK_SET); + fseek(wavfile3,44,SEEK_SET); + + } else if(BlockFlag == 1) { + BlockFlag = 2; + fclose(wavfile1); + fclose(wavfile2); + wavfile1 = fopen("/sd/mydir/SoundDecoder_second/03.wav","rb"); + if(wavfile1 == NULL) { + printf("Cannot Open wavfile1\n\r"); + } + wavfile2 = fopen("/sd/mydir/SoundDecoder_second/10.wav","rb"); + if(wavfile2 == NULL) { + printf("Cannot Open wavfile2\n\r"); + } + + } else { + + BlockFlag = 1; + fclose(wavfile2); + fclose(wavfile3); + 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"); + } + } FadeFlag = 1; - fseek(wavfile2,44,SEEK_SET); - fseek(wavfile3,44,SEEK_SET); //printf("We are inside the FadeOut interrupt routine\n\r"); } @@ -406,31 +438,31 @@ timer_open.reset(); timer_open.start(); wavfile1 = fopen("/sd/mydir/SoundDecoder_second/01.wav","rb"); - if(wavfile1 == NULL) { + if(wavfile1 == NULL) { printf("Cannot Open wavfile1\n\r"); } - + timer_open.reset(); printf("It took %d useconds to open file\n\r",timer_open.read_us()); - - + + timer_open.start(); wavfile2 = fopen("/sd/mydir/SoundDecoder_second/09.wav","rb"); - if(wavfile2 == NULL) { + if(wavfile2 == NULL) { printf("Cannot Open wavfile2\n\r"); } timer_open.reset(); printf("It took %d useconds to open file\n\r",timer_open.read_us()); - + timer_open.start(); wavfile3 = fopen("/sd/mydir/SoundDecoder_second/02.wav","rb"); - if(wavfile3 == NULL) { + if(wavfile3 == NULL) { printf("Cannot Open wavfile3\n\r"); } timer_open.reset(); printf("It took %d useconds to open file\n\r",timer_open.read_us()); - - + + Sound1 = ReadFileInfo(Sound1,wavfile1); Sound2 = ReadFileInfo(Sound2,wavfile2); Sound3 = ReadFileInfo(Sound3,wavfile3); @@ -449,29 +481,29 @@ Play_WaveFileLoop(Sound1,Sound2,Sound3,wavfile1,wavfile2,wavfile3); //Play_WaveFileDual(StartupWav,WavInfo_Startup); printf("finished playing Wav file\n\r"); - - + + timer_open.reset(); timer_open.start(); fclose(wavfile1); timer_open.stop(); printf("It took %d useconds to close file\n\r",timer_open.read_us()); - + timer_open.reset(); - timer_open.start(); + timer_open.start(); fclose(wavfile2); timer_open.stop(); - printf("It took %d useconds to close file\n\r",timer_open.read_us()); - - + printf("It took %d useconds to close file\n\r",timer_open.read_us()); + + timer_open.reset(); - timer_open.start(); + timer_open.start(); fclose(wavfile3); timer_open.stop(); printf("It took %d useconds to close file\n\r",timer_open.read_us()); - - - + + + /************************************PLAY WAV FILE LOOP*******************/ //Play_WaveFileLoop(Sound, NotchingSet); /************************************END OF PLAY WAV FILE LOOP*************/ @@ -676,91 +708,95 @@ - /*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.*/ + /*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); - } - if(feof(wavfile1)) { - 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 + if( slice1 == (Sound1.FileInfo.num_slices-1) ) { + slice1 = 0; + fseek(wavfile1,44,SEEK_SET); + } + if(feof(wavfile1)) { + 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 + 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 + fread(Sound3.FileInfo.slice_buf,Sound3.FileInfo.FileFormat.block_align,1,wavfile3); + Sound3.data_sptr=(short *)Sound3.FileInfo.slice_buf; // 16 bit samples //============================================================================================= - /*Block2*/ + /*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; - //We are now performing this section above. + //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; + //We are now performing this section above. if(FadeFlag) { - if(feof(wavfile1)) { - fseek(wavfile1,44,SEEK_SET); - } + if(BlockFlag == 1) { + if(feof(wavfile1)) { + fseek(wavfile1,44,SEEK_SET); + } - //require this to get the fadeout coefficient for Sound1. - NotchFadeOut.FadeCoeff = NotchFadeOut.FadeOut();//compute new FadeOut Coeff value + //require this to get the fadeout coefficient for Sound1. + NotchFadeOut.FadeCoeff = NotchFadeOut.FadeOut();//compute new FadeOut Coeff value - if( ((Sound2.FileInfo.FileData.subchunk2_size) - NotchFadeIn.Length - 2*11025) <= (ftell(wavfile2) + 44)) - { + if( ((Sound2.FileInfo.FileData.subchunk2_size) - NotchFadeIn.Length - 2*11025) <= (ftell(wavfile2) + 44)) { - //required for calculating the fade In coefficient for Sound3 - NotchFadeIn.FadeCoeff = NotchFadeIn.FadeIn(); + //required for calculating the fade In coefficient for Sound3 + NotchFadeIn.FadeCoeff = NotchFadeIn.FadeIn(); - //Read In the next Notch + //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). + /* + 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(wavfile2) + 44) >= Sound2.FileInfo.FileData.subchunk2_size ) { - if( (ftell(wavfile2) + 44) >= Sound2.FileInfo.FileData.subchunk2_size ) { + //need to explicitly test if this notation/syntax works for pointers.... + /*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.*/ /*Confirmed 8/9/2019 this works!*/ - //need to explicitly test if this notation/syntax works for pointers.... - /*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.*/ - *Sound1.data_sptr = *Sound3.data_sptr*NotchFadeIn.FadeCoeff;//Sound 3 by itself. + *Sound1.data_sptr = *Sound3.data_sptr*NotchFadeIn.FadeCoeff;//Sound 3 by itself. + } else { + + *Sound1.data_sptr = *Sound1.data_sptr*NotchFadeOut.FadeCoeff + *Sound2.data_sptr + *Sound3.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 { - *Sound1.data_sptr = *Sound1.data_sptr*NotchFadeOut.FadeCoeff + *Sound2.data_sptr + *Sound3.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. + *Sound1.data_sptr = *Sound1.data_sptr*NotchFadeOut.FadeCoeff + *Sound2.data_sptr;//Sound1 and Sound 2 cross fade } - } else { - *Sound1.data_sptr = *Sound1.data_sptr*NotchFadeOut.FadeCoeff + *Sound2.data_sptr;//Sound1 and Sound 2 cross fade } } - - /********************END OF DATA ASSIGNMENT SECTION*************************************************/