d

Dependents:   WavePlayer_JM

Fork of wave_player by Steve Ravet

Files at this revision

API Documentation at this revision

Comitter:
jmar7
Date:
Wed Mar 26 18:18:53 2014 +0000
Parent:
1:acc3e18e77ad
Commit message:
v2

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 3af9b368c30c wave_player.cpp
--- a/wave_player.cpp	Tue Jan 18 03:57:27 2011 +0000
+++ b/wave_player.cpp	Wed Mar 26 18:18:53 2014 +0000
@@ -23,6 +23,7 @@
   wave_DAC=_dac;
   wave_DAC->write_u16(32768);        //DAC is 0-3.3V, so idles at ~1.6V
   verbosity=0;
+  volume=0;
 }
 
 //-----------------------------------------------------------------------------
@@ -37,6 +38,11 @@
   verbosity=v;
 }
 
+
+int * wave_player:: getVolume() 
+{
+  return &volume;
+}
 //-----------------------------------------------------------------------------
 // player function.  Takes a pointer to an opened wave file.  The file needs
 // to be stored in a filesystem with enough bandwidth to feed the wave data.
@@ -44,7 +50,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 *ptr)
 {
         unsigned chunk_id,chunk_size,channel;
         unsigned data,samp_int,i;
@@ -129,6 +135,8 @@
 // while 16 and 32 bit wave files use signed data
 //
         for (slice=0;slice<num_slices;slice+=1) {
+          if(*ptr==0)
+            break;
           fread(slice_buf,wav_format.block_align,1,wavefile);
           if (feof(wavefile)) {
             printf("Oops -- not enough slices in the wave file\n");
@@ -204,7 +212,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]*(16-volume)>>4);
     DAC_rptr=(DAC_rptr+1) & 0xff;
   }
 }
diff -r acc3e18e77ad -r 3af9b368c30c wave_player.h
--- a/wave_player.h	Tue Jan 18 03:57:27 2011 +0000
+++ b/wave_player.h	Wed Mar 26 18:18:53 2014 +0000
@@ -43,7 +43,7 @@
  *
  * @param wavefile  A pointer to an opened wave file
  */
-void play(FILE *wavefile);
+void play(FILE *wavefile, bool *ptr);
 
 /** 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,8 +57,9 @@
  * @param v the verbosity level
  */
 void set_verbosity(int v);
-
+int * getVolume();
 private:
+int volume;
 void dac_out(void);
 int verbosity;
 AnalogOut *wave_DAC;