From b8d9ca09f164c0162535c6330469595def15b745 Mon Sep 17 00:00:00 2001 From: "5684185+vsariola@users.noreply.github.com" <5684185+vsariola@users.noreply.github.com> Date: Sat, 14 Feb 2026 23:00:25 +0200 Subject: [PATCH] fix(cmd/sointu-vsti): query sample rate through host.GetTimeInfo Closes #222 --- CHANGELOG.md | 4 ++++ cmd/sointu-vsti/main.go | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b395f7b..e2bd163 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). roughly to -12 dBFS true peak. ([#211][i211]) ### Fixed +- VSTi queries the host sample rate more robustly. Cubase previously reported + the sample rate as 0 Hz, leading to persistent error message about the sample + rate not being 44100 Hz. ([#222][i222]) - Occasional NaNs in the Trisaw oscillator when the color was 0 in the Go VM. - The tracker thought that "sync" unit pops the value from stack, even if the VM did not, resulting it claiming errors in patches that worked once compiled. @@ -427,3 +430,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). [i211]: https://github.com/vsariola/sointu/issues/211 [i215]: https://github.com/vsariola/sointu/issues/215 [i221]: https://github.com/vsariola/sointu/issues/221 +[i222]: https://github.com/vsariola/sointu/issues/222 diff --git a/cmd/sointu-vsti/main.go b/cmd/sointu-vsti/main.go index 5206fb7..5f4d8f1 100644 --- a/cmd/sointu-vsti/main.go +++ b/cmd/sointu-vsti/main.go @@ -34,6 +34,14 @@ func (c *VSTIProcessContext) BPM() (bpm float64, ok bool) { return timeInfo.Tempo, true } +func (c *VSTIProcessContext) SampleRate() (samplerate float64, ok bool) { + timeInfo := c.host.GetTimeInfo(0) + if timeInfo == nil || timeInfo.SampleRate == 0 { + return 0, false + } + return timeInfo.SampleRate, true +} + func init() { var ( version = int32(100) @@ -60,6 +68,7 @@ func init() { context := &VSTIProcessContext{host: h} buf := make(sointu.AudioBuffer, 1024) var totalFrames int64 = 0 + start := time.Now() return vst2.Plugin{ UniqueID: [4]byte{'S', 'n', 't', 'u'}, Version: version, @@ -70,8 +79,11 @@ func init() { Category: vst2.PluginCategorySynth, Flags: vst2.PluginIsSynth, ProcessFloatFunc: func(in, out vst2.FloatBuffer) { - if s := h.GetSampleRate(); math.Abs(float64(h.GetSampleRate()-44100.0)) > 1e-6 { - player.SendAlert("WrongSampleRate", fmt.Sprintf("VSTi host sample rate is %.0f Hz; sointu supports 44100 Hz only", s), tracker.Error) + if time.Since(start) > 2*time.Second { // limit the rate we query the samplerate from the host and send alerts + if s, ok := context.SampleRate(); ok && math.Abs(float64(s-44100.0)) > 1e-6 { + player.SendAlert("WrongSampleRate", fmt.Sprintf("VSTi host sample rate is %.0f Hz; Sointu supports 44100 Hz only", s), tracker.Error) + } + start = time.Now() } left := out.Channel(0) right := out.Channel(1)