From 54a13b2ada6b9edc34d529d3e779a27da589cc86 Mon Sep 17 00:00:00 2001 From: davidovski Date: Mon, 22 Apr 2024 18:42:03 +0100 Subject: compress ambient audio --- main.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index a2a8276..7ef0c9d 100644 --- a/main.go +++ b/main.go @@ -15,6 +15,7 @@ import ( "github.com/hajimehoshi/ebiten/v2/inpututil" "github.com/hajimehoshi/ebiten/v2/audio" "github.com/hajimehoshi/ebiten/v2/audio/wav" + "github.com/hajimehoshi/ebiten/v2/audio/vorbis" ) @@ -64,8 +65,8 @@ var ( //go:embed assets/start.wav startWav_src []byte - //go:embed assets/ambient.wav - ambientWav_src []byte + //go:embed assets/ambient.ogg + ambientOgg_src []byte ) var ( @@ -551,6 +552,21 @@ func (g *Game) SetPlacing() { g.StopRewinding() } +func loadAudioVorbis(oggFile []byte, audioContext *audio.Context) *audio.Player { + + var err error + sound, err := vorbis.DecodeWithoutResampling(bytes.NewReader(oggFile)) + if err != nil { + return nil + } + + p, err := audioContext.NewPlayer(sound) + + if err != nil { + return nil + } + return p +} func loadAudio(wavFile []byte, audioContext *audio.Context) *audio.Player { var err error @@ -574,7 +590,7 @@ func (g *Game) LoadAudio() { g.audioPlayer.rewindAudio = loadAudio(rewindWav_src, g.audioPlayer.audioContext) g.audioPlayer.stopAudio = loadAudio(stopWav_src, g.audioPlayer.audioContext) g.audioPlayer.startAudio = loadAudio(startWav_src, g.audioPlayer.audioContext) - g.audioPlayer.ambientAudio = loadAudio(ambientWav_src, g.audioPlayer.audioContext) + g.audioPlayer.ambientAudio = loadAudioVorbis(ambientOgg_src, g.audioPlayer.audioContext) if g.audioPlayer.ambientAudio == nil { fmt.Printf("AUDIO NUL") -- cgit v1.2.1