adfasf

Fork of wave_player by Steve Ravet

Revision:
2:ab8c3f888b64
Parent:
0:62c18ade9a60
--- a/wave_player.cpp	Tue Jan 18 03:57:27 2011 +0000
+++ b/wave_player.cpp	Mon Apr 11 16:49:39 2016 +0000
@@ -21,8 +21,9 @@
 wave_player::wave_player(AnalogOut *_dac)
 {
   wave_DAC=_dac;
-  wave_DAC->write_u16(32768);        //DAC is 0-3.3V, so idles at ~1.6V
+  wave_DAC->write_u16(32768);        //DAC is 0-3.3V, so idles at ~1.6V 
   verbosity=0;
+  volume  = 16;
 }
 
 //-----------------------------------------------------------------------------
@@ -44,8 +45,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* play_pt)
 {
+        
         unsigned chunk_id,chunk_size,channel;
         unsigned data,samp_int,i;
         short unsigned dac_data;
@@ -129,6 +131,9 @@
 // while 16 and 32 bit wave files use signed data
 //
         for (slice=0;slice<num_slices;slice+=1) {
+          if(*play_pt == false){
+              break;
+          }
           fread(slice_buf,wav_format.block_align,1,wavefile);
           if (feof(wavefile)) {
             printf("Oops -- not enough slices in the wave file\n");
@@ -139,6 +144,9 @@
           data_wptr=(int *)slice_buf;     // 32 bit samples
           slice_value=0;
           for (channel=0;channel<wav_format.num_channels;channel++) {
+            if(play_pt == false){
+    break;
+}
             switch (wav_format.sig_bps) {
               case 16:
                 if (verbosity)
@@ -204,7 +212,13 @@
 #ifdef VERBOSE
   printf("ISR rdptr %d got %u\n",DAC_rptr,DAC_fifo[DAC_rptr]);
 #endif
-    wave_DAC->write_u16(DAC_fifo[DAC_rptr]);
+    if(volume > 0){
+        wave_DAC->write_u16(((DAC_fifo[DAC_rptr]) * (volume/4+5)) >> 4);
+    }
+    else{
+        wave_DAC->write_u16(0);
+    }
+    
     DAC_rptr=(DAC_rptr+1) & 0xff;
   }
 }