old demo that i want to try in mbed studio
Dependencies: mbed SDFileSystem_Copy_of_mbed_version I2S
Diff: NotchingDemo.cpp
- Revision:
- 32:6ee488c97dcc
- Parent:
- 31:0f8c3adf09c3
- Child:
- 33:a75f0a30fbdc
--- a/NotchingDemo.cpp Sun May 26 20:58:26 2019 +0000
+++ b/NotchingDemo.cpp Sun May 26 21:29:41 2019 +0000
@@ -24,6 +24,7 @@
DigitalIn NotchUp(p16);
InterruptIn Horn(p16);
Ticker sampletick;
+Ticker fileswitch_tick;
Ticker BellTick;
Ticker EdTick;
Ticker TickFadeOut;
@@ -209,7 +210,7 @@
int BellFlag = 0;
int BellFlag2 = 0;
int FadeFlag = 0;
-int DualEngineFlag = 0;
+int FileSwitchFlag = 0;
short value[1];
@@ -231,6 +232,7 @@
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;
@@ -242,6 +244,8 @@
//short *data_sptr_bell = 0;
short *data_sptr_ed = 0;
short *data_sptr_startup = 0;
+FILE *StartupWav;
+FILE *N3Wav;
void flip()
{
led2 = !led2;
@@ -286,12 +290,12 @@
}
-void N2SoundIsr()
+void FileSwitch_isr()
{
- DualEngineFlag = 1;
- fseek(N2Wav,44,SEEK_SET);
- fseek(HornWav,44,SEEK_SET);
- //TickFadeOut.detach(&N2SoundIsr);//,5.0);
+ FileSwitchFlag = 1;
+
+ fseek(N3Wav,44,SEEK_SET);
+// fclose(StartupWav);
}
@@ -317,6 +321,7 @@
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***************************
@@ -354,7 +359,7 @@
void Play_WaveFileLoop(classSoundFile Sounds[], Notch_STRUCT NotchingSet);
int main()
{
- //LocalFileSystem local("local");
+
NotchUp.mode(PullUp);
@@ -362,71 +367,102 @@
WAV_FILE_STRUCT WavInfo_Idle;
pc.printf("Beginning of program\n");
- FILE *StartupWav;
+
FILE *IdleWav;
- DIR *dir;
- dirent *ent;
- int iterator = 0;
-
-
- printf("Directory is about to be opened? Still dont really Get this concept\n\r");
- //if i try to open folder SoundDecoder2, it gets stuck after file 13... WHY
- if ((dir = opendir ("/sd/mydir/SoundDecoder_second")) != NULL) {
+
- // print all the files and directories within directory
- while ((ent = readdir (dir)) != NULL) {
- //printf("%s\r\n",string(ent->d_name));
- filename[iterator] = (ent->d_name);
- printf("Filename: %s\n\r",filename[iterator]);
- //printf("%s\r\n",filename[iterator]);
- iterator = iterator + 1;
- //printf("%s\r\n", ent->d_name);
- //filenames.push_back(string(dirp->d_name));
- }
- closedir (dir);
- }
+
-
-
- string FileName;
- //vector <classSoundFile> Sound (27);
- const char* FOLDER;
-
+ printf("About to Start ReadFileInfo Operations\n\r");
+ /*
+ FILE* mywav1 = fopen("/sd/mydir/SoundDecoder_second/01.wav","rb");
+ if(mywav1 == NULL){
+ printf("Cannot Open mywav1\n\r");
+ }
+ FILE* mywav2 = fopen("/sd/mydir/SoundDecoder_second/02.wav","rb");
+ if(mywav2 == NULL){
+ printf("Cannot Open mywav2\n\r");
+ }
+ FILE* mywav3 = fopen("/sd/mydir/SoundDecoder_second/03.wav","rb");
+ if(mywav3 == NULL){
+ printf("Cannot Open mywav3\n\r");
+ }
+ FILE* mywav4 = fopen("/sd/mydir/SoundDecoder_second/04.wav","rb");
+ if(mywav4 == NULL){
+ printf("Cannot Open mywav4\n\r");
+ }
- int aaa = 0;
- string folder = RootFolder + filename[0];
- FOLDER = folder.c_str();
+ FILE* mywav5 = fopen("/sd/mydir/SoundDecoder_second/01.wav","rb");
+ if(mywav5 == NULL){
+ printf("Cannot Open mywav5\n\r");
+ }
+ FILE* mywav6 = fopen("/sd/mydir/SoundDecoder_second/01.wav","rb");
+ if(mywav6 == NULL){
+ printf("Cannot Open mywav6\n\r");
+ }
+ FILE* mywav7 = fopen("/sd/mydir/SoundDecoder_second/01.wav","rb");
+ if(mywav7 == NULL){
+ printf("Cannot Open mywav7\n\r");
+ }
+ FILE* mywav8 = fopen("/sd/mydir/SoundDecoder_second/01.wav","rb");
+ if(mywav8 == NULL){
+ printf("Cannot Open mywav8\n\r");
+ }
+ FILE* mywav9 = fopen("/sd/mydir/SoundDecoder_second/01.wav","rb");
+ if(mywav9 == NULL){
+ printf("Cannot Open mywav9\n\r");
+ }
+ FILE* mywav10 = fopen("/sd/mydir/SoundDecoder_second/01.wav","rb");
+ if(mywav10 == NULL){
+ printf("Cannot Open mywav10\n\r");
+ }
+ FILE* mywav11= fopen("/sd/mydir/SoundDecoder_second/01.wav","rb");
+ if(mywav11 == NULL){
+ printf("Cannot Open mywav11\n\r");
+ }
+ FILE* mywav12 = fopen("/sd/mydir/SoundDecoder_second/01.wav","rb");
+ if(mywav12 == NULL){
+ printf("Cannot Open mywav12\n\r");
+ }
+ FILE* mywav13 = fopen("/sd/mydir/SoundDecoder_second/01.wav","rb");
+ if(mywav13 == NULL){
+ printf("Cannot Open mywav13\n\r");
+ }
+ FILE* mywav14 = fopen("/sd/mydir/SoundDecoder_second/01.wav","rb");
+ if(mywav14 == NULL){
+ printf("Cannot Open mywav14\n\r");
+ }
- WAV_FILE_STRUCT WavStruct21;
- WAV_FILE_STRUCT WavStruct22;
-
+ */
-
-
+ HeyWav = fopen("/sd/mydir/645Engine/EX_FlangeJoint1_11k_minus12dB.wav","rb");
+ if(HeyWav == NULL) {
+ printf("Cannot Open HeyWav\n\r");
+ }
+
+ N3Wav = fopen("/sd/mydir/SoundDecoder_second/03.wav","rb");
+ if(N3Wav == NULL) {
+ printf("Cannot Open N3Wav\n\r");
+ }
+ WavInfo_N3 = ReadFileInfo(WavInfo_N3,N3Wav);
+ fclose(N3Wav);
- HeyWav = fopen("/sd/mydir/645Engine/EX_FlangeJoint1_11k_minus12dB.wav","rb");
- if(HeyWav == NULL){
- printf("Cannot Open HeyWav\n\r");
- }
-
-
-
printf("About to Read HeyWav\n\r");
-
-
+
+
WavInfo_Hey = ReadFileInfo(WavInfo_Hey,HeyWav);
@@ -447,11 +483,15 @@
printf("Hello i2s has starrted!");
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
timer_open.reset();
- timer_open.start();
+ timer_open.start();
+ N3Wav = fopen("/sd/mydir/SoundDecoder_second/03.wav","rb");
+ if(N3Wav == NULL) {
+ printf("Cannot Open N3Wav\n\r");
+ }
StartupWav = fopen("/sd/mydir/Startup.wav","rb");
timer_open.reset();
printf("It took %d useconds to open file\n\r",timer_open.read_us());
@@ -460,13 +500,18 @@
fseek(StartupWav,44,SEEK_SET);
+ timer_open.reset();
+ timer_open.start();
WavInfo_Startup = ReadFileInfo(WavInfo_Startup,StartupWav);
+ timer_open.stop();
+ printf("It took %d useconds to Read In File Info\n\r",timer_open.read_us());
-
-
+
+
+
printf("about to play wav file\n\r");
- Play_WaveFile(StartupWav,WavInfo_Startup);
+ Play_WaveFileDual(StartupWav,WavInfo_Startup);
printf("finished playing Wav file\n\r");
timer_open.reset();
timer_open.start();
@@ -608,7 +653,48 @@
+void Play_WaveFileDual(FILE * my_wav, WAV_FILE_STRUCT FileInfo)
+{
+ while(slice<FileInfo.num_slices) {
+ if(FileSwitchFlag == 1) {
+ fread(WavInfo_N3.slice_buf,WavInfo_N3.FileFormat.block_align,1,N3Wav);
+ data_sptr=(short*)WavInfo_N3.slice_buf;
+ } else {
+ fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,my_wav);
+ data_sptr=(short *)FileInfo.slice_buf; // 16 bit samples
+ }
+ for (channel=0; channel<FileInfo.FileFormat.num_channels; channel++) {
+ if(flag1 == 1) {
+ Buffer1[place_hold1] = data_sptr[channel];
+ place_hold1 = place_hold1 + 1;
+ if(place_hold1 >= BufferLen) {
+ while(1) {
+ if(flag1 == 0) {
+ break;
+ }
+
+ }
+ }
+
+ } else if(flag2 == 1) {
+ Buffer2[place_hold2] = data_sptr[channel];
+ place_hold2 = place_hold2 + 1;
+ if(place_hold2 >= BufferLen) {
+
+ while(1) {
+ if(flag2 == 0) {
+
+ break;
+ }
+ }
+ }
+ }
+
+ }
+ slice = slice + 1;
+ }
+}
//void Play_WaveFileLoop(FILE * my_wav, WAV_FILE_STRUCT FileInfo)//(classSoundFile Sounds)