A version of the mbed waveplayer, but setup for the mbed application board PWM speaker and audio out jack

Dependents:   AppBoard_Waveplayer mbed_blinky LED_effects_w_sound ECE4180Lab3_RTOS ... more

Fork of wave_player by Steve Ravet

Files at this revision

API Documentation at this revision

Comitter:
4180_1
Date:
Fri Nov 01 15:24:51 2013 +0000
Parent:
1:acc3e18e77ad
Commit message:
Application board waveplayer demo
; Reads wav file from USB and outputs to speaker and audio out jack

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 b1cea7afcfd2 wave_player.cpp
--- a/wave_player.cpp	Tue Jan 18 03:57:27 2011 +0000
+++ b/wave_player.cpp	Fri Nov 01 15:24:51 2013 +0000
@@ -18,10 +18,14 @@
 
 //-----------------------------------------------------------------------------
 // constructor -- accepts an mbed pin to use for AnalogOut.  Only p18 will work
-wave_player::wave_player(AnalogOut *_dac)
-{
+wave_player::wave_player(AnalogOut *_dac, PwmOut *_pwm)
+{  
+
+    
+  wave_PWM= _pwm;  
   wave_DAC=_dac;
   wave_DAC->write_u16(32768);        //DAC is 0-3.3V, so idles at ~1.6V
+  *wave_PWM=32768;
   verbosity=0;
 }
 
@@ -204,7 +208,10 @@
 #ifdef VERBOSE
   printf("ISR rdptr %d got %u\n",DAC_rptr,DAC_fifo[DAC_rptr]);
 #endif
-    wave_DAC->write_u16(DAC_fifo[DAC_rptr]);
+    //scale down Analog voltage by 8 for PC speakers
+    wave_DAC->write_u16(DAC_fifo[DAC_rptr]>>3);
+    //Output to onboard speaker using PWM (Class D Audio Amp!)
+    wave_PWM->write(float(DAC_fifo[DAC_rptr]/65536.0));
     DAC_rptr=(DAC_rptr+1) & 0xff;
   }
 }
diff -r acc3e18e77ad -r b1cea7afcfd2 wave_player.h
--- a/wave_player.h	Tue Jan 18 03:57:27 2011 +0000
+++ b/wave_player.h	Fri Nov 01 15:24:51 2013 +0000
@@ -37,7 +37,7 @@
  *
  * @param _dac pointer to an AnalogOut object to which the samples are sent.
  */
-wave_player(AnalogOut *_dac);
+wave_player(AnalogOut *_dac, PwmOut *_pwm);
 
 /** the player function.
  *
@@ -62,6 +62,7 @@
 void dac_out(void);
 int verbosity;
 AnalogOut *wave_DAC;
+PwmOut *wave_PWM;
 Ticker tick;
 unsigned short DAC_fifo[256];
 short DAC_wptr;