audio: add Resample (#2212)

Closes #2055
This commit is contained in:
Vseslav Kochenov 2022-07-23 12:32:22 +03:00 committed by GitHub
parent 017ad69e93
commit 00b530bfcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,6 +40,7 @@ import (
"sync"
"time"
"github.com/hajimehoshi/ebiten/v2/audio/internal/convert"
"github.com/hajimehoshi/ebiten/v2/internal/hooks"
)
@ -435,3 +436,13 @@ func (h *hookImpl) OnResumeAudio(f func() error) {
func (h *hookImpl) AppendHookOnBeforeUpdate(f func() error) {
hooks.AppendHookOnBeforeUpdate(f)
}
// Resample explicitly resamples a stream to fit a new sample rate.
//
// If original sample rate matches the new one, Resample returns source as it is.
func Resample(source io.ReadSeeker, size int64, from, to int) io.ReadSeeker {
if from == to {
return source
}
return convert.NewResampling(source, size, from, to)
}