From 54a13b2ada6b9edc34d529d3e779a27da589cc86 Mon Sep 17 00:00:00 2001 From: davidovski Date: Mon, 22 Apr 2024 18:42:03 +0100 Subject: compress ambient audio --- assets/ambient.ogg | Bin 0 -> 2893087 bytes assets/tiles.png | Bin 4612 -> 4654 bytes go.mod | 2 ++ main.go | 22 +++++++++++++++++++--- 4 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 assets/ambient.ogg diff --git a/assets/ambient.ogg b/assets/ambient.ogg new file mode 100644 index 0000000..f64284c Binary files /dev/null and b/assets/ambient.ogg differ diff --git a/assets/tiles.png b/assets/tiles.png index e5e0bd4..58096da 100644 Binary files a/assets/tiles.png and b/assets/tiles.png differ diff --git a/go.mod b/go.mod index 866b73f..0e8272e 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,8 @@ require ( github.com/ebitengine/oto/v3 v3.2.0 // indirect github.com/ebitengine/purego v0.7.0 // indirect github.com/jezek/xgb v1.1.1 // indirect + github.com/jfreymuth/oggvorbis v1.0.5 // indirect + github.com/jfreymuth/vorbis v1.0.2 // indirect golang.org/x/sync v0.6.0 // indirect golang.org/x/sys v0.18.0 // indirect ) 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