Play/Stop Feature
Fork of wave_player by
Diff: wave_player.cpp
- Revision:
- 2:68f1136f2ea6
- Parent:
- 0:62c18ade9a60
--- a/wave_player.cpp Tue Jan 18 03:57:27 2011 +0000 +++ b/wave_player.cpp Fri May 01 16:50:44 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 *play, int *control) { unsigned chunk_id,chunk_size,channel; unsigned data,samp_int,i; @@ -129,7 +129,20 @@ // while 16 and 32 bit wave files use signed data // for (slice=0;slice<num_slices;slice+=1) { + + playStop = *play; + volumeControl = *control; + if (playStop == false) + { + DAC_on = 0; + tick.detach(); + free(slice_buf); + return; + } fread(slice_buf,wav_format.block_align,1,wavefile); + // while (*play == false) { + // break; + // } if (feof(wavefile)) { printf("Oops -- not enough slices in the wave file\n"); exit(1); @@ -170,6 +183,8 @@ slice_value+=32768; break; } + slice_value = slice_value * (16 - volumeControl); + slice_value = slice_value >> 4; dac_data=(short unsigned)slice_value; if (verbosity) printf("sample %d wptr %d slice_value %d dac_data %u\n",slice,DAC_wptr,(int)slice_value,dac_data);