From 0fec0f99ca2a9c07cd95168c86b935c0f2931cd5 Mon Sep 17 00:00:00 2001 From: Dan Cogliano Date: Tue, 28 Nov 2023 17:47:44 -0500 Subject: [PATCH] Add fast forward feature to playing sound tracks. (#74) * Added playback speed control (i.e. 1x, 2x, 3x) * updated .h file for playback speed functions * Fixed getPlaySpeed interrupt issue, added comments to new #defines * Fixed comment --- Adafruit_VS1053.cpp | 17 +++++++++++++++++ Adafruit_VS1053.h | 14 ++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/Adafruit_VS1053.cpp b/Adafruit_VS1053.cpp index 5ed9245..2e8b1de 100644 --- a/Adafruit_VS1053.cpp +++ b/Adafruit_VS1053.cpp @@ -307,6 +307,23 @@ void Adafruit_VS1053_FilePlayer::feedBuffer_noLock(void) { } } +// get current playback speed. 0 or 1 indicates normal speed +uint16_t Adafruit_VS1053_FilePlayer::getPlaySpeed() { + noInterrupts(); + sciWrite(VS1053_SCI_WRAMADDR, VS1053_PARA_PLAYSPEED); + uint16_t speed = sciRead(VS1053_SCI_WRAM); + interrupts(); + return speed; +} + +// set playback speed: 0 or 1 for normal speed, 2 for 2x, 3 for 3x, etc. +void Adafruit_VS1053_FilePlayer::setPlaySpeed(uint16_t speed) { + noInterrupts(); + sciWrite(VS1053_SCI_WRAMADDR, VS1053_PARA_PLAYSPEED); + sciWrite(VS1053_SCI_WRAM, speed); + interrupts(); +} + /***************************************************************/ /* VS1053 'low level' interface */ diff --git a/Adafruit_VS1053.h b/Adafruit_VS1053.h index c642c32..a74360f 100644 --- a/Adafruit_VS1053.h +++ b/Adafruit_VS1053.h @@ -107,6 +107,10 @@ typedef volatile RwReg PortReg; //!< Type definition/alias used to specify the 0x0E //!< SCI_AICTRL register 2. Used to access the user's application program #define VS1053_SCI_AICTRL3 \ 0x0F //!< SCI_AICTRL register 3. Used to access the user's application program +#define VS1053_SCI_WRAM 0x06 //!< RAM write/read +#define VS1053_SCI_WRAMADDR 0x07 //!< Base address for RAM write/read + +#define VS1053_PARA_PLAYSPEED 0x1E04 //!< 0,1 = normal speed, 2 = 2x, 3 = 3x etc #define VS1053_DATABUFFERLEN 32 //!< Length of the data buffer @@ -387,6 +391,16 @@ class Adafruit_VS1053_FilePlayer : public Adafruit_VS1053 { * @param pause whether or not to pause playback */ void pausePlaying(boolean pause); + /*! + * @brief Determine current playback speed + * @return Returns playback speed, i.e. 1 for 1x, 2 for 2x, 3 for 3x + */ + uint16_t getPlaySpeed(); + /*! + * @brief Set playback speed + * @param speed Set playback speed, i.e. 1 for 1x, 2 for 2x, 3 for 3x + */ + void setPlaySpeed(uint16_t speed); private: void feedBuffer_noLock(void);