Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed FATFileSystem
WDplayer/WDplayer.cpp@2:964e19f2f3f1, 2019-04-18 (annotated)
- Committer:
- rottenegg
- Date:
- Thu Apr 18 19:47:30 2019 +0000
- Revision:
- 2:964e19f2f3f1
- Child:
- 3:63cdd5cab431
Documented the N5110-Modded and added the WDplayer, a Library that plays 8-Bit Mono-stereo .wav files - However, it has problems running alongside as a Ticker event.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rottenegg | 2:964e19f2f3f1 | 1 | #include "WDplayer.h" |
rottenegg | 2:964e19f2f3f1 | 2 | |
rottenegg | 2:964e19f2f3f1 | 3 | unsigned char *buffer = (unsigned char *)malloc(1); |
rottenegg | 2:964e19f2f3f1 | 4 | |
rottenegg | 2:964e19f2f3f1 | 5 | void WDplayer::intWD(const char *path) { |
rottenegg | 2:964e19f2f3f1 | 6 | //open File |
rottenegg | 2:964e19f2f3f1 | 7 | _fptr = fopen(path,"r"); |
rottenegg | 2:964e19f2f3f1 | 8 | if (_fptr == NULL) { |
rottenegg | 2:964e19f2f3f1 | 9 | std::cerr << "Error File not Found" << std::endl; |
rottenegg | 2:964e19f2f3f1 | 10 | } |
rottenegg | 2:964e19f2f3f1 | 11 | //get info |
rottenegg | 2:964e19f2f3f1 | 12 | unsigned int samplerate; |
rottenegg | 2:964e19f2f3f1 | 13 | fseek(_fptr,24,SEEK_SET); |
rottenegg | 2:964e19f2f3f1 | 14 | fread(&samplerate,4,1,_fptr); |
rottenegg | 2:964e19f2f3f1 | 15 | fseek(_fptr,0,SEEK_END); |
rottenegg | 2:964e19f2f3f1 | 16 | unsigned int len = ftell(_fptr); |
rottenegg | 2:964e19f2f3f1 | 17 | _pwmfreq = (1.0f / samplerate); |
rottenegg | 2:964e19f2f3f1 | 18 | _path = path; |
rottenegg | 2:964e19f2f3f1 | 19 | _length = len - 44; |
rottenegg | 2:964e19f2f3f1 | 20 | _fptr = NULL; |
rottenegg | 2:964e19f2f3f1 | 21 | _tck = 0; |
rottenegg | 2:964e19f2f3f1 | 22 | }; |
rottenegg | 2:964e19f2f3f1 | 23 | |
rottenegg | 2:964e19f2f3f1 | 24 | void WDplayer::WDplay(PwmOut &dac) { |
rottenegg | 2:964e19f2f3f1 | 25 | _fptr = fopen(_path,"r"); |
rottenegg | 2:964e19f2f3f1 | 26 | fseek(_fptr,44,SEEK_SET); |
rottenegg | 2:964e19f2f3f1 | 27 | //sampling loop _ source of main performance issues |
rottenegg | 2:964e19f2f3f1 | 28 | for (_tck = _length; _tck > 1; _tck--) { |
rottenegg | 2:964e19f2f3f1 | 29 | fread(buffer,1,1,_fptr); |
rottenegg | 2:964e19f2f3f1 | 30 | dac.write((float)buffer[0] / 255.00f); |
rottenegg | 2:964e19f2f3f1 | 31 | wait(_pwmfreq / 2.0f); //I dont like this & Playback present here |
rottenegg | 2:964e19f2f3f1 | 32 | } |
rottenegg | 2:964e19f2f3f1 | 33 | _fptr = NULL; |
rottenegg | 2:964e19f2f3f1 | 34 | _tck = 0; |
rottenegg | 2:964e19f2f3f1 | 35 | }; |
rottenegg | 2:964e19f2f3f1 | 36 | |
rottenegg | 2:964e19f2f3f1 | 37 | void WDplayer::WDtck(PwmOut &dac) { |
rottenegg | 2:964e19f2f3f1 | 38 | if (_fptr == NULL) { |
rottenegg | 2:964e19f2f3f1 | 39 | _fptr = fopen(_path,"r"); |
rottenegg | 2:964e19f2f3f1 | 40 | fseek(_fptr,44,SEEK_SET); |
rottenegg | 2:964e19f2f3f1 | 41 | } |
rottenegg | 2:964e19f2f3f1 | 42 | //sampling loop |
rottenegg | 2:964e19f2f3f1 | 43 | if (_tck == _length) { |
rottenegg | 2:964e19f2f3f1 | 44 | _fptr = NULL; |
rottenegg | 2:964e19f2f3f1 | 45 | _tck = 0; |
rottenegg | 2:964e19f2f3f1 | 46 | } else { |
rottenegg | 2:964e19f2f3f1 | 47 | fread(buffer,1,1,_fptr); |
rottenegg | 2:964e19f2f3f1 | 48 | dac.write( (int)buffer[0] / 255.00 ); |
rottenegg | 2:964e19f2f3f1 | 49 | //wait(_pwmfreq / 2.0f); //I dont like this remove to tick mode |
rottenegg | 2:964e19f2f3f1 | 50 | _tck++; |
rottenegg | 2:964e19f2f3f1 | 51 | } |
rottenegg | 2:964e19f2f3f1 | 52 | }; |
rottenegg | 2:964e19f2f3f1 | 53 | |
rottenegg | 2:964e19f2f3f1 | 54 | float WDplayer::get_pwmfreq() { |
rottenegg | 2:964e19f2f3f1 | 55 | return _pwmfreq; |
rottenegg | 2:964e19f2f3f1 | 56 | }; |