From 6fbcee95148cb3e3265914d1be948a7061d78ac1 Mon Sep 17 00:00:00 2001 From: Mark Kremer Date: Thu, 11 Jul 2024 20:51:39 +0200 Subject: [PATCH] Limit resample ratio in speedy-player example --- examples/speedy-player/main.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/examples/speedy-player/main.go b/examples/speedy-player/main.go index 97bf5a7..bf199d6 100644 --- a/examples/speedy-player/main.go +++ b/examples/speedy-player/main.go @@ -7,6 +7,7 @@ import ( "unicode" "github.com/gdamore/tcell/v2" + "github.com/gopxl/beep" "github.com/gopxl/beep/effects" "github.com/gopxl/beep/mp3" @@ -128,13 +129,21 @@ func (ap *audioPanel) handle(event tcell.Event) (changed, quit bool) { case 'z': speaker.Lock() - ap.resampler.SetRatio(ap.resampler.Ratio() * 15 / 16) + newRatio := ap.resampler.Ratio() * 15 / 16 + if newRatio < 0.001 { + newRatio = 0.001 + } + ap.resampler.SetRatio(newRatio) speaker.Unlock() return true, false case 'x': speaker.Lock() - ap.resampler.SetRatio(ap.resampler.Ratio() * 16 / 15) + newRatio := ap.resampler.Ratio() * 16 / 15 + if newRatio > 100 { + newRatio = 100 + } + ap.resampler.SetRatio(newRatio) speaker.Unlock() return true, false }