summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavidovski <david@davidovski.xyz>2024-04-22 18:42:03 +0100
committerdavidovski <david@davidovski.xyz>2024-04-22 18:42:03 +0100
commit54a13b2ada6b9edc34d529d3e779a27da589cc86 (patch)
tree6c279ef4b52f64e9c5c75881dff59d20e802205c
parent0c46c616a126569f778b04ea2c7bf04e34664939 (diff)
compress ambient audio
-rw-r--r--assets/ambient.oggbin0 -> 2893087 bytes
-rw-r--r--assets/tiles.pngbin4612 -> 4654 bytes
-rw-r--r--go.mod2
-rw-r--r--main.go22
4 files changed, 21 insertions, 3 deletions
diff --git a/assets/ambient.ogg b/assets/ambient.ogg
new file mode 100644
index 0000000..f64284c
--- /dev/null
+++ b/assets/ambient.ogg
Binary files differ
diff --git a/assets/tiles.png b/assets/tiles.png
index e5e0bd4..58096da 100644
--- a/assets/tiles.png
+++ b/assets/tiles.png
Binary files 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")