old demo that i want to try in mbed studio
Dependencies: mbed SDFileSystem_Copy_of_mbed_version I2S
Revision 50:78ded157e9bb, committed 2019-09-09
- Comitter:
- roryhand
- Date:
- Mon Sep 09 21:18:27 2019 +0000
- Parent:
- 49:ce6b36eb0d88
- Child:
- 51:dab013a902bd
- Commit message:
- Added in appropriate stuff. Yet it does not work yet. Sounds terrible...
Changed in this revision
| NotchingDemo.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/NotchingDemo.cpp Mon Sep 09 21:06:07 2019 +0000
+++ b/NotchingDemo.cpp Mon Sep 09 21:18:27 2019 +0000
@@ -336,7 +336,8 @@
printf("Cannot Open wavfile2\n\r");
}
fseek(wavfile2,44,SEEK_SET);//go to beginning of audio segment
-
+ slice1 = 0;
+ slice2 = 0;
} else {
//BlockFlag = 1;
@@ -350,6 +351,8 @@
printf("Cannot Open wavfile3\n\r");
}
fseek(wavfile3,44,SEEK_SET);//go to beginning of audio segment
+ slice2 = 0;
+ slice3 = 0;
}
FadeFlag = 1;
//printf("We are inside the FadeOut interrupt routine\n\r");
@@ -698,32 +701,10 @@
void Play_WaveFileLoop(classSoundFile Sound1, classSoundFile Sound2, classSoundFile Sound3, FILE *wavfile1, FILE *wavfile2, FILE *wavfile3)
{
+
while(1) { //might have to change this to a while(1) loop?
- //New format!! This should be (roughly) the way that this is done, with the new structures and classes
-
-//Block 1 of code. We need to pass in 3x classSoundFile objects, and 3x FILE* pointer objects.
-//This will allow us to switch between the 3 different files (using "cross-fades") as needed.
- /*Remember that these will need to be global varaibles to work properly*/
-
-
- //make sure we are reading in the correct "notch" here
-
-
-
- /*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);
- }
if(BlockFlag == 0) {
@@ -736,320 +717,188 @@
}
fread(Sound1.FileInfo.slice_buf,Sound1.FileInfo.FileFormat.block_align,1,wavfile1);
Sound1.data_sptr=(short *)Sound1.FileInfo.slice_buf; // 16 bit samples
-
+ }
- else if(BlockFlag == 1) {
- if( slice1 == (Sound1.FileInfo.num_slices-1) ) {
- slice1 = 0;
- fseek(wavfile1,44,SEEK_SET);
- }
- if(feof(wavfile1)) {
- fseek(wavfile1,44,SEEK_SET);
- }
+ else if(BlockFlag == 1) {
+ if( slice1 == (Sound1.FileInfo.num_slices-1) ) {
+ slice1 = 0;
+ fseek(wavfile1,44,SEEK_SET);
+ }
+ if(feof(wavfile1)) {
+ fseek(wavfile1,44,SEEK_SET);
+ }
//Sound1=======================================================================================
- 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
//Sound1=======================================================================================
- if(FadeFlag == 1) {
-
-//Sound2=======================================================================================
- fread(Sound2.FileInfo.slice_buf,Sound2.FileInfo.FileFormat.block_align,1,wavfile2);
- Sound2.data_sptr=(short *)Sound2.FileInfo.slice_buf; // 16 bit samples
-//=============================================================================================
-
+ if(FadeFlag == 1) {
-
-//Sound3=======================================================================================
- fread(Sound3.FileInfo.slice_buf,Sound3.FileInfo.FileFormat.block_align,1,wavfile3);
- Sound3.data_sptr=(short *)Sound3.FileInfo.slice_buf; // 16 bit samples
-//=============================================================================================
- //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
- //no longer require the above section as we are reading in data for Sound3 (above, at beginning of function).
+ //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. //Confirmed 8/9/2019 this works!
- *Sound1.data_sptr = *Sound3.data_sptr*NotchFadeIn.FadeCoeff;//Sound 3 by itself.
- fclose(wavfile1);
- fclose(wavfile2);
- BlockFlag = 1;
- FadeFlag = 0;
- } else {
+ *Sound1.data_sptr = *Sound3.data_sptr*NotchFadeIn.FadeCoeff;//Sound 3 by itself.
+ fclose(wavfile1);
+ fclose(wavfile2);
+ BlockFlag = 1;
+ FadeFlag = 0;
+ } 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;//Sound1 and Sound 2 cross fade
+ *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;//Sound1 and Sound 2 cross fade
}
- /*else
- {
- //not convinced this is needed. Check written logic.
- }*/
+ }
+ /*else
+ {
+ //not convinced this is needed. Check written logic.
+
+ }*/
- } else if(BlockFlag == 2) {
- if( slice3 == (Sound3.FileInfo.num_slices-1) ) {
- slice3 = 0;
- fseek(wavfile3,44,SEEK_SET);
- }
- if(feof(wavfile3)) {
- fseek(wavfile3,44,SEEK_SET);
- }
+ } else if(BlockFlag == 2) {
+ if( slice3 == (Sound3.FileInfo.num_slices-1) ) {
+ slice3 = 0;
+ fseek(wavfile3,44,SEEK_SET);
+ }
+ if(feof(wavfile3)) {
+ fseek(wavfile3,44,SEEK_SET);
+ }
+
+
+//Sound3=======================================================================================
+ fread(Sound3.FileInfo.slice_buf,Sound3.FileInfo.FileFormat.block_align,1,wavfile3);
+ Sound3.data_sptr=(short *)Sound3.FileInfo.slice_buf; // 16 bit samples
+//=============================================================================================
+ if(FadeFlag == 1) {
+ //Sound2=======================================================================================
+ 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
//=============================================================================================
- if(FadeFlag == 1) {
- //Sound2=======================================================================================
- fread(Sound2.FileInfo.slice_buf,Sound2.FileInfo.FileFormat.block_align,1,wavfile2);
- Sound2.data_sptr=(short *)Sound2.FileInfo.slice_buf; // 16 bit samples
- //=============================================================================================
- //Sound1=======================================================================================
- fread(Sound1.FileInfo.slice_buf,Sound1.FileInfo.FileFormat.block_align,1,wavfile1);
- Sound1.data_sptr=(short *)Sound1.FileInfo.slice_buf; // 16 bit samples
- //=============================================================================================
- //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
- //no longer require the above section as we are reading in data for Sound3 (above, at beginning of function).
+ //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. //Confirmed 8/9/2019 this works!
- *Sound1.data_sptr = *Sound1.data_sptr*NotchFadeIn.FadeCoeff;//Sound 1 by itself.
- fclose(wavfile3);
- fclose(wavfile2);
- BlockFlag = 2;
- FadeFlag = 0;
- } else {
+ *Sound1.data_sptr = *Sound1.data_sptr*NotchFadeIn.FadeCoeff;//Sound 1 by itself.
+ fclose(wavfile3);
+ fclose(wavfile2);
+ BlockFlag = 2;
+ FadeFlag = 0;
+ } else {
- *Sound1.data_sptr = *Sound3.data_sptr*NotchFadeOut.FadeCoeff + *Sound2.data_sptr + *Sound1.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 = *Sound3.data_sptr*NotchFadeOut.FadeCoeff + *Sound2.data_sptr;//Sound3 and Sound 2 cross fade
+ *Sound1.data_sptr = *Sound3.data_sptr*NotchFadeOut.FadeCoeff + *Sound2.data_sptr + *Sound1.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 = *Sound3.data_sptr*NotchFadeOut.FadeCoeff + *Sound2.data_sptr;//Sound3 and Sound 2 cross fade
}
- /*else
- {
-
- //Again, not convinced this needs to be here. check written logic
- } */
}
-//=============================================================================================
-
- /*
- //Sound2=======================================================================================
- 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
- //=============================================================================================
- */
-
+ /*else
+ {
- /*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.
-
- /*
- if(FadeFlag) {
- 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
-
+ //Again, not convinced this needs to be here. check written logic
+ } */
- 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();
-
- //Read In the next Notch
-
-
- //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 ) {
-
- //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!
+ }
- *Sound1.data_sptr = *Sound3.data_sptr*NotchFadeIn.FadeCoeff;//Sound 3 by itself.
- fclose(wavfile1);
- fclose(wavfile2);
- BlockFlag = 1;
- FadeFlag = 0;
- } 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;//Sound1 and Sound 2 cross fade
- }
-
- }
-
-
- //********************END OF DATA ASSIGNMENT SECTION*************************************************
-
- else if(BlockFlag == 2) {
- if(feof(wavfile3)) {
- fseek(wavfile3,44,SEEK_SET);
- }
+ /**********************************************************************************************************/
+ /****************************DATA OUTPUT SECTION***********************************************************/
+ /**********************************************************************************************************/
+ for (channel=0; channel<Sound1.FileInfo.FileFormat.num_channels; channel++) {
+ switch (Sound1.FileInfo.FileFormat.sig_bps) {
+ case 16:
+ if(flag1 == 1) {
+ Buffer1[place_hold1] = Sound1.data_sptr[channel];
+ place_hold1 = place_hold1 + 1;
+ if(place_hold1 >= BufferLen) {
+ while(1) {
+ if(flag1 == 0) {
+ break;
+ }//if(flag1 == 0)
- //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)) {
-
-
- //required for calculating the fade In coefficient for Sound3
- NotchFadeIn.FadeCoeff = NotchFadeIn.FadeIn();
-
- //Read In the next Notch
-
-
- //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 ) {
+ }//while(1)
+ }//if(place_hold1 > = BufferLen)
- //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!
+ } else if(flag2 == 1) {
+ Buffer2[place_hold2] = Sound1.data_sptr[channel];
+ place_hold2 = place_hold2 + 1;
+ if(place_hold2 >= BufferLen) {
+ while(1) {
- *Sound1.data_sptr = *Sound1.data_sptr*NotchFadeIn.FadeCoeff;//Sound 1 by itself.
- fclose(wavfile3);
- fclose(wavfile2);
- BlockFlag = 2;
- FadeFlag = 0;
- } else {
-
- *Sound1.data_sptr = *Sound3.data_sptr*NotchFadeOut.FadeCoeff + *Sound2.data_sptr + *Sound1.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.
+ if(flag2 == 0) {
+ break;
}
-
- } else {
- *Sound1.data_sptr = *Sound3.data_sptr*NotchFadeOut.FadeCoeff + *Sound2.data_sptr;//Sound3 and Sound 2 cross fade
}
-
-
}
- }*/ //if(FadeFlag)
+ }
+ }
+ }
+ slice1 = slice1 + 1;
+ slice2 = slice2 + 1;
+ slice3 = slice3 + 1;
- /**********************************************************************************************************/
- /****************************DATA OUTPUT SECTION***********************************************************/
- /**********************************************************************************************************/
- for (channel=0; channel<Sound1.FileInfo.FileFormat.num_channels; channel++) {
- switch (Sound1.FileInfo.FileFormat.sig_bps) {
- case 16:
- if(flag1 == 1) {
- Buffer1[place_hold1] = Sound1.data_sptr[channel];
- place_hold1 = place_hold1 + 1;
- if(place_hold1 >= BufferLen) {
- while(1) {
- if(flag1 == 0) {
- break;
- }//if(flag1 == 0)
+ }
- }//while(1)
- }//if(place_hold1 > = BufferLen)
-
- } else if(flag2 == 1) {
- Buffer2[place_hold2] = Sound1.data_sptr[channel];
- place_hold2 = place_hold2 + 1;
- if(place_hold2 >= BufferLen) {
- while(1) {
-
- if(flag2 == 0) {
- break;
- }
- }
- }
-
- }
- }
- }
- slice1 = slice1 + 1;
- slice2 = slice2 + 1;
- slice3 = slice3 + 1;
- }
- }
+}