plays wav files
Fork of wave_player by
Diff: wave_player.cpp
- Revision:
- 2:90454b75f0ad
- Parent:
- 0:62c18ade9a60
--- a/wave_player.cpp Tue Jan 18 03:57:27 2011 +0000 +++ b/wave_player.cpp Thu Nov 03 14:43:52 2016 +0000 @@ -15,7 +15,6 @@ #include <stdio.h> #include <wave_player.h> - //----------------------------------------------------------------------------- // constructor -- accepts an mbed pin to use for AnalogOut. Only p18 will work wave_player::wave_player(AnalogOut *_dac) @@ -44,8 +43,9 @@ // 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 &playing, int &_vol ) { + vol = &_vol; unsigned chunk_id,chunk_size,channel; unsigned data,samp_int,i; short unsigned dac_data; @@ -128,7 +128,7 @@ // note that from what I can find that 8 bit wave files use unsigned data, // while 16 and 32 bit wave files use signed data // - for (slice=0;slice<num_slices;slice+=1) { + for (slice=0;slice<num_slices && playing;slice+=1) { fread(slice_buf,wav_format.block_align,1,wavefile); if (feof(wavefile)) { printf("Oops -- not enough slices in the wave file\n"); @@ -204,7 +204,7 @@ #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-*vol)) >> 4 ); DAC_rptr=(DAC_rptr+1) & 0xff; } }