Play/Stop Feature
Fork of wave_player by
Revision 2:68f1136f2ea6, committed 2015-05-01
- Comitter:
- anevil14
- Date:
- Fri May 01 16:50:44 2015 +0000
- Parent:
- 1:acc3e18e77ad
- Commit message:
- The Wave Player is interrupted when a pushbutton is pressed
Changed in this revision
wave_player.cpp | Show annotated file Show diff for this revision Revisions of this file |
wave_player.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r acc3e18e77ad -r 68f1136f2ea6 wave_player.cpp --- 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);
diff -r acc3e18e77ad -r 68f1136f2ea6 wave_player.h --- a/wave_player.h Tue Jan 18 03:57:27 2011 +0000 +++ b/wave_player.h Fri May 01 16:50:44 2015 +0000 @@ -43,8 +43,7 @@ * * @param wavefile A pointer to an opened wave file */ -void play(FILE *wavefile); - +void play(FILE *wavefile, bool *play, int *control); /** Set the printf verbosity of the wave player. A nonzero verbosity level * will put wave_player in a mode where the complete contents of the wave * file are echoed to the screen, including header values, and including @@ -67,6 +66,9 @@ short DAC_wptr; volatile short DAC_rptr; short DAC_on; + +bool playStop; +int volumeControl; };