Compare commits

..

No commits in common. "55d14b0d0743ac1b6fe55953f08db3c320add5c2" and "843f7c5e0d922827e87ca89cc2040ba7938ec938" have entirely different histories.

3 changed files with 9 additions and 22 deletions

View File

@ -1,6 +1,5 @@
![Windows](https://img.shields.io/badge/Windows-0078D6?style=for-the-badge&logo=windows&logoColor=white)
![Linux](https://img.shields.io/badge/Linux-FCC624?style=for-the-badge&logo=linux&logoColor=black)
![macOS](https://img.shields.io/badge/mac%20os-000000?style=for-the-badge&logo=macos&logoColor=F0F0F0)
# VBAN Sendtext
@ -24,10 +23,10 @@ For an outline of past/future changes refer to: [CHANGELOG](CHANGELOG.md)
## Tested against
- Basic 1.1.2.2
- Banana 2.1.2.2
- Potato 3.1.2.2
- Matrix 1.0.2.6
- Basic 1.1.1.9
- Banana 2.1.1.9
- Potato 3.1.1.9
- Matrix 1.0.1.2
---

View File

@ -10,7 +10,6 @@ import (
const (
vbanProtocolTxt = 0x40
vbanTxtUtf8 = 0x10
streamNameSz = 16
headerSz = 4 + 1 + 1 + 1 + 1 + 16 + 4
)
@ -60,7 +59,7 @@ func newPacket(streamname string) (packet, error) {
// sr defines the samplerate for the request.
func (p *packet) sr() byte {
return byte(p.bpsIndex | vbanProtocolTxt)
return byte(vbanProtocolTxt + p.bpsIndex)
}
// nbc defines the channel of the request.
@ -75,7 +74,7 @@ func (p *packet) header() []byte {
p.hbuf.WriteByte(p.sr())
p.hbuf.WriteByte(byte(0))
p.hbuf.WriteByte(p.nbc())
p.hbuf.WriteByte(byte(vbanTxtUtf8))
p.hbuf.WriteByte(byte(0x10))
p.hbuf.Write(p.streamname[:])
var frameBytes [4]byte

View File

@ -4,8 +4,6 @@ import (
"fmt"
"io"
"time"
"github.com/charmbracelet/log"
)
// VbanTxt is used to send VBAN-TXT requests to a distant Voicemeeter/Matrix.
@ -13,7 +11,6 @@ type VbanTxt struct {
conn io.WriteCloser
packet packet
ratelimit time.Duration
lastSend time.Time
}
// New constructs a fully formed VbanTxt instance. This is the package's entry point.
@ -43,18 +40,8 @@ func New(host string, port int, streamname string, options ...Option) (*VbanTxt,
}
// Send is responsible for firing each VBAN-TXT request.
// It enforces rate limiting by waiting only when necessary.
// It waits for {vt.ratelimit} time before returning.
func (vt *VbanTxt) Send(cmd string) error {
if elapsed := time.Since(vt.lastSend); elapsed < vt.ratelimit {
log.Debugf(
"Rate limit in effect. Waiting for %v before sending next command.",
vt.ratelimit-elapsed,
)
time.Sleep(vt.ratelimit - elapsed)
}
vt.lastSend = time.Now()
_, err := vt.conn.Write(append(vt.packet.header(), cmd...))
if err != nil {
return fmt.Errorf("error sending command (%s): %w", cmd, err)
@ -62,6 +49,8 @@ func (vt *VbanTxt) Send(cmd string) error {
vt.packet.bumpFrameCounter()
time.Sleep(vt.ratelimit)
return nil
}