8000 Assert the resampler ratio is a valid number by MarkKremer · Pull Request #120 · gopxl/beep · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Assert the resampler ratio is a valid number #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md 10000
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Upgrade Go version to 1.21 ([#2](https://github.com/gopxl/beep/pull/2))
- Upgrade Oto version to 3.1 ([#3](https://github.com/gopxl/beep/pull/3))
- Panic when `Resampler` is given a ratio of `Inf` or `NaN`. ([#120](https://github.com/gopxl/beep/pull/120))

## [v1.0.0] 2023-10-07
- Forked [faiface/beep](https://github.com/faiface/beep) to [gopxl/beep](https://github.com/gopxl/beep).
11 changes: 10 additions & 1 deletion resample.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package beep

import "fmt"
import (
"fmt"
"math"
)

// Resample takes a Streamer which is assumed to stream at the old sample rate and returns a
// Streamer, which streams the data from the original Streamer resampled to the new sample rate.
Expand Down Expand Up @@ -44,6 +47,9 @@ func ResampleRatio(quality int, ratio float64, s Streamer) *Resampler {
if quality < 1 || 64 < quality {
panic(fmt.Errorf("resample: invalid quality: %d", quality))
}
if math.IsInf(ratio, 0) || math.IsNaN(ratio) {
panic(fmt.Errorf("resample: invalid ratio: %d", ratio))
}
return &Resampler{
s: s,
ratio: ratio,
Expand Down Expand Up @@ -148,6 +154,9 @@ func (r *Resampler) Ratio() float64 {

// SetRatio sets the resampling ratio. This does not cause any glitches in the stream.
func (r *Resampler) SetRatio(ratio float64) {
if math.IsInf(ratio, 0) || math.IsNaN(ratio) {
panic(fmt.Errorf("resample: invalid ratio: %d", ratio))
}
r.pos = int(float64(r.pos) * r.ratio / ratio)
r.ratio = ratio
}
Expand Down
0