diff options
author | davidovski <david@davidovski.xyz> | 2024-04-22 18:42:03 +0100 |
---|---|---|
committer | davidovski <david@davidovski.xyz> | 2024-04-22 18:42:03 +0100 |
commit | 54a13b2ada6b9edc34d529d3e779a27da589cc86 (patch) | |
tree | 6c279ef4b52f64e9c5c75881dff59d20e802205c | |
parent | 0c46c616a126569f778b04ea2c7bf04e34664939 (diff) |
compress ambient audio
-rw-r--r-- | assets/ambient.ogg | bin | 0 -> 2893087 bytes | |||
-rw-r--r-- | assets/tiles.png | bin | 4612 -> 4654 bytes | |||
-rw-r--r-- | go.mod | 2 | ||||
-rw-r--r-- | main.go | 22 |
4 files changed, 21 insertions, 3 deletions
diff --git a/assets/ambient.ogg b/assets/ambient.ogg Binary files differnew file mode 100644 index 0000000..f64284c --- /dev/null +++ b/assets/ambient.ogg diff --git a/assets/tiles.png b/assets/tiles.png Binary files differindex e5e0bd4..58096da 100644 --- a/assets/tiles.png +++ b/assets/tiles.png @@ -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 ) @@ -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") |