Volume correction

Fork of wave_player_appbd by jim hamblen

Revision:
2:b1cea7afcfd2
Parent:
0:62c18ade9a60
Child:
3:cb29173d2fde
--- 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;
   }
 }