not sure what happened here but okay
Fork of wave_player by
Revision 2:802c72d59b7a, committed 2016-10-12
- Comitter:
- mvaca3
- Date:
- Wed Oct 12 16:33:25 2016 +0000
- Parent:
- 1:acc3e18e77ad
- Commit message:
- added wave player library
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 802c72d59b7a wave_player.cpp --- a/wave_player.cpp Tue Jan 18 03:57:27 2011 +0000 +++ b/wave_player.cpp Wed Oct 12 16:33:25 2016 +0000 @@ -23,6 +23,8 @@ wave_DAC=_dac; wave_DAC->write_u16(32768); //DAC is 0-3.3V, so idles at ~1.6V verbosity=0; + volume = 1; + isStarted = false; } //----------------------------------------------------------------------------- @@ -129,10 +131,14 @@ // while 16 and 32 bit wave files use signed data // for (slice=0;slice<num_slices;slice+=1) { - fread(slice_buf,wav_format.block_align,1,wavefile); - if (feof(wavefile)) { - printf("Oops -- not enough slices in the wave file\n"); - exit(1); + if (!isStarted) { + break; + } else { + fread(slice_buf,wav_format.block_align,1,wavefile); + if (feof(wavefile)) { + printf("Oops -- not enough slices in the wave file\n"); + exit(1); + } } data_sptr=(short *)slice_buf; // 16 bit samples data_bptr=(unsigned char *)slice_buf; // 8 bit samples @@ -204,7 +210,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])*volume); DAC_rptr=(DAC_rptr+1) & 0xff; } }
diff -r acc3e18e77ad -r 802c72d59b7a wave_player.h --- a/wave_player.h Tue Jan 18 03:57:27 2011 +0000 +++ b/wave_player.h Wed Oct 12 16:33:25 2016 +0000 @@ -37,7 +37,9 @@ * * @param _dac pointer to an AnalogOut object to which the samples are sent. */ +bool isStarted; wave_player(AnalogOut *_dac); +float volume; /** the player function. *