Wave Player
Dependents: Capacitive_Touch_Sensor_MP3_Player
Fork of wave_player by
Diff: wave_player.cpp
- Revision:
- 2:87acbc2d0023
- Parent:
- 0:62c18ade9a60
diff -r acc3e18e77ad -r 87acbc2d0023 wave_player.cpp --- a/wave_player.cpp Tue Jan 18 03:57:27 2011 +0000 +++ b/wave_player.cpp Mon Nov 21 21:13:54 2016 +0000 @@ -14,8 +14,7 @@ #include <mbed.h> #include <stdio.h> #include <wave_player.h> - - +int g_volume = 0; //----------------------------------------------------------------------------- // constructor -- accepts an mbed pin to use for AnalogOut. Only p18 will work wave_player::wave_player(AnalogOut *_dac) @@ -44,7 +43,7 @@ // SDcard filesystem can be hotrodded by increasing the SPI frequency it uses // internally. //----------------------------------------------------------------------------- -void wave_player::play(FILE *wavefile) +void wave_player::play(FILE *wavefile, int *startStop, int *volume) { unsigned chunk_id,chunk_size,channel; unsigned data,samp_int,i; @@ -56,6 +55,7 @@ int *data_wptr; FMT_STRUCT wav_format; long slice,num_slices; + DAC_wptr=0; DAC_rptr=0; for (i=0;i<256;i+=2) { @@ -134,6 +134,13 @@ printf("Oops -- not enough slices in the wave file\n"); exit(1); } + //exit when user stops song + if (*startStop == 0){ + break; + } + //pass volume to dac_out + g_volume = *volume; + data_sptr=(short *)slice_buf; // 16 bit samples data_bptr=(unsigned char *)slice_buf; // 8 bit samples data_wptr=(int *)slice_buf; // 32 bit samples @@ -194,6 +201,7 @@ } fread(&chunk_id,4,1,wavefile); fread(&chunk_size,4,1,wavefile); + } } @@ -204,7 +212,8 @@ #ifdef VERBOSE printf("ISR rdptr %d got %u\n",DAC_rptr,DAC_fifo[DAC_rptr]); #endif - wave_DAC->write_u16(DAC_fifo[DAC_rptr]); + + wave_DAC->write_u16((DAC_fifo[DAC_rptr]*(16 - g_volume))>>4); DAC_rptr=(DAC_rptr+1) & 0xff; } }