diff --git a/README.md b/README.md index 672fa4b..53cac22 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 @@ -58,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. @@ -97,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 @@ -130,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 @@ -151,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 @@ -178,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 diff --git a/examples/WTrigAdvanced/WTrigAdvanced.ino b/examples/WTrigAdvanced/WTrigAdvanced.ino index 406e7c6..ccd1e18 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 @@ -93,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/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.cpp b/wavTrigger.cpp index d16cac4..4317206 100644 --- a/wavTrigger.cpp +++ b/wavTrigger.cpp @@ -41,24 +41,20 @@ uint8_t txbuf[5]; // ************************************************************** void wavTrigger::flush(void) { -int i; -uint8_t dat; - 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()) - dat = WTSerial.read(); + WTSerial.read(); } // ************************************************************** void wavTrigger::update(void) { -int i; uint8_t dat; uint8_t voice; uint16_t track; @@ -130,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; @@ -149,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++) { - if (voiceTable[i] == trk) - fResult = true; + for (int i = 0; i < MAX_NUM_VOICES; i++) { + if (voiceTable[i] == (uint16_t)trk) + 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); } @@ -220,20 +208,15 @@ uint8_t txbuf[6]; } // ************************************************************** -bool wavTrigger::getVersion(char *pDst, int len) { - -int i; +bool wavTrigger::getVersion(char *pDst) { update(); if (!versionRcvd) { return false; } - for (i = 0; i < (VERSION_STRING_LEN - 1); i++) { - if (i >= (len - 1)) - break; + for (int i = 0; i < (VERSION_STRING_LEN - 1); i++) { pDst[i] = version[i]; } - pDst[++i] = 0; return true; } @@ -370,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; @@ -378,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); } @@ -389,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; @@ -397,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; @@ -411,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); } @@ -437,5 +414,3 @@ uint8_t txbuf[6]; txbuf[5] = EOM; WTSerial.write(txbuf, 6); } - - diff --git a/wavTrigger.h b/wavTrigger.h index a89ca72..5c23878 100644 --- a/wavTrigger.h +++ b/wavTrigger.h @@ -78,9 +78,13 @@ #ifdef __WT_USE_ALTSOFTSERIAL__ -#include "../AltSoftSerial/AltSoftSerial.h" +#include +#else +#ifdef __SAM3X8E__ +#include #else #include +#endif #ifdef __WT_USE_SERIAL1__ #define WTSerial Serial1 #define __WT_SERIAL_ASSIGNED__ @@ -108,7 +112,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);