From 81f9f70dc7b20314f275b582682507013ae53db7 Mon Sep 17 00:00:00 2001 From: nomakewan Date: Sun, 10 Sep 2023 19:34:20 -0700 Subject: [PATCH 1/9] Silence compilation errors These changes resolve the compilation errors in the Arduino IDE by discarding an unnecessary variable from flush() and explicitly typecasting trk from int to uint16_t for the comparison operation in isTrackPlaying(int trk). --- wavTrigger.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/wavTrigger.cpp b/wavTrigger.cpp index d16cac4..14044ea 100644 --- a/wavTrigger.cpp +++ b/wavTrigger.cpp @@ -42,7 +42,6 @@ uint8_t txbuf[5]; void wavTrigger::flush(void) { int i; -uint8_t dat; rxCount = 0; rxLen = 0; @@ -51,7 +50,7 @@ uint8_t dat; voiceTable[i] = 0xffff; } while(WTSerial.available()) - dat = WTSerial.read(); + WTSerial.read(); } @@ -168,7 +167,7 @@ bool fResult = false; update(); for (i = 0; i < MAX_NUM_VOICES; i++) { - if (voiceTable[i] == trk) + if (voiceTable[i] == (uint16_t)trk) fResult = true; } return fResult; From f38eb81be0b18790375d7ad7df251c7de679c0cd Mon Sep 17 00:00:00 2001 From: nomakewan Date: Sun, 10 Sep 2023 22:34:56 -0700 Subject: [PATCH 2/9] Correct bounds issue in getVersion This corrects an out-of-bounds character array issue which can occur when calling getVersion, due to an unnecessary prefix increment which is already handled by the update function. --- wavTrigger.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/wavTrigger.cpp b/wavTrigger.cpp index 14044ea..007f1e9 100644 --- a/wavTrigger.cpp +++ b/wavTrigger.cpp @@ -232,7 +232,6 @@ int i; break; pDst[i] = version[i]; } - pDst[++i] = 0; return true; } From 34c214155f2d867dc5584c74abb07d0a6918cbfa Mon Sep 17 00:00:00 2001 From: nomakewan Date: Sun, 10 Sep 2023 22:45:54 -0700 Subject: [PATCH 3/9] Additional fix Missed the erroneous break statement which is unnecessary since update() already handled the bounds checking and version array cleaning. --- wavTrigger.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/wavTrigger.cpp b/wavTrigger.cpp index 007f1e9..6fdee4e 100644 --- a/wavTrigger.cpp +++ b/wavTrigger.cpp @@ -228,8 +228,6 @@ int i; return false; } for (i = 0; i < (VERSION_STRING_LEN - 1); i++) { - if (i >= (len - 1)) - break; pDst[i] = version[i]; } return true; From 123423237474e66422b3ba41f42f20424887d0bd Mon Sep 17 00:00:00 2001 From: nomakewan Date: Sun, 10 Sep 2023 23:01:55 -0700 Subject: [PATCH 4/9] Correct AltSoftSerial errors This corrects errors related to AltSoftSerial, enforcing the use of the standard Arduino Library for it rather than a hardcoded path to its header file. It also updates the README accordingly. --- README.md | 8 +------- examples/WTrigAdvanced/WTrigAdvanced.ino | 1 - examples/WTrigBasic/WTrigBasic.ino | 1 - wavTrigger.h | 2 +- 4 files changed, 2 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 672fa4b..2d22d31 100644 --- a/README.md +++ b/README.md @@ -5,13 +5,7 @@ WAV Trigger Serial Control Arduino Library Because the UNO's single serial port is used for programming, this library makes use of the AltSoftwareSerial library from PJRC by default. If you're using an UNO, you'll -therefore want to download and install that library as well. Be sure to include both -library headers at the top of your sketch. (See the example sketches) - -``` -#include -#include -``` +therefore want to download and install that library as well. However, if you're using an Arduino with at least one additional hardware serial port, you will not need AltSoftSerial. Instead, just make one small change to the diff --git a/examples/WTrigAdvanced/WTrigAdvanced.ino b/examples/WTrigAdvanced/WTrigAdvanced.ino index 406e7c6..1876020 100644 --- a/examples/WTrigAdvanced/WTrigAdvanced.ino +++ b/examples/WTrigAdvanced/WTrigAdvanced.ino @@ -43,7 +43,6 @@ // 10 to 20 seconds long and have no silence at the start of the file. #include -#include // Arduino build environment requires this #include #define LED 13 // our LED diff --git a/examples/WTrigBasic/WTrigBasic.ino b/examples/WTrigBasic/WTrigBasic.ino index 2a69be6..76d5fa0 100644 --- a/examples/WTrigBasic/WTrigBasic.ino +++ b/examples/WTrigBasic/WTrigBasic.ino @@ -41,7 +41,6 @@ // to 20 seconds long and have no silence at the start of the file. #include -#include // Arduino build environment requires this #include #define LED 13 // our LED diff --git a/wavTrigger.h b/wavTrigger.h index a89ca72..d9d328c 100644 --- a/wavTrigger.h +++ b/wavTrigger.h @@ -78,7 +78,7 @@ #ifdef __WT_USE_ALTSOFTSERIAL__ -#include "../AltSoftSerial/AltSoftSerial.h" +#include #else #include #ifdef __WT_USE_SERIAL1__ From f3fa82cb60d07104e0a70e0291b5c509a5a576de Mon Sep 17 00:00:00 2001 From: nomakewan Date: Mon, 11 Sep 2023 02:08:50 -0700 Subject: [PATCH 5/9] Fix new compile error Fixes newly-created compiler error due to removing the unused parameter from getVersion. --- examples/WTrigAdvanced/WTrigAdvanced.ino | 2 +- wavTrigger.cpp | 2 +- wavTrigger.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/WTrigAdvanced/WTrigAdvanced.ino b/examples/WTrigAdvanced/WTrigAdvanced.ino index 1876020..ccd1e18 100644 --- a/examples/WTrigAdvanced/WTrigAdvanced.ino +++ b/examples/WTrigAdvanced/WTrigAdvanced.ino @@ -92,7 +92,7 @@ void setup() { // If bi-directional communication is wired up, then we should by now be able // to fetch the version string and number of tracks on the SD card. - if (wTrig.getVersion(gWTrigVersion, VERSION_STRING_LEN)) { + if (wTrig.getVersion(gWTrigVersion)) { Serial.print(gWTrigVersion); Serial.print("\n"); gNumTracks = wTrig.getNumTracks(); diff --git a/wavTrigger.cpp b/wavTrigger.cpp index 6fdee4e..ddd4d3b 100644 --- a/wavTrigger.cpp +++ b/wavTrigger.cpp @@ -219,7 +219,7 @@ uint8_t txbuf[6]; } // ************************************************************** -bool wavTrigger::getVersion(char *pDst, int len) { +bool wavTrigger::getVersion(char *pDst) { int i; diff --git a/wavTrigger.h b/wavTrigger.h index d9d328c..2fb08bb 100644 --- a/wavTrigger.h +++ b/wavTrigger.h @@ -108,7 +108,7 @@ class wavTrigger void flush(void); void setReporting(bool enable); void setAmpPwr(bool enable); - bool getVersion(char *pDst, int len); + bool getVersion(char *pDst); int getNumTracks(void); bool isTrackPlaying(int trk); void masterGain(int gain); From 7ac4482e192e67ccbe7d87002484541f2805be3f Mon Sep 17 00:00:00 2001 From: nomakewan Date: Wed, 13 Sep 2023 06:15:53 -0700 Subject: [PATCH 6/9] Update README.md Updates the README to match the current code of this PR. --- README.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 2d22d31..53cac22 100644 --- a/README.md +++ b/README.md @@ -52,14 +52,14 @@ See the comments below. Usage: ====== -In all cases below, the range for t (track number) is 1 through 4096; +In all cases below, the range for trk (track number) is 1 through 4096; wavTrigger wTtrig; **wTrig.start()** - you must call this method first to initialize the serial communications. -**wTrig.getVersion(char \*pDst, int len)** - this function will return **len** bytes of +**wTrig.getVersion(char \*pDst)** - this function will return **VERSION_STRING_LEN** bytes of the WAV Trigger version string to the location specified by **pDst**. The function returns TRUE if successful, and FALSE if the string is not available. This function requires bi-directional communication with the WAV Trigger. @@ -91,32 +91,32 @@ wavTrigger wTtrig; hear the result immediately. If audio is not playing, the new sample-rate offset will be used the next time a track is started. -**wTrig.trackPlaySolo(int t)** - this function stops any and all tracks that are +**wTrig.trackPlaySolo(int trk)** - this function stops any and all tracks that are currently playing and starts track number **t** from the beginning. -**wTrig.trackPlayPoly(int t)** - this function starts track number **t** from the +**wTrig.trackPlayPoly(int trk)** - this function starts track number **t** from the beginning, blending it with any other tracks that are currently playing, including potentially another copy of the same track. -**wTrig.trackLoad(int t)** - this function loads track number **t** and pauses it +**wTrig.trackLoad(int trk)** - this function loads track number **t** and pauses it at the beginning of the track. Loading muiltiple tracks and then un-pausing them all with resumeAllInSync() function below allows for starting multiple tracks in sample sync. -**wTrig.trackStop(int t)** - this function stops track number **t** if it's currently +**wTrig.trackStop(int trk)** - this function stops track number **t** if it's currently playing. If track t is not playing, this function does nothing. No other tracks are affected. -**wTrig.trackPause(int t)** - this function pauses track number **t** if it's currently +**wTrig.trackPause(int trk)** - this function pauses track number **t** if it's currently playing. If track t is not playing, this function does nothing. Keep in mind that a paused track is still using one of the 8 voice slots. A voice allocated to playing a track becomes free only when that sound is stopped or the track reaches the end of the file (and is not looping). -**wTrig.trackResume(int t)** - this function resumes track number **t** if it's currently +**wTrig.trackResume(int trk)** - this function resumes track number **t** if it's currently paused. If track number **t** is not paused, this function does nothing. -**wTrig.trackLoop(int t, bool enable)** - this function enables (true) or disables +**wTrig.trackLoop(int trk, bool enable)** - this function enables (true) or disables (false) the loop flag for track **t**. This command does not actually start a track, only determines how it behaves once it is playing and reaches the end. If the loop flag is set, that track will loop continuously until it's stopped, in which @@ -124,7 +124,7 @@ wavTrigger wTtrig; flag is cleared, in which case it will stop when it reaches the end of the track. This command may be used either before a track is started or while it's playing. -**wTrig.trackGain(int t, int gain)** - this function immediately sets the gain of +**wTrig.trackGain(int trk, int gain)** - this function immediately sets the gain of track **t** to the specified value. The range for gain is -70 to +10. A value of 0 (no gain) plays the track at the nominal value in the wav file. This is the default gain for every track until changed. A value of -70 is completely @@ -145,7 +145,7 @@ wavTrigger wTtrig; audio buffer. Any tracks that were loaded using the trackLoad() function will start and remain sample locked (in sample sync) with one another. -**wTrig.trackFade(int t, int gain, int time, bool stopFlag)** - this command initiates +**wTrig.trackFade(int trk, int gain, int time, bool stopFlag)** - this command initiates a hardware volume fade on track number **t** if it is currently playing. The track volume will transition smoothly from the current value to the target gain in the specified number of milliseconds. If the stopFlag is non-zero, the track will be @@ -172,18 +172,18 @@ sketch demonstrates the use of these functions. **wTrig.flush()** - This function clears the WAV Trigger communication buffer and resets the local track status info. -**wTrig.trackPlaySolo(int t, bool lock)** - this function stops any and all tracks that +**wTrig.trackPlaySolo(int trk, bool lock)** - this function stops any and all tracks that are currently playing and starts track number **t** from the beginning. If **lock** is TRUE, the track will not be subject to the WAV Trigger's voice stealing algorithm, and will not be stopped if the max number of voices is reached. -**wTrig.trackPlayPoly(int t, bool lock)** - this function starts track number **t** from +**wTrig.trackPlayPoly(int trk, bool lock)** - this function starts track number **t** from the beginning, blending it with any other tracks that are currently playing, including potentially another copy of the same track. If **lock** is TRUE, the track will not be subject to the WAV Trigger's voice stealing algorithm, and will not be stopped if the max number of voices is reached. -**wTrig.trackLoad(int t, bool lock)** - this function loads track number **t** and pauses it +**wTrig.trackLoad(int trk, bool lock)** - this function loads track number **t** and pauses it at the beginning of the track. Loading muiltiple tracks and then un-pausing them all with resumeAllInSync() function allows for starting multiple tracks in sample sync. If **lock** is TRUE, the track will not be subject to the WAV Trigger's voice From 7ea17de69fedbb1180c0a2a4fe53119b7f6ad71d Mon Sep 17 00:00:00 2001 From: nomakewan Date: Wed, 13 Sep 2023 10:10:05 -0700 Subject: [PATCH 7/9] Fix Due compatibility Checks to see if the user's board is a Due or its derivatives and if so includes Arduino.h instead of HardwareSerial.h since that is where the serial ports are defined on the Due. --- wavTrigger.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/wavTrigger.h b/wavTrigger.h index 2fb08bb..232aaf6 100644 --- a/wavTrigger.h +++ b/wavTrigger.h @@ -80,7 +80,11 @@ #ifdef __WT_USE_ALTSOFTSERIAL__ #include #else +#if defined(__SAM3X8E__) +#include +#else #include +#endif #ifdef __WT_USE_SERIAL1__ #define WTSerial Serial1 #define __WT_SERIAL_ASSIGNED__ From 88b5e4e38829692f6d2168790bba8a528dec0313 Mon Sep 17 00:00:00 2001 From: nomakewan Date: Fri, 29 Sep 2023 16:01:24 -0700 Subject: [PATCH 8/9] Formatting update --- wavTrigger.cpp | 2 -- wavTrigger.h | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/wavTrigger.cpp b/wavTrigger.cpp index ddd4d3b..5a0e027 100644 --- a/wavTrigger.cpp +++ b/wavTrigger.cpp @@ -433,5 +433,3 @@ uint8_t txbuf[6]; txbuf[5] = EOM; WTSerial.write(txbuf, 6); } - - diff --git a/wavTrigger.h b/wavTrigger.h index 232aaf6..5c23878 100644 --- a/wavTrigger.h +++ b/wavTrigger.h @@ -80,7 +80,7 @@ #ifdef __WT_USE_ALTSOFTSERIAL__ #include #else -#if defined(__SAM3X8E__) +#ifdef __SAM3X8E__ #include #else #include From f5107369fe9ac2b23ef0d4928f436afdcb7c3066 Mon Sep 17 00:00:00 2001 From: nomakewan Date: Mon, 29 Apr 2024 21:47:41 -0700 Subject: [PATCH 9/9] Clean up code --- wavTrigger.cpp | 47 ++++++++++++++--------------------------------- 1 file changed, 14 insertions(+), 33 deletions(-) diff --git a/wavTrigger.cpp b/wavTrigger.cpp index 5a0e027..4317206 100644 --- a/wavTrigger.cpp +++ b/wavTrigger.cpp @@ -41,12 +41,10 @@ uint8_t txbuf[5]; // ************************************************************** void wavTrigger::flush(void) { -int i; - rxCount = 0; rxLen = 0; rxMsgReady = false; - for (i = 0; i < MAX_NUM_VOICES; i++) { + for (int i = 0; i < MAX_NUM_VOICES; i++) { voiceTable[i] = 0xffff; } while(WTSerial.available()) @@ -57,7 +55,6 @@ int i; // ************************************************************** void wavTrigger::update(void) { -int i; uint8_t dat; uint8_t voice; uint16_t track; @@ -129,7 +126,7 @@ uint16_t track; break; case RSP_VERSION_STRING: - for (i = 0; i < (VERSION_STRING_LEN - 1); i++) + for (int i = 0; i < (VERSION_STRING_LEN - 1); i++) version[i] = rxMessage[i + 1]; version[VERSION_STRING_LEN - 1] = 0; versionRcvd = true; @@ -148,44 +145,36 @@ uint16_t track; ///\Serial.print("Sys info received\n"); // ========================== break; - } rxCount = 0; rxLen = 0; rxMsgReady = false; - } // if (rxMsgReady) - } // while (WTSerial.available() > 0) } // ************************************************************** bool wavTrigger::isTrackPlaying(int trk) { -int i; -bool fResult = false; - update(); - for (i = 0; i < MAX_NUM_VOICES; i++) { + for (int i = 0; i < MAX_NUM_VOICES; i++) { if (voiceTable[i] == (uint16_t)trk) - fResult = true; + return true; } - return fResult; + return false; } // ************************************************************** void wavTrigger::masterGain(int gain) { uint8_t txbuf[7]; -unsigned short vol; txbuf[0] = SOM1; txbuf[1] = SOM2; txbuf[2] = 0x07; txbuf[3] = CMD_MASTER_VOLUME; - vol = (unsigned short)gain; - txbuf[4] = (uint8_t)vol; - txbuf[5] = (uint8_t)(vol >> 8); + txbuf[4] = (uint8_t)gain; + txbuf[5] = (uint8_t)(gain >> 8); txbuf[6] = EOM; WTSerial.write(txbuf, 7); } @@ -221,13 +210,11 @@ uint8_t txbuf[6]; // ************************************************************** bool wavTrigger::getVersion(char *pDst) { -int i; - update(); if (!versionRcvd) { return false; } - for (i = 0; i < (VERSION_STRING_LEN - 1); i++) { + for (int i = 0; i < (VERSION_STRING_LEN - 1); i++) { pDst[i] = version[i]; } return true; @@ -366,7 +353,6 @@ uint8_t txbuf[5]; void wavTrigger::trackGain(int trk, int gain) { uint8_t txbuf[9]; -unsigned short vol; txbuf[0] = SOM1; txbuf[1] = SOM2; @@ -374,9 +360,8 @@ unsigned short vol; txbuf[3] = CMD_TRACK_VOLUME; txbuf[4] = (uint8_t)trk; txbuf[5] = (uint8_t)(trk >> 8); - vol = (unsigned short)gain; - txbuf[6] = (uint8_t)vol; - txbuf[7] = (uint8_t)(vol >> 8); + txbuf[6] = (uint8_t)gain; + txbuf[7] = (uint8_t)(gain >> 8); txbuf[8] = EOM; WTSerial.write(txbuf, 9); } @@ -385,7 +370,6 @@ unsigned short vol; void wavTrigger::trackFade(int trk, int gain, int time, bool stopFlag) { uint8_t txbuf[12]; -unsigned short vol; txbuf[0] = SOM1; txbuf[1] = SOM2; @@ -393,9 +377,8 @@ unsigned short vol; txbuf[3] = CMD_TRACK_FADE; txbuf[4] = (uint8_t)trk; txbuf[5] = (uint8_t)(trk >> 8); - vol = (unsigned short)gain; - txbuf[6] = (uint8_t)vol; - txbuf[7] = (uint8_t)(vol >> 8); + txbuf[6] = (uint8_t)gain; + txbuf[7] = (uint8_t)(gain >> 8); txbuf[8] = (uint8_t)time; txbuf[9] = (uint8_t)(time >> 8); txbuf[10] = stopFlag; @@ -407,15 +390,13 @@ unsigned short vol; void wavTrigger::samplerateOffset(int offset) { uint8_t txbuf[7]; -unsigned short off; txbuf[0] = SOM1; txbuf[1] = SOM2; txbuf[2] = 0x07; txbuf[3] = CMD_SAMPLERATE_OFFSET; - off = (unsigned short)offset; - txbuf[4] = (uint8_t)off; - txbuf[5] = (uint8_t)(off >> 8); + txbuf[4] = (uint8_t)offset; + txbuf[5] = (uint8_t)(offset >> 8); txbuf[6] = EOM; WTSerial.write(txbuf, 7); }