This is edited to have volume control

Fork of wave_player by Steve Ravet

Files at this revision

API Documentation at this revision

Comitter:
bkf34
Date:
Wed Mar 11 22:13:26 2015 +0000
Parent:
1:acc3e18e77ad
Commit message:
3/11... 6:13PM

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
--- a/wave_player.cpp	Tue Jan 18 03:57:27 2011 +0000
+++ b/wave_player.cpp	Wed Mar 11 22:13:26 2015 +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, bool *playpoint)
 {
         unsigned chunk_id,chunk_size,channel;
         unsigned data,samp_int,i;
@@ -54,6 +54,7 @@
         short *data_sptr;
         unsigned char *data_bptr;
         int *data_wptr;
+       
         FMT_STRUCT wav_format;
         long slice,num_slices;
   DAC_wptr=0;
@@ -129,6 +130,10 @@
 // while 16 and 32 bit wave files use signed data
 //
         for (slice=0;slice<num_slices;slice+=1) {
+            if (*playpoint == false)
+            {
+                break;
+            }
           fread(slice_buf,wav_format.block_align,1,wavefile);
           if (feof(wavefile)) {
             printf("Oops -- not enough slices in the wave file\n");
@@ -204,8 +209,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]);
+    wave_DAC->write_u16(((DAC_fifo[DAC_rptr]) * (vol-16)) >> 4);
     DAC_rptr=(DAC_rptr+1) & 0xff;
   }
 }
 
+int* wave_player:: volu()
+{
+return &vol;
+}
+
--- a/wave_player.h	Tue Jan 18 03:57:27 2011 +0000
+++ b/wave_player.h	Wed Mar 11 22:13:26 2015 +0000
@@ -43,7 +43,7 @@
  *
  * @param wavefile  A pointer to an opened wave file
  */
-void play(FILE *wavefile);
+void play(FILE *wavefile, bool *playpoint);
 
 /** 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,7 +57,7 @@
  * @param v the verbosity level
  */
 void set_verbosity(int v);
-
+int* volu();
 private:
 void dac_out(void);
 int verbosity;
@@ -67,6 +67,7 @@
 short DAC_wptr;
 volatile short DAC_rptr;
 short DAC_on;
+int vol;
 };