Skip to content

Commit

Permalink
Limit resample ratio in speedy-player example
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkKremer committed Jul 11, 2024
1 parent 0705855 commit 6fbcee9
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions examples/speedy-player/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 6fbcee9

Please sign in to comment.