plays wav files

Fork of wave_player by Steve Ravet

Files at this revision

API Documentation at this revision

Comitter:
decfrv
Date:
Thu Nov 03 14:43:52 2016 +0000
Parent:
1:acc3e18e77ad
Commit message:
lab4

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	Thu Nov 03 14:43:52 2016 +0000
@@ -15,7 +15,6 @@
 #include <stdio.h>
 #include <wave_player.h>
 
-
 //-----------------------------------------------------------------------------
 // constructor -- accepts an mbed pin to use for AnalogOut.  Only p18 will work
 wave_player::wave_player(AnalogOut *_dac)
@@ -44,8 +43,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 &playing, int &_vol )
 {
+        vol = &_vol;
         unsigned chunk_id,chunk_size,channel;
         unsigned data,samp_int,i;
         short unsigned dac_data;
@@ -128,7 +128,7 @@
 // note that from what I can find that 8 bit wave files use unsigned data,
 // while 16 and 32 bit wave files use signed data
 //
-        for (slice=0;slice<num_slices;slice+=1) {
+        for (slice=0;slice<num_slices && playing;slice+=1) {
           fread(slice_buf,wav_format.block_align,1,wavefile);
           if (feof(wavefile)) {
             printf("Oops -- not enough slices in the wave file\n");
@@ -204,7 +204,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-*vol)) >> 4 );
     DAC_rptr=(DAC_rptr+1) & 0xff;
   }
 }
--- a/wave_player.h	Tue Jan 18 03:57:27 2011 +0000
+++ b/wave_player.h	Thu Nov 03 14:43:52 2016 +0000
@@ -43,7 +43,7 @@
  *
  * @param wavefile  A pointer to an opened wave file
  */
-void play(FILE *wavefile);
+void play(FILE *wavefile, bool &playing, int &vol);
 
 /** 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
@@ -59,7 +59,7 @@
 void set_verbosity(int v);
 
 private:
-void dac_out(void);
+void dac_out();
 int verbosity;
 AnalogOut *wave_DAC;
 Ticker tick;
@@ -67,6 +67,7 @@
 short DAC_wptr;
 volatile short DAC_rptr;
 short DAC_on;
+volatile int *vol;
 };