adfasf

Fork of wave_player by Steve Ravet

Files at this revision

API Documentation at this revision

Comitter:
agamemaker
Date:
Mon Apr 11 16:49:39 2016 +0000
Parent:
1:acc3e18e77ad
Commit message:
hello

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 ab8c3f888b64 wave_player.cpp
--- 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;
   }
 }
diff -r acc3e18e77ad -r ab8c3f888b64 wave_player.h
--- a/wave_player.h	Tue Jan 18 03:57:27 2011 +0000
+++ b/wave_player.h	Mon Apr 11 16:49:39 2016 +0000
@@ -43,7 +43,7 @@
  *
  * @param wavefile  A pointer to an opened wave file
  */
-void play(FILE *wavefile);
+void play(FILE *wavefile, bool* play_p);
 
 /** 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
@@ -57,6 +57,7 @@
  * @param v the verbosity level
  */
 void set_verbosity(int v);
+int volume;
 
 private:
 void dac_out(void);