Add sound effect
This commit is contained in:
parent
d53f8150ef
commit
a16f89fe9c
21
main.go
21
main.go
@ -5,20 +5,23 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
|
"io"
|
||||||
|
|
||||||
"github.com/clktmr/n64/drivers/cartfs"
|
"github.com/clktmr/n64/drivers/cartfs"
|
||||||
"github.com/clktmr/n64/drivers/controller"
|
"github.com/clktmr/n64/drivers/controller"
|
||||||
"github.com/clktmr/n64/drivers/display"
|
"github.com/clktmr/n64/drivers/display"
|
||||||
"github.com/clktmr/n64/drivers/draw"
|
"github.com/clktmr/n64/drivers/draw"
|
||||||
|
"github.com/clktmr/n64/drivers/rspq/mixer"
|
||||||
"github.com/clktmr/n64/fonts/gomono12"
|
"github.com/clktmr/n64/fonts/gomono12"
|
||||||
_ "github.com/clktmr/n64/machine"
|
_ "github.com/clktmr/n64/machine"
|
||||||
|
"github.com/clktmr/n64/rcp/audio"
|
||||||
"github.com/clktmr/n64/rcp/serial/joybus"
|
"github.com/clktmr/n64/rcp/serial/joybus"
|
||||||
"github.com/clktmr/n64/rcp/texture"
|
"github.com/clktmr/n64/rcp/texture"
|
||||||
"github.com/clktmr/n64/rcp/video"
|
"github.com/clktmr/n64/rcp/video"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
//go:embed gopher-anim.CI8
|
//go:embed gopher-anim.CI8 squeak.pcm_s16be
|
||||||
_tutorialFiles embed.FS
|
_tutorialFiles embed.FS
|
||||||
tutorialFiles cartfs.FS = cartfs.Embed(_tutorialFiles)
|
tutorialFiles cartfs.FS = cartfs.Embed(_tutorialFiles)
|
||||||
)
|
)
|
||||||
@ -53,6 +56,20 @@ func main() {
|
|||||||
gopherRect := image.Rect(0, 0, 128, 128)
|
gopherRect := image.Rect(0, 0, 128, 128)
|
||||||
blows := 0
|
blows := 0
|
||||||
|
|
||||||
|
audio.Start(48000)
|
||||||
|
mixer.Init()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
audio.Buffer.ReadFrom(mixer.Output)
|
||||||
|
}()
|
||||||
|
|
||||||
|
squeakFile, err := tutorialFiles.Open("squeak.pcm_s16be")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
squeakReader := squeakFile.(io.ReadSeeker)
|
||||||
|
squeakSource := mixer.NewSource(squeakReader, 16000)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
fb := display.Swap() // Blocks until next VBlank
|
fb := display.Swap() // Blocks until next VBlank
|
||||||
input := <-controllers
|
input := <-controllers
|
||||||
@ -71,6 +88,8 @@ func main() {
|
|||||||
if blows < 8 {
|
if blows < 8 {
|
||||||
if input[0].Pressed()&joybus.ButtonA != 0 {
|
if input[0].Pressed()&joybus.ButtonA != 0 {
|
||||||
blows++
|
blows++
|
||||||
|
squeakReader.Seek(0, io.SeekStart)
|
||||||
|
mixer.SetSource(0, squeakSource)
|
||||||
}
|
}
|
||||||
if input[0].Down()&joybus.ButtonA != 0 {
|
if input[0].Down()&joybus.ButtonA != 0 {
|
||||||
gopherFrame.X += 128 // blowing gopher
|
gopherFrame.X += 128 // blowing gopher
|
||||||
|
|||||||
BIN
squeak.pcm_s16be
Normal file
BIN
squeak.pcm_s16be
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user