From 57be2f618081fd5fd47ad8b860387992e3e65693 Mon Sep 17 00:00:00 2001 From: "John M. Wargo" Date: Tue, 28 Nov 2023 17:11:00 -0500 Subject: [PATCH 1/8] applied changes from #75 --- Adafruit_VS1053.cpp | 30 ++++++++++++++++++++++++++---- Adafruit_VS1053.h | 10 ++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/Adafruit_VS1053.cpp b/Adafruit_VS1053.cpp index 5ed9245..cccb35a 100644 --- a/Adafruit_VS1053.cpp +++ b/Adafruit_VS1053.cpp @@ -40,6 +40,7 @@ SIGNAL(TIMER0_COMPA_vect) { myself->feedBuffer(); } #endif volatile boolean feedBufferLock = false; //!< Locks feeding the buffer +boolean _loopPlayback; #if defined(ESP8266) ICACHE_RAM_ATTR @@ -102,6 +103,7 @@ Adafruit_VS1053_FilePlayer::Adafruit_VS1053_FilePlayer(int8_t rst, int8_t cs, playingMusic = false; _cardCS = cardcs; + _loopPlayback = false; } Adafruit_VS1053_FilePlayer::Adafruit_VS1053_FilePlayer(int8_t cs, int8_t dcs, @@ -111,6 +113,7 @@ Adafruit_VS1053_FilePlayer::Adafruit_VS1053_FilePlayer(int8_t cs, int8_t dcs, playingMusic = false; _cardCS = cardcs; + _loopPlayback = false; } Adafruit_VS1053_FilePlayer::Adafruit_VS1053_FilePlayer(int8_t mosi, int8_t miso, @@ -122,6 +125,7 @@ Adafruit_VS1053_FilePlayer::Adafruit_VS1053_FilePlayer(int8_t mosi, int8_t miso, playingMusic = false; _cardCS = cardcs; + _loopPlayback = false; } boolean Adafruit_VS1053_FilePlayer::begin(void) { @@ -174,6 +178,14 @@ boolean Adafruit_VS1053_FilePlayer::stopped(void) { return (!playingMusic && !currentTrack); } +void Adafruit_VS1053_FilePlayer::playbackLoop(boolean loopState) { + _loopPlayback = loopState; +} + +boolean Adafruit_VS1053_FilePlayer::playbackLooped(){ + return _loopPlayback; +} + // Just checks to see if the name ends in ".mp3" boolean Adafruit_VS1053_FilePlayer::isMP3File(const char *fileName) { return (strlen(fileName) > 4) && @@ -297,10 +309,20 @@ void Adafruit_VS1053_FilePlayer::feedBuffer_noLock(void) { int bytesread = currentTrack.read(mp3buffer, VS1053_DATABUFFERLEN); if (bytesread == 0) { - // must be at the end of the file, wrap it up! - playingMusic = false; - currentTrack.close(); - break; + // must be at the end of the file + if (_loopPlayback) { + // play in loop + if (isMP3File(currentTrack.name())) { + currentTrack.seek(mp3_ID3Jumper(currentTrack)); + } else { + currentTrack.seek(0); + } + } else { + // wrap it up! + playingMusic = false; + currentTrack.close(); + break; + } } playData(mp3buffer, bytesread); diff --git a/Adafruit_VS1053.h b/Adafruit_VS1053.h index c642c32..ef5e59b 100644 --- a/Adafruit_VS1053.h +++ b/Adafruit_VS1053.h @@ -387,6 +387,16 @@ class Adafruit_VS1053_FilePlayer : public Adafruit_VS1053 { * @param pause whether or not to pause playback */ void pausePlaying(boolean pause); + /*! + * @brief Set state for playback looping + * @param loopState Sets playback loop state (Note: Only use with startPlayingFile, if used with playFullFile no subsequent code in the sketch executes) + */ + void playbackLoop(boolean loopState); + /*! + * @brief Retrieve playback loop state + * @return Returns true when looped playback is enabled + */ + boolean playbackLooped(); private: void feedBuffer_noLock(void); From 4357fbc7520adf1ff71aa02f1383617513164926 Mon Sep 17 00:00:00 2001 From: "John M. Wargo" Date: Tue, 28 Nov 2023 17:49:49 -0500 Subject: [PATCH 2/8] fixed layout issues (I think) from checks --- Adafruit_VS1053.cpp | 4 +--- Adafruit_VS1053.h | 4 +++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Adafruit_VS1053.cpp b/Adafruit_VS1053.cpp index cccb35a..386498a 100644 --- a/Adafruit_VS1053.cpp +++ b/Adafruit_VS1053.cpp @@ -182,9 +182,7 @@ void Adafruit_VS1053_FilePlayer::playbackLoop(boolean loopState) { _loopPlayback = loopState; } -boolean Adafruit_VS1053_FilePlayer::playbackLooped(){ - return _loopPlayback; -} +boolean Adafruit_VS1053_FilePlayer::playbackLooped(){ return _loopPlayback } // Just checks to see if the name ends in ".mp3" boolean Adafruit_VS1053_FilePlayer::isMP3File(const char *fileName) { diff --git a/Adafruit_VS1053.h b/Adafruit_VS1053.h index ef5e59b..331a220 100644 --- a/Adafruit_VS1053.h +++ b/Adafruit_VS1053.h @@ -389,7 +389,9 @@ class Adafruit_VS1053_FilePlayer : public Adafruit_VS1053 { void pausePlaying(boolean pause); /*! * @brief Set state for playback looping - * @param loopState Sets playback loop state (Note: Only use with startPlayingFile, if used with playFullFile no subsequent code in the sketch executes) + * @param loopState Sets playback loop state (Note: Only use with + * startPlayingFile, if used with playFullFile no subsequent code in the + * sketch executes) */ void playbackLoop(boolean loopState); /*! From a18421d36c66fbe5409e336181969edf9d9d0ba0 Mon Sep 17 00:00:00 2001 From: "John M. Wargo" Date: Tue, 28 Nov 2023 18:18:06 -0500 Subject: [PATCH 3/8] fixed incomplete comment --- Adafruit_VS1053.cpp | 2 +- Adafruit_VS1053.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Adafruit_VS1053.cpp b/Adafruit_VS1053.cpp index c574384..0c91afd 100644 --- a/Adafruit_VS1053.cpp +++ b/Adafruit_VS1053.cpp @@ -182,7 +182,7 @@ void Adafruit_VS1053_FilePlayer::playbackLoop(boolean loopState) { _loopPlayback = loopState; } -boolean Adafruit_VS1053_FilePlayer::playbackLooped(){ return _loopPlayback } +boolean Adafruit_VS1053_FilePlayer::playbackLooped(){ return _loopPlayback } // Just checks to see if the name ends in ".mp3" boolean Adafruit_VS1053_FilePlayer::isMP3File(const char *fileName) { diff --git a/Adafruit_VS1053.h b/Adafruit_VS1053.h index e973ed4..6071dfb 100644 --- a/Adafruit_VS1053.h +++ b/Adafruit_VS1053.h @@ -403,6 +403,7 @@ class Adafruit_VS1053_FilePlayer : public Adafruit_VS1053 { * @return Returns true when looped playback is enabled */ boolean playbackLooped(); + /*! * @brief Determine current playback speed * @return Returns playback speed, i.e. 1 for 1x, 2 for 2x, 3 for 3x */ From e70fb267c6146539851b73298a33f984d46b81fc Mon Sep 17 00:00:00 2001 From: "John M. Wargo" Date: Tue, 28 Nov 2023 18:30:21 -0500 Subject: [PATCH 4/8] Update Adafruit_VS1053.cpp --- Adafruit_VS1053.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adafruit_VS1053.cpp b/Adafruit_VS1053.cpp index 0c91afd..c3a1e86 100644 --- a/Adafruit_VS1053.cpp +++ b/Adafruit_VS1053.cpp @@ -182,7 +182,7 @@ void Adafruit_VS1053_FilePlayer::playbackLoop(boolean loopState) { _loopPlayback = loopState; } -boolean Adafruit_VS1053_FilePlayer::playbackLooped(){ return _loopPlayback } +boolean Adafruit_VS1053_FilePlayer::playbackLooped(){ return _loopPlayback; } // Just checks to see if the name ends in ".mp3" boolean Adafruit_VS1053_FilePlayer::isMP3File(const char *fileName) { From 082227da53e1f5a670e055d569f8130084d85166 Mon Sep 17 00:00:00 2001 From: "John M. Wargo" Date: Tue, 28 Nov 2023 19:05:19 -0500 Subject: [PATCH 5/8] I truly don't understand what the big deal is here. --- Adafruit_VS1053.cpp | 2 +- Adafruit_VS1053.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Adafruit_VS1053.cpp b/Adafruit_VS1053.cpp index c3a1e86..eea525c 100644 --- a/Adafruit_VS1053.cpp +++ b/Adafruit_VS1053.cpp @@ -182,7 +182,7 @@ void Adafruit_VS1053_FilePlayer::playbackLoop(boolean loopState) { _loopPlayback = loopState; } -boolean Adafruit_VS1053_FilePlayer::playbackLooped(){ return _loopPlayback; } +boolean Adafruit_VS1053_FilePlayer::playbackLooped() { return _loopPlayback; } // Just checks to see if the name ends in ".mp3" boolean Adafruit_VS1053_FilePlayer::isMP3File(const char *fileName) { diff --git a/Adafruit_VS1053.h b/Adafruit_VS1053.h index 6071dfb..6a45d16 100644 --- a/Adafruit_VS1053.h +++ b/Adafruit_VS1053.h @@ -393,8 +393,8 @@ class Adafruit_VS1053_FilePlayer : public Adafruit_VS1053 { void pausePlaying(boolean pause); /*! * @brief Set state for playback looping - * @param loopState Sets playback loop state (Note: Only use with - * startPlayingFile, if used with playFullFile no subsequent code in the + * @param loopState Sets playback loop state (Note: Only use with + * startPlayingFile, if used with playFullFile no subsequent code in the * sketch executes) */ void playbackLoop(boolean loopState); From a73e942e0dbe2657bb342db0e0964215dfa95691 Mon Sep 17 00:00:00 2001 From: "John M. Wargo" Date: Tue, 28 Nov 2023 19:20:02 -0500 Subject: [PATCH 6/8] Update Adafruit_VS1053.cpp --- Adafruit_VS1053.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Adafruit_VS1053.cpp b/Adafruit_VS1053.cpp index eea525c..3ddb954 100644 --- a/Adafruit_VS1053.cpp +++ b/Adafruit_VS1053.cpp @@ -40,7 +40,7 @@ SIGNAL(TIMER0_COMPA_vect) { myself->feedBuffer(); } #endif volatile boolean feedBufferLock = false; //!< Locks feeding the buffer -boolean _loopPlayback; +boolean _loopPlayback; //!< internal variable, used to control playback looping #if defined(ESP8266) ICACHE_RAM_ATTR @@ -103,7 +103,7 @@ Adafruit_VS1053_FilePlayer::Adafruit_VS1053_FilePlayer(int8_t rst, int8_t cs, playingMusic = false; _cardCS = cardcs; - _loopPlayback = false; + _loopPlayback = false; } Adafruit_VS1053_FilePlayer::Adafruit_VS1053_FilePlayer(int8_t cs, int8_t dcs, From 885d2b35085f141dac75bb5bc77408b25f87d2b2 Mon Sep 17 00:00:00 2001 From: "John M. Wargo" Date: Tue, 28 Nov 2023 19:28:38 -0500 Subject: [PATCH 7/8] Update Adafruit_VS1053.cpp spaces? Seriously?? Sigh --- Adafruit_VS1053.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adafruit_VS1053.cpp b/Adafruit_VS1053.cpp index 3ddb954..53ee14d 100644 --- a/Adafruit_VS1053.cpp +++ b/Adafruit_VS1053.cpp @@ -40,7 +40,7 @@ SIGNAL(TIMER0_COMPA_vect) { myself->feedBuffer(); } #endif volatile boolean feedBufferLock = false; //!< Locks feeding the buffer -boolean _loopPlayback; //!< internal variable, used to control playback looping +boolean _loopPlayback; //!< internal variable, used to control playback looping #if defined(ESP8266) ICACHE_RAM_ATTR From 25e17deefa804fcab70077b6a716f0826b20e971 Mon Sep 17 00:00:00 2001 From: "John M. Wargo" Date: Tue, 28 Nov 2023 19:38:38 -0500 Subject: [PATCH 8/8] ugh, another space. --- Adafruit_VS1053.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adafruit_VS1053.cpp b/Adafruit_VS1053.cpp index 53ee14d..f486789 100644 --- a/Adafruit_VS1053.cpp +++ b/Adafruit_VS1053.cpp @@ -103,7 +103,7 @@ Adafruit_VS1053_FilePlayer::Adafruit_VS1053_FilePlayer(int8_t rst, int8_t cs, playingMusic = false; _cardCS = cardcs; - _loopPlayback = false; + _loopPlayback = false; } Adafruit_VS1053_FilePlayer::Adafruit_VS1053_FilePlayer(int8_t cs, int8_t dcs,