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
Diff: WDplayer/WDplayer.cpp
- Revision:
- 17:7d4d8905b608
- Parent:
- 12:ff8d26124c38
- Child:
- 18:14e5391beccf
--- a/WDplayer/WDplayer.cpp Tue May 07 21:26:26 2019 +0000 +++ b/WDplayer/WDplayer.cpp Wed May 08 00:30:09 2019 +0000 @@ -17,9 +17,6 @@ void WDplayer::intWD(const char *path, bool allocate) { //Open File and Check _fptr = fopen(path,"r"); - if (_fptr == NULL) { - std::cerr << "Error File not Found" << std::endl; - } //Get Riff Information unsigned int samplerate; fseek(_fptr,24,SEEK_SET); @@ -34,7 +31,6 @@ _tck = 0; lock = false; vtck = 4000; - cache = NULL; _dac->period( _pwmfreq / 4.0f); if (allocate) { cache = (unsigned char*)std::calloc(4000,sizeof(unsigned char)); @@ -93,24 +89,32 @@ _tck = 0; vtck = 0; } else if (vtck > 2001 && !lock) { - //Block 1 Update - for (int i = 0; i <= 2000; i++) { - fread(buffer,1,1,_fptr); - cache[i] = ((unsigned char)buffer[0]); - } - lock = true; - _tck = _tck + 2000; + this->UpdateBlock1(); } else if (vtck < 1999 && lock) { - //Block 2 Update - for (int i = 2001; i <= 4000; i++) { - fread(buffer,1,1,_fptr); - cache[i] = ((int)buffer[0]); - } - lock = false; - _tck = _tck + 2000; + this->UpdateBlock2(); } } +void WDplayer::UpdateBlock2() { + //Block 2 Update + for (int i = 2001; i <= 4000; i++) { + fread(buffer,1,1,_fptr); + cache[i] = ((int)buffer[0]); + } + lock = false; + _tck = _tck + 2000; +} + +void WDplayer::UpdateBlock1() { + //Block 1 Update + for (int i = 0; i <= 2000; i++) { + fread(buffer,1,1,_fptr); + cache[i] = ((unsigned char)buffer[0]); + } + lock = true; + _tck = _tck + 2000; +} + void WDplayer::ISRset() { this->ISRpreload(); ISR.attach(callback(this,&WDplayer::ISRtck),_pwmfreq);