From 00b530bfcc58ed8c36a5820b6175677c3abffc20 Mon Sep 17 00:00:00 2001 From: Vseslav Kochenov Date: Sat, 23 Jul 2022 12:32:22 +0300 Subject: [PATCH] audio: add Resample (#2212) Closes #2055 --- audio/audio.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/audio/audio.go b/audio/audio.go index a91046ec3..09ee026b4 100644 --- a/audio/audio.go +++ b/audio/audio.go @@ -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) +}