help :(
Dependencies: FFT
Diff: main.cpp
- Revision:
- 9:97abd5e954f1
- Parent:
- 8:24c18eecc442
- Child:
- 10:a259a4a70210
--- a/main.cpp Fri Dec 04 03:48:15 2020 +0000 +++ b/main.cpp Fri Dec 04 07:32:34 2020 +0000 @@ -25,7 +25,7 @@ //string song = "around_the_world-atc"; string song; int song_data_length; -int song_data[]; +const unsigned short *song_data; bool play = false; @@ -116,9 +116,11 @@ // for (int a = 0; a < 64; a++) { + + freq = sample[1]/4; - + //pc.printf("%f\n",freq); @@ -147,7 +149,8 @@ } } matrix.writeDisplay(); - wait(.15); + Thread::wait(50); + //wait(.15); break; case(2): // CASE HIGH @@ -160,7 +163,8 @@ } } matrix.writeDisplay(); - wait(.15); + Thread::wait(50); + //wait(.15); @@ -174,7 +178,8 @@ } } matrix.writeDisplay(); - wait(.15); + Thread::wait(50); + //wait(.15); break; case(4): // CASE LOW @@ -187,7 +192,7 @@ } } matrix.writeDisplay(); - wait(.15); + Thread::wait(50); break; case(5): // CASE OFF @@ -200,7 +205,8 @@ } } matrix.writeDisplay(); - wait(.15); + Thread::wait(50); + //wait(.15); break; default: @@ -220,26 +226,27 @@ float buffer[BUFFER_SIZE]; int buffer_index = 0; - - //int num_elements = NUM_ELEMENTS_AROUND_THE_WORLD; - int num_elements = 16979; - for(int i=0; i<num_elements; ++i ) { - buffer[buffer_index] = song_data[i]; - // pc.printf("%f", buffer[buffer_index]); - buffer_index++; - //pc.printf("%d\n",value); - //buffer_index++; - if(buffer_index == BUFFER_SIZE) { - //fast fourier tranform function here - vRealFFT(buffer, 4); - display_fft(buffer); - buffer_index = 0; - memset(buffer,0,sizeof(buffer)); + int song_array_index = 0; + if(play) { + //int num_elements = NUM_ELEMENTS_AROUND_THE_WORLD; + while(play && song_array_index < song_data_length) { + buffer[buffer_index] = song_data[song_array_index]; + song_array_index++; + // pc.printf("%f", buffer[buffer_index]); + buffer_index++; + //pc.printf("%d\n",value); + //buffer_index++; + if(buffer_index == BUFFER_SIZE) { + //fast fourier tranform function here + vRealFFT(buffer, 4); + display_fft(buffer); + buffer_index = 0; + memset(buffer,0,sizeof(buffer)); + + } } - } - Thread::wait(300); } @@ -253,25 +260,27 @@ // string song_title = "/sd/" + "" + ".wav"; - if(play == true) - { - //speaker_lock.lock(); - FILE *wave_file; - dir = "/sd/" + song + ".wav"; + if(play == true) { + speaker_lock.lock(); + FILE *wave_file; + dir = "/sd/" + song + ".wav"; + + file_lock.lock(); + wave_file=fopen(dir.c_str(),"r"); + file_lock.unlock(); - file_lock.lock(); - wave_file=fopen(dir.c_str(),"r"); - file_lock.unlock(); - - waver.play(wave_file); + waver.play(wave_file); - file_lock.lock(); - fclose(wave_file); - file_lock.unlock(); - //speaker_lock.unlock(); - } + file_lock.lock(); + fclose(wave_file); + file_lock.unlock(); + play = false; + myled = 0; + speaker_lock.unlock(); + } Thread::wait(1000); } + } @@ -322,12 +331,12 @@ case 'P': // wave_player plays play = true; - led =1; + myled =1; break; case 'S': // wave_player stops play = false; - //led = 0; + myled = 0; break; default: break;