This is edited to have volume control
Fork of wave_player by
Diff: wave_player.cpp
- Revision:
- 2:c189a55454f1
- Parent:
- 0:62c18ade9a60
--- a/wave_player.cpp Tue Jan 18 03:57:27 2011 +0000 +++ b/wave_player.cpp Wed Mar 11 22:13:26 2015 +0000 @@ -44,7 +44,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, bool *playpoint) { unsigned chunk_id,chunk_size,channel; unsigned data,samp_int,i; @@ -54,6 +54,7 @@ short *data_sptr; unsigned char *data_bptr; int *data_wptr; + FMT_STRUCT wav_format; long slice,num_slices; DAC_wptr=0; @@ -129,6 +130,10 @@ // while 16 and 32 bit wave files use signed data // for (slice=0;slice<num_slices;slice+=1) { + if (*playpoint == false) + { + break; + } fread(slice_buf,wav_format.block_align,1,wavefile); if (feof(wavefile)) { printf("Oops -- not enough slices in the wave file\n"); @@ -204,8 +209,13 @@ #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]) * (vol-16)) >> 4); DAC_rptr=(DAC_rptr+1) & 0xff; } } +int* wave_player:: volu() +{ +return &vol; +} +