amended wave player

Fork of wave_player_appbd by jim hamblen

Files at this revision

API Documentation at this revision

Comitter:
niv17
Date:
Thu Apr 09 20:23:37 2015 +0000
Parent:
2:b1cea7afcfd2
Commit message:
check code. find how to fix the buffer.

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	Fri Nov 01 15:24:51 2013 +0000
+++ b/wave_player.cpp	Thu Apr 09 20:23:37 2015 +0000
@@ -14,11 +14,11 @@
 #include <mbed.h>
 #include <stdio.h>
 #include <wave_player.h>
-
+//Serial terminal(USBTX,USBRX);
 
 //-----------------------------------------------------------------------------
 // constructor -- accepts an mbed pin to use for AnalogOut.  Only p18 will work
-wave_player::wave_player(AnalogOut *_dac, PwmOut *_pwm)
+wave_player::wave_player(AnalogOut *_dac, PwmOut *_pwm, unsigned short * waveArray)
 {  
 
     
@@ -27,6 +27,7 @@
   wave_DAC->write_u16(32768);        //DAC is 0-3.3V, so idles at ~1.6V
   *wave_PWM=32768;
   verbosity=0;
+  wavebuf = waveArray;
 }
 
 //-----------------------------------------------------------------------------
@@ -41,6 +42,8 @@
   verbosity=v;
 }
 
+
+
 //-----------------------------------------------------------------------------
 // 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.
@@ -48,6 +51,9 @@
 // SDcard filesystem can be hotrodded by increasing the SPI frequency it uses
 // internally.
 //-----------------------------------------------------------------------------
+
+
+
 void wave_player::play(FILE *wavefile)
 {
         unsigned chunk_id,chunk_size,channel;
@@ -118,8 +124,10 @@
 // starting up ticker to write samples out -- no printfs until tick.detach is called
         if (verbosity)
           tick.attach_us(this,&wave_player::dac_out, 500000); 
-        else
+        else{
+          //wavebuf[DAC_rptr] = DAC_fifo[DAC_rptr];
           tick.attach_us(this,&wave_player::dac_out, samp_int); 
+          }
         DAC_on=1; 
 
 // start reading slices, which contain one sample each for however many channels
@@ -199,20 +207,35 @@
     fread(&chunk_id,4,1,wavefile);
     fread(&chunk_size,4,1,wavefile);
   }
+  printf("\r\n********************END OF FILE*************\n");
 }
 
 
 void wave_player::dac_out()
 {
+
   if (DAC_on) {
 #ifdef VERBOSE
   printf("ISR rdptr %d got %u\n",DAC_rptr,DAC_fifo[DAC_rptr]);
 #endif
     //scale down Analog voltage by 8 for PC speakers
-    wave_DAC->write_u16(DAC_fifo[DAC_rptr]>>3);
+    wave_DAC->write_u16(DAC_fifo[DAC_rptr]>>3);                  // --removed
     //Output to onboard speaker using PWM (Class D Audio Amp!)
-    wave_PWM->write(float(DAC_fifo[DAC_rptr]/65536.0));
+    wave_PWM->write(float(DAC_fifo[DAC_rptr]/65536.0));        //   --removed
+  
+   
     DAC_rptr=(DAC_rptr+1) & 0xff;
   }
+  
+  
+
+   
 }
 
+void wave_player::getFIFO(unsigned short * buf){
+    printf("\n*******PRINT FIFO********\r\n");
+ //  buf = DAC_fifo;
+     for(int i =0; i<256; i++)
+       buf[i] = DAC_fifo[i];
+     printf("\n*******END OF FIFO********\r\n");
+}
\ No newline at end of file
--- a/wave_player.h	Fri Nov 01 15:24:51 2013 +0000
+++ b/wave_player.h	Thu Apr 09 20:23:37 2015 +0000
@@ -1,5 +1,5 @@
 #include <mbed.h>
-
+//Serial terminal(USBTX,USBRX);
 typedef struct uFMT_STRUCT {
   short comp_code;
   short num_channels;
@@ -37,7 +37,7 @@
  *
  * @param _dac pointer to an AnalogOut object to which the samples are sent.
  */
-wave_player(AnalogOut *_dac, PwmOut *_pwm);
+wave_player(AnalogOut *_dac, PwmOut *_pwm, unsigned  short * waveArray);
 
 /** the player function.
  *
@@ -57,12 +57,13 @@
  * @param v the verbosity level
  */
 void set_verbosity(int v);
-
+void getFIFO(unsigned short *);
 private:
 void dac_out(void);
 int verbosity;
 AnalogOut *wave_DAC;
 PwmOut *wave_PWM;
+unsigned short * wavebuf;
 Ticker tick;
 unsigned short DAC_fifo[256];
 short DAC_wptr;