Files
game-driver/pkg/audio/context.go
mapleafgo ec168be827
Some checks failed
ci/woodpecker/tag/woodpecker Pipeline failed
feat(audio): 使用 Windowed Sinc 高质量重采样器替代线性插值
统一音频输出采样率为 44100Hz,使用 go-audio-resampler 库实现
Windowed Sinc + Polyphase FIR 算法(VeryHigh 28-bit 精度),
替代原有的线性插值透传方案。

主要变更:
- 新增 sincResampler:三阶段 Read 循环(填充→处理→Flush)
- 双缓冲区架构避免输出样本丢失,复用内存减少 GC 压力
- WAV/MP3/BGM 播放管线全部接入 Sinc 重采样器
- 移除旧的 linearResampler 和透传模式

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 01:35:04 +08:00

38 lines
659 B
Go

package audio
import (
"sync"
"github.com/ebitengine/oto/v3"
"go.uber.org/zap"
)
var (
otoCtx *oto.Context
otoOnce sync.Once
)
const (
UniversalSampleRate = 44100
DefaultChannelCount = 2
)
func initContext() (*oto.Context, error) {
var initErr error
otoOnce.Do(func() {
op := &oto.NewContextOptions{}
op.SampleRate = UniversalSampleRate
op.ChannelCount = DefaultChannelCount
op.Format = oto.FormatSignedInt16LE
var ready <-chan struct{}
otoCtx, ready, initErr = oto.NewContext(op)
if initErr != nil {
return
}
<-ready
zap.S().Infof("oto/v3 音频系统就绪 (%d Hz)", UniversalSampleRate)
})
return otoCtx, initErr
}