Skip to content

Commit

Permalink
21/8/21 12:18 PM
Browse files Browse the repository at this point in the history
  • Loading branch information
eboatwright committed Aug 21, 2021
1 parent 7e60a63 commit 5b2e92c
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 1 deletion.
19 changes: 19 additions & 0 deletions audio.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package pearl


import (
"github.com/hajimehoshi/ebiten/v2/audio"
"github.com/hajimehoshi/ebiten/v2/audio/wav"

"os"
)


func PlaySoundFromFile(path string) {
sfx, _ := os.Open(path)
decoded, _ := wav.Decode(g.audioContext, sfx)
player, _ := audio.NewPlayer(g.audioContext, decoded)

player.Rewind()
player.Play()
}
15 changes: 15 additions & 0 deletions examples/5-audio/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main


import (
"github.com/eboatwright/pearl"
)


func main() {
pearl.Start(960, 600, 3, "Audio Test", pearl.RGBA(0, 0, 0, 255), func() {
scene := &pearl.Scene { ID: "scene" }
pearl.LoadScene(scene)
pearl.PlaySoundFromFile("test.wav")
})
}
Binary file added examples/5-audio/test.wav
Binary file not shown.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/eboatwright/pearl

go 1.16

require github.com/hajimehoshi/ebiten/v2 v2.1.4 // indirect
require github.com/hajimehoshi/ebiten/v2 v2.1.4
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210410170116-ea3d685f79fb h1:T6gaWBvRzJjuOrdCtg8fXXjKai2xSDqWTcKFUPuw8Tw=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210410170116-ea3d685f79fb/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/gofrs/flock v0.8.0 h1:MSdYClljsF3PbENUUEx85nkWfJSGfzYI9yEBZOJz6CY=
github.com/gofrs/flock v0.8.0/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
github.com/hajimehoshi/bitmapfont/v2 v2.1.3/go.mod h1:2BnYrkTQGThpr/CY6LorYtt/zEPNzvE/ND69CRTaHMs=
github.com/hajimehoshi/ebiten/v2 v2.1.4 h1:ok1sjnDUm1VHVRvI4HEHzk7CjAsnNj/dqIo2/ObGcy4=
github.com/hajimehoshi/ebiten/v2 v2.1.4/go.mod h1:mpAvpmTRbMdhQDZplZ4rfEogRhdsfAGTC0zLhxawKHY=
github.com/hajimehoshi/file2byteslice v0.0.0-20200812174855-0e5e8a80490e/go.mod h1:CqqAHp7Dk/AqQiwuhV1yT2334qbA/tFWQW0MD2dGqUE=
github.com/hajimehoshi/go-mp3 v0.3.2/go.mod h1:qMJj/CSDxx6CGHiZeCgbiq2DSUkbK0UbtXShQcnfyMM=
github.com/hajimehoshi/oto v0.6.1/go.mod h1:0QXGEkbuJRohbJaxr7ZQSxnju7hEhseiPx2hrh6raOI=
github.com/hajimehoshi/oto v0.7.1 h1:I7maFPz5MBCwiutOrz++DLdbr4rTzBsbBuV2VpgU9kk=
github.com/hajimehoshi/oto v0.7.1/go.mod h1:wovJ8WWMfFKvP587mhHgot/MBr4DnNy9m6EepeVGnos=
github.com/jakecoffman/cp v1.1.0/go.mod h1:JjY/Fp6d8E1CHnu74gWNnU0+b9VzEdUVPoJxg2PsTQg=
github.com/jfreymuth/oggvorbis v1.0.3/go.mod h1:1U4pqWmghcoVsCJJ4fRBKv9peUJMBHixthRlBeD6uII=
Expand Down
3 changes: 3 additions & 0 deletions pearl.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package pearl
import (
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
"github.com/hajimehoshi/ebiten/v2/audio"

"image/color"
"fmt"
Expand All @@ -22,6 +23,7 @@ type game struct {
currentScene *Scene
showFPS bool
timeStart time.Time
audioContext *audio.Context
}

func (g *game) Update() error {
Expand Down Expand Up @@ -75,6 +77,7 @@ func Start(windowWidth, windowHeight, screenScale int, windowTitle string, backg
windowTitle: windowTitle,
backgroundColor: backgroundColor,
timeStart: time.Now(),
audioContext: audio.NewContext(48000),
}

ebiten.SetWindowSize(g.windowWidth, g.windowHeight)
Expand Down

0 comments on commit 5b2e92c

Please sign in to comment.