restore the saved microphone volume on connect
Apply the persisted microphone volume when the stream is created. The value was written to the configuration on every adjustment but never read back, so the microphone returned to full gain on each start. Read a saved volume of zero as zero rather than as a missing value. A user who muted their microphone and quit came back unmuted. Save the configuration after a volume change and report a failure. The setter only updated the in-memory value, so the new level was lost unless something else happened to save afterwards. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
cb4f91596e
commit
fbb6a148ff
@@ -51,6 +51,7 @@ func (b *Barnard) connect(reconnect bool) bool {
|
||||
return false
|
||||
}
|
||||
b.Stream = stream
|
||||
b.Stream.SetMicVolume(b.UserConfig.GetMicVolume(), false)
|
||||
b.Stream.AttachStream(b.Client)
|
||||
b.Stream.SetNoiseProcessor(b.NoiseSuppressor)
|
||||
b.Stream.SetAGCEnabled(b.UserConfig.GetAGCEnabled())
|
||||
|
||||
@@ -316,6 +316,15 @@ func (c *Config) SetMicVolume(v float32) {
|
||||
c.config.MicVolume = &t
|
||||
}
|
||||
|
||||
func (c *Config) GetMicVolume() float32 {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
if c.config.MicVolume == nil {
|
||||
return 1.0
|
||||
}
|
||||
return *c.config.MicVolume
|
||||
}
|
||||
|
||||
func (c *Config) GetHotkeys() *Hotkeys {
|
||||
return c.config.Hotkeys
|
||||
}
|
||||
|
||||
@@ -115,6 +115,18 @@ func TestMakeHostPortHandlesIPv6AndMalformedAddress(t *testing.T) {
|
||||
t.Fatalf("got %q:%d", host, port)
|
||||
}
|
||||
}
|
||||
|
||||
// Regression: a stored zero mic volume was treated as an uninitialized value,
|
||||
// so a persisted mute became full volume after reconnecting.
|
||||
func TestMicVolumeAllowsPersistedMute(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "barnard.toml")
|
||||
cfg := NewConfig(&path)
|
||||
cfg.SetMicVolume(0)
|
||||
if got := cfg.GetMicVolume(); got != 0 {
|
||||
t.Fatalf("got %v, want mute", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigUsesHomeEnvironmentForDefaultPath(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
t.Setenv("HOME", dir)
|
||||
|
||||
@@ -338,11 +338,17 @@ func (b *Barnard) setTransmit(ui *uiterm.Ui, val int) {
|
||||
func (b *Barnard) OnMicVolumeDown(ui *uiterm.Ui, key uiterm.Key) {
|
||||
b.Stream.SetMicVolume(-0.1, true)
|
||||
b.UserConfig.SetMicVolume(b.Stream.GetMicVolume())
|
||||
if err := b.UserConfig.SaveConfig(); err != nil {
|
||||
b.AddOutputLine("Microphone: could not save volume: " + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Barnard) OnMicVolumeUp(ui *uiterm.Ui, key uiterm.Key) {
|
||||
b.Stream.SetMicVolume(0.1, true)
|
||||
b.UserConfig.SetMicVolume(b.Stream.GetMicVolume())
|
||||
if err := b.UserConfig.SaveConfig(); err != nil {
|
||||
b.AddOutputLine("Microphone: could not save volume: " + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Barnard) OnQuitPress(ui *uiterm.Ui, key uiterm.Key) {
|
||||
|
||||
Reference in New Issue
Block a user