Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 15 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <AltSoftSerial.h>
#include <wavTrigger.h>
```
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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -97,40 +91,40 @@ 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
case it will stop immediately but the loop flag will remain set, or until the loop
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
Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions examples/WTrigAdvanced/WTrigAdvanced.ino
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
// 10 to 20 seconds long and have no silence at the start of the file.

#include <Metro.h>
#include <AltSoftSerial.h> // Arduino build environment requires this
#include <wavTrigger.h>

#define LED 13 // our LED
Expand Down Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion examples/WTrigBasic/WTrigBasic.ino
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
// to 20 seconds long and have no silence at the start of the file.

#include <Metro.h>
#include <AltSoftSerial.h> // Arduino build environment requires this
#include <wavTrigger.h>

#define LED 13 // our LED
Expand Down
59 changes: 17 additions & 42 deletions wavTrigger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -370,17 +353,15 @@ uint8_t txbuf[5];
void wavTrigger::trackGain(int trk, int gain) {

uint8_t txbuf[9];
unsigned short vol;

txbuf[0] = SOM1;
txbuf[1] = SOM2;
txbuf[2] = 0x09;
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);
}
Expand All @@ -389,17 +370,15 @@ 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;
txbuf[2] = 0x0c;
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;
Expand All @@ -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);
}
Expand All @@ -437,5 +414,3 @@ uint8_t txbuf[6];
txbuf[5] = EOM;
WTSerial.write(txbuf, 6);
}


8 changes: 6 additions & 2 deletions wavTrigger.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,13 @@


#ifdef __WT_USE_ALTSOFTSERIAL__
#include "../AltSoftSerial/AltSoftSerial.h"
#include <AltSoftSerial.h>
#else
#ifdef __SAM3X8E__
#include <Arduino.h>
#else
#include <HardwareSerial.h>
#endif
#ifdef __WT_USE_SERIAL1__
#define WTSerial Serial1
#define __WT_SERIAL_ASSIGNED__
Expand Down Expand Up @@ -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);
Expand Down