for alarm program
Fork of wave_player by
Diff: wave_player.cpp
- Revision:
- 2:69c7fc62c0ef
- Parent:
- 0:62c18ade9a60
--- a/wave_player.cpp Tue Jan 18 03:57:27 2011 +0000 +++ b/wave_player.cpp Tue Dec 02 15:19:55 2014 +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, volatile bool *play_ptr /*, volatile int *volume_ptr //JJH*/) { unsigned chunk_id,chunk_size,channel; unsigned data,samp_int,i; @@ -67,7 +67,7 @@ fread(&chunk_id,4,1,wavefile); fread(&chunk_size,4,1,wavefile); - while (!feof(wavefile)) { + while (!feof(wavefile) && *play_ptr == true) { if (verbosity) printf("Read chunk ID 0x%x, size 0x%x\n",chunk_id,chunk_size); switch (chunk_id) { @@ -129,6 +129,8 @@ // while 16 and 32 bit wave files use signed data // for (slice=0;slice<num_slices;slice+=1) { + if(*play_ptr == false) + break; fread(slice_buf,wav_format.block_align,1,wavefile); if (feof(wavefile)) { printf("Oops -- not enough slices in the wave file\n"); @@ -173,7 +175,11 @@ 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); - DAC_fifo[DAC_wptr]=dac_data; + + // Scale data according to volume + // dac_data = (dac_data * (16 - *volume_ptr)) / 16; //JJH + DAC_fifo[DAC_wptr]= dac_data; + DAC_wptr=(DAC_wptr+1) & 0xff; while (DAC_wptr==DAC_rptr) { }