Documentation
¶
Overview ¶
Sparkfun Tsunami serial control library for golang
Tsunami is a polyphonic Wav file player with 4 stereo (or 8 mono) outputs. Wav files can be triggered using the 16 onboard contacts, via MIDI, serial connection or Qwiic to a PC or other microcontroller.
Index ¶
- Constants
- type Tsunami
- func (t *Tsunami) Close() error
- func (t *Tsunami) GetNumTracks() int
- func (t *Tsunami) GetVersion() string
- func (t *Tsunami) IsTrackPlaying(trk int) bool
- func (t *Tsunami) MasterGain(out, gain int) error
- func (t *Tsunami) ResumeAllInSync() error
- func (t *Tsunami) SamplerateOffset(out, offset int) error
- func (t *Tsunami) SetInputMix(mix int) error
- func (t *Tsunami) SetMidiBank(bank int) error
- func (t *Tsunami) SetReporting(enable bool) error
- func (t *Tsunami) SetTriggerBank(bank int) error
- func (t *Tsunami) Start() error
- func (t *Tsunami) StopAllTracks() error
- func (t *Tsunami) TrackFade(trk, gain int, d time.Duration, stopFlag bool) error
- func (t *Tsunami) TrackGain(trk, gain int) error
- func (t *Tsunami) TrackLoad(trk, out int, lock bool) error
- func (t *Tsunami) TrackLoop(trk int, enable bool) error
- func (t *Tsunami) TrackPause(trk int) error
- func (t *Tsunami) TrackPlayPoly(trk, out int, lock bool) error
- func (t *Tsunami) TrackPlaySolo(trk, out int, lock bool) error
- func (t *Tsunami) TrackResume(trk int) error
- func (t *Tsunami) TrackStop(trk int) error
Examples ¶
Constants ¶
const ( CMD_GET_VERSION = 1 CMD_GET_SYS_INFO = 2 CMD_TRACK_CONTROL = 3 CMD_STOP_ALL = 4 CMD_MASTER_VOLUME = 5 CMD_TRACK_VOLUME = 8 CMD_TRACK_FADE = 10 CMD_RESUME_ALL_SYNC = 11 CMD_SAMPLERATE_OFFSET = 12 CMD_SET_REPORTING = 13 CMD_SET_TRIGGER_BANK = 14 CMD_SET_INPUT_MIX = 15 CMD_SET_MIDI_BANK = 16 TRK_PLAY_SOLO = 0 TRK_PLAY_POLY = 1 TRK_PAUSE = 2 TRK_RESUME = 3 TRK_STOP = 4 TRK_LOOP_ON = 5 TRK_LOOP_OFF = 6 TRK_LOAD = 7 RSP_VERSION_STRING = 129 RSP_SYSTEM_INFO = 130 RSP_STATUS = 131 RSP_TRACK_REPORT = 132 MAX_MESSAGE_LEN = 32 MAX_NUM_VOICES = 18 VERSION_STRING_LEN = 23 SOM1 = 0xf0 SOM2 = 0xaa EOM = 0x55 IMIX_OUT1 = 0x01 IMIX_OUT2 = 0x02 IMIX_OUT3 = 0x04 IMIX_OUT4 = 0x08 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Tsunami ¶
type Tsunami struct {
// contains filtered or unexported fields
}
Tsunami serial connection.
Example ¶
package main
import (
"fmt"
"time"
"github.com/mcuadros/go-tsunami"
)
func main() {
ts, err := tsunami.NewTsunami("/dev/ttyUSB0")
if err != nil {
panic(err)
}
defer ts.Close()
if err := ts.Start(); err != nil {
panic(err)
}
trackNum := 1002
fmt.Println(ts.GetNumTracks())
ts.TrackGain(trackNum, 70) // muted
ts.TrackPlaySolo(trackNum, 0, false) // track = 19 (aka "19.WAV"), output = 0 (aka "1L")
ts.TrackFade(trackNum, 0, time.Second*5, false) // track 19, fade to gain of 0,
fmt.Println("Track 19 stopped.")
}
Output: Fading IN track 19 right now... Gain set to unity (0)! Playing for 5 seconds... Fading OUT track 19 right now... Track 19 stopped.
func NewTsunami ¶
NewTsunami returns a new Tsuanmi connection to the given port.
func (*Tsunami) GetNumTracks ¶
GetNumTracks this function will return the Tsunami version. This function requires bi-directional communication with Tsunami.
func (*Tsunami) GetVersion ¶
GetVersion this function will return the Tsunami version string. This function requires bi-directional communication with Tsunami.
func (*Tsunami) IsTrackPlaying ¶
IsTrackPlaying if reporting has been enabled, this function can be used to determine if a particular track is currently playing.
func (*Tsunami) MasterGain ¶
MasterGain this function immediately sets the gain of the specific stereo output to the specified value. The range for gain is -70 to +4. If audio is playing, you will hear the result immediately. If audio is not playing, the new gain will be used the next time a track is started.
func (*Tsunami) ResumeAllInSync ¶
ResumeAllInSync this command resumes all paused tracks within the same audio buffer. Any tracks that were loaded using the TrackLoad() function will start and remain sample locked (in sample sync) with one another.
func (*Tsunami) SamplerateOffset ¶
SamplerateOffset this function immediately sets sample-rate offset, or playback speed / pitch, of the specified stereo output. The range for for the offset is -32767 to +32676, giving a speed range of 1/2x to 2x, or a pitch range of down one octave to up one octave. If audio is playing, you will hear the result immediately. If audio is not playing, the new sample-rate offset will be used the next time a track is started.
func (*Tsunami) SetInputMix ¶
SetInputMix this function controls the routing of the audio input channels. For bits 1 through 4, a "1" causes the 2 input channels to be mixed into the corresponding output pair. As an example, to route the audio input to output pairs 1, 2 and 4, the syntax is: SetInputMix(IMIX_OUT1 | IMIX_OUT2 | IMIX_OUT4)
The routing is immediate and does no ramping, so to avoid pops, be sure that the input is quiet when switching.
func (*Tsunami) SetMidiBank ¶
SetMidiBank this function sets the MIDI bank. The bank range is 1 - 32. Each bank will offset the MIDI Note number to track assignment by 128. For bank 1, the default, MIDI Note number maps to track 1. For bank 2, MIDI Note number 1 maps to track 129, MIDI Note number 2 to track 130, and so on.
func (*Tsunami) SetReporting ¶
SetReporting this function enables or disables track reporting. When enabled, the Tsunami will send a message whenever a track starts or ends, specifying the track number. Provided you call update() periodically, the library will use these messages to maintain status of all tracks, allowing you to query if particular tracks are playing or not.
func (*Tsunami) SetTriggerBank ¶
SetTriggerBank this function sets the trigger bank. The bank range is 1 - 32. Each bank will offset the normal trigger function track assignment by 16. For bank 1, the default, trigger one maps to track 1. For bank 2, trigger 1 maps to track 17, trigger 2 to track 18, and so on.
func (*Tsunami) StopAllTracks ¶
StopAllTracks this commands stops any and all tracks that are currently playing.
func (*Tsunami) TrackFade ¶
TrackFade this command initiates a hardware volume fade on track number trk 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 stopped at the completion of the fade (for fade-outs.)
func (*Tsunami) TrackGain ¶
TrackGain this function immediately sets the gain of track trk 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 muted. If the track is playing, you will hear the result immediately. If the track is not playing, the gain will be used the next time the track is started. Every track can have its own gain.
Because the effect is immediate, large changes can produce ubrupt results. If you want to fade in or fade out a track, send small changes spaced out at regular intervals. Increment or decrementing by 1 every 20 to 50 msecs produces nice smooth fades. Better yet, use the trackFade() function below.
func (*Tsunami) TrackLoad ¶
TrackLoad this function loads track number trk and pauses it at the beginning of the track. Loading muiltiple tracks and then un-pausing the all with resumeAllInSync() function below allows for starting multiple tracks in sample sync. The track is routed to the specified stereo output. If lock is true, the track will not be subject to Tsunami's voice stealing algorithm.
func (*Tsunami) TrackLoop ¶
TrackLoop this function enables (true) or disables (false) the loop flag for track trk. 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.
func (*Tsunami) TrackPause ¶
TrackPause this function pauses track number trk if it's currently playing. If track 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).
func (*Tsunami) TrackPlayPoly ¶
TrackPlayPoly this function starts track number trk from the beginning, blending it with any other tracks that are currently playing, including potentially another copy of the same track. The track is routed to the specified stereo output. If lock is true, the track will not be subject to Tsunami's voice stealing algorithm.
func (*Tsunami) TrackPlaySolo ¶
TrackPlaySolo this function stops any and all tracks that are currently playing and starts track number trk from the beginning. The track is routed to the specified stereo output. If lock is true, the track will not be subject to Tsunami's voice stealing algorithm.
func (*Tsunami) TrackResume ¶
TrackResume this function resumes track number trk if it's currently paused. If track number t is not paused, this function does nothing.