Plays 8-bit Mono Wav Files for PWM

Files at this revision

API Documentation at this revision

Comitter:
rottenegg
Date:
Wed Apr 17 05:07:15 2019 +0000
Parent:
2:41149130ecf4
Commit message:
Changed the PwmOut for internal pin declaration to external + changed the WDtick to manually wait from main

Changed in this revision

WDplayer.cpp Show annotated file Show diff for this revision Revisions of this file
WDplayer.h Show annotated file Show diff for this revision Revisions of this file
diff -r 41149130ecf4 -r 574fdfeb949e WDplayer.cpp
--- a/WDplayer.cpp	Tue Apr 09 04:32:52 2019 +0000
+++ b/WDplayer.cpp	Wed Apr 17 05:07:15 2019 +0000
@@ -1,6 +1,5 @@
 #include "WDplayer.h"
 
-PwmOut dac(PTC10);
 unsigned char *buffer = (unsigned char *)malloc(1);
 
 void WDplayer::intWD(const char *path) {
@@ -16,27 +15,26 @@
     fseek(_fptr,0,SEEK_END);
     unsigned int len = ftell(_fptr);
     _pwmfreq = (1.0f / samplerate);
-    dac.period(_pwmfreq / (8.0f * 1.75f));//wave control and playback factor control
     _path = path;
     _length = len - 44;
     _fptr = NULL;
     _tck = 0;
 };
 
-void WDplayer::WDplay() {
+void WDplayer::WDplay(PwmOut &dac) {
     _fptr = fopen(_path,"r");
     fseek(_fptr,44,SEEK_SET);
     //sampling loop _ source of main performance issues
     for (_tck = _length; _tck > 1; _tck--) {
         fread(buffer,1,1,_fptr);
-        dac.write((int)buffer[0] / 255.00);
-        wait(_pwmfreq / 1.75f); //I dont like this & Playback present here        
+        dac.write((float)buffer[0] / 255.00f);
+        wait(_pwmfreq / 2.0f); //I dont like this & Playback present here        
     }
     _fptr = NULL;
     _tck = 0;
 };
 
-void WDplayer::WDtck() {
+void WDplayer::WDtck(PwmOut &dac) {
     if (_fptr == NULL) {
     _fptr = fopen(_path,"r");
     fseek(_fptr,44,SEEK_SET);
@@ -48,11 +46,11 @@
     } else {
         fread(buffer,1,1,_fptr);
         dac.write( (int)buffer[0] / 255.00 );
-        wait(_pwmfreq / 1.75f); //I dont like this remove to tick mode
-        
+        //wait(_pwmfreq / 2.0f); //I dont like this remove to tick mode
+        _tck++;
     }
 };
 
-unsigned long WDplayer::get_pwmfreq() {
+float WDplayer::get_pwmfreq() {
     return _pwmfreq;
 };
\ No newline at end of file
diff -r 41149130ecf4 -r 574fdfeb949e WDplayer.h
--- a/WDplayer.h	Tue Apr 09 04:32:52 2019 +0000
+++ b/WDplayer.h	Wed Apr 17 05:07:15 2019 +0000
@@ -57,16 +57,16 @@
     /** Plays the Wav File (mbed waits till File has finished playing)
      *
      */
-    void WDplay();
+    void WDplay(PwmOut &dac);
     /** Plays the Wav File one Sample at a time
      *
      */
-    void WDtck();
+    void WDtck(PwmOut &dac);
     /** Returns the created PWM period.
      *
      *@returns A unsigned long of the Period the PWM is working on
      */
-    unsigned long get_pwmfreq();
+    float get_pwmfreq();
     
     
     private: