help :(
Dependencies: FFT
Diff: main.cpp
- Revision:
- 10:a259a4a70210
- Parent:
- 9:97abd5e954f1
- Child:
- 11:951bbb0385aa
--- a/main.cpp Fri Dec 04 07:32:34 2020 +0000 +++ b/main.cpp Fri Dec 04 17:17:17 2020 +0000 @@ -27,6 +27,7 @@ int song_data_length; const unsigned short *song_data; bool play = false; +bool song_selected = false; // delete later @@ -114,11 +115,10 @@ float freq = 0; matrix.begin(0x70); - - // for (int a = 0; a < 64; a++) { - + //calculates FFT value of passed in array + //Value scaled down by 4 for visualization freq = sample[1]/4; @@ -149,7 +149,7 @@ } } matrix.writeDisplay(); - Thread::wait(50); + Thread::wait(10); //wait(.15); break; @@ -163,7 +163,7 @@ } } matrix.writeDisplay(); - Thread::wait(50); + Thread::wait(10); //wait(.15); @@ -178,7 +178,7 @@ } } matrix.writeDisplay(); - Thread::wait(50); + Thread::wait(10); //wait(.15); break; @@ -192,7 +192,7 @@ } } matrix.writeDisplay(); - Thread::wait(50); + Thread::wait(10); break; case(5): // CASE OFF @@ -205,7 +205,7 @@ } } matrix.writeDisplay(); - Thread::wait(50); + Thread::wait(10); //wait(.15); break; @@ -213,9 +213,6 @@ break; } - //} - - //pc.printf("done"); } @@ -223,9 +220,12 @@ void display_thread(void const* args) { while(1) { - + + //Buffer which will hold 64 values float buffer[BUFFER_SIZE]; + //index for iteratiing through buffer int buffer_index = 0; + //index for iterating through song array int song_array_index = 0; if(play) { //int num_elements = NUM_ELEMENTS_AROUND_THE_WORLD; @@ -260,13 +260,17 @@ // string song_title = "/sd/" + "" + ".wav"; - if(play == true) { + if(play == true && song_selected == true) { speaker_lock.lock(); FILE *wave_file; dir = "/sd/" + song + ".wav"; file_lock.lock(); wave_file=fopen(dir.c_str(),"r"); + if(wave_file == NULL) + { + pc.printf("Error opening music file\n"); + } file_lock.unlock(); waver.play(wave_file); @@ -303,31 +307,46 @@ if (pc.getc() == '!') { c = pc.getc(); switch(c) { + /* case '1': song = "africa-toto"; break; + */ case '2': song = "around_the_world-atc"; song_data_length = NUM_ELEMENTS_AROUND_THE_WORLD; song_data = data_around_the_world; + song_selected = true; + //play = true; break; + + /* case '3': song = "beautiful_life-ace_of_base"; break; + */ + + case '4': song = "dont_speak-no_doubt"; song_data_length = NUM_ELEMENTS_DONT_SPEAK_NO_DOUBT; song_data = data_dont_speak_no_doubt; + song_selected = true; break; case '5': song = "my-love"; song_data_length = NUM_ELEMENTS_MY_LOVE; song_data = data_my_love; + song_selected = true; break; + + /* case '6': song = "Song1_test"; break; + */ + case 'P': // wave_player plays play = true;