fix(sointu-vsti): warn about sample rate only after plugin init

This commit is contained in:
5684185+vsariola@users.noreply.github.com 2024-09-22 09:59:58 +03:00
parent ce673578fd
commit 8fd2df19a1
3 changed files with 12 additions and 14 deletions

View File

@ -10,6 +10,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
the command line tools.
### Fixed
- Warn about plugin sample rate being different from 44100 only after
ProcessFloatFunc has been called, so that host has time to set the sample rate
after initialization.
- Crashes with sample-based oscillators in the 32-bit library, as the pointer to
sample-table (edi) got accidentally overwritten by detune
- Sample-based oscillators could hard crash if a x87 stack overflow happened

View File

@ -9,7 +9,6 @@ import (
"math"
"os"
"path/filepath"
"time"
"github.com/vsariola/sointu"
"github.com/vsariola/sointu/cmd"
@ -66,13 +65,6 @@ func init() {
model, player := tracker.NewModelPlayer(cmd.MainSynther, recoveryFile)
t := gioui.NewTracker(model)
tracker.Bool{BoolData: (*tracker.InstrEnlarged)(model)}.Set(true)
if s := h.GetSampleRate(); math.Abs(float64(h.GetSampleRate()-44100.0)) > 1e-6 {
model.Alerts().AddAlert(tracker.Alert{
Message: fmt.Sprintf("VSTi host sample rate is %.0f Hz; sointu supports 44100 Hz only", s),
Priority: tracker.Error,
Duration: 10 * time.Second,
})
}
go t.Main()
context := VSTIProcessContext{host: h}
buf := make(sointu.AudioBuffer, 1024)
@ -86,6 +78,9 @@ 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)
}
left := out.Channel(0)
right := out.Channel(1)
if len(buf) < out.Frames {

View File

@ -171,12 +171,12 @@ func (p *Player) Process(buffer sointu.AudioBuffer, context PlayerProcessContext
err2 := p.peakVolumeMeter.Update(oldBuffer)
if err != nil {
p.synth = nil
p.sendAlert("PlayerVolume", err.Error(), Warning)
p.SendAlert("PlayerVolume", err.Error(), Warning)
return
}
if err2 != nil {
p.synth = nil
p.sendAlert("PlayerVolume", err2.Error(), Warning)
p.SendAlert("PlayerVolume", err2.Error(), Warning)
return
}
p.send(nil)
@ -185,7 +185,7 @@ func (p *Player) Process(buffer sointu.AudioBuffer, context PlayerProcessContext
}
// we were not able to fill the buffer with NUM_RENDER_TRIES attempts, destroy synth and throw an error
p.synth = nil
p.sendAlert("PlayerCrash", fmt.Sprintf("synth did not fill the audio buffer even with %d render calls", numRenderTries), Error)
p.SendAlert("PlayerCrash", fmt.Sprintf("synth did not fill the audio buffer even with %d render calls", numRenderTries), Error)
}
func (p *Player) advanceRow() {
@ -302,7 +302,7 @@ loop:
}
}
func (p *Player) sendAlert(name, message string, priority AlertPriority) {
func (p *Player) SendAlert(name, message string, priority AlertPriority) {
p.send(Alert{
Name: name,
Priority: priority,
@ -319,7 +319,7 @@ func (p *Player) compileOrUpdateSynth() {
err := p.synth.Update(p.song.Patch, p.song.BPM)
if err != nil {
p.synth = nil
p.sendAlert("PlayerCrash", fmt.Sprintf("synth.Update: %v", err), Error)
p.SendAlert("PlayerCrash", fmt.Sprintf("synth.Update: %v", err), Error)
return
}
} else {
@ -327,7 +327,7 @@ func (p *Player) compileOrUpdateSynth() {
p.synth, err = p.synther.Synth(p.song.Patch, p.song.BPM)
if err != nil {
p.synth = nil
p.sendAlert("PlayerCrash", fmt.Sprintf("synther.Synth: %v", err), Error)
p.SendAlert("PlayerCrash", fmt.Sprintf("synther.Synth: %v", err), Error)
return
}
}