mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-27 12:18:55 +01:00
examples/wav: add -bits option to specify 8bits
This commit is contained in:
parent
0eb2b9980d
commit
1cd6a1f10c
@ -22,6 +22,9 @@ var (
|
|||||||
//go:embed jab.wav
|
//go:embed jab.wav
|
||||||
Jab_wav []byte
|
Jab_wav []byte
|
||||||
|
|
||||||
|
//go:embed jab8.wav
|
||||||
|
Jab8_wav []byte
|
||||||
|
|
||||||
//go:embed jump.ogg
|
//go:embed jump.ogg
|
||||||
Jump_ogg []byte
|
Jump_ogg []byte
|
||||||
|
|
||||||
|
BIN
examples/resources/audio/jab8.wav
Normal file
BIN
examples/resources/audio/jab8.wav
Normal file
Binary file not shown.
@ -16,6 +16,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"flag"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2"
|
"github.com/hajimehoshi/ebiten/v2"
|
||||||
@ -32,6 +34,10 @@ const (
|
|||||||
sampleRate = 48000
|
sampleRate = 48000
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
flagBitsPerSample = flag.Int("bits", 16, "bits per sample")
|
||||||
|
)
|
||||||
|
|
||||||
type Game struct {
|
type Game struct {
|
||||||
audioContext *audio.Context
|
audioContext *audio.Context
|
||||||
audioPlayer *audio.Player
|
audioPlayer *audio.Player
|
||||||
@ -59,7 +65,14 @@ func NewGame() (*Game, error) {
|
|||||||
// ...
|
// ...
|
||||||
|
|
||||||
// Decode wav-formatted data and retrieve decoded PCM stream.
|
// Decode wav-formatted data and retrieve decoded PCM stream.
|
||||||
d, err := wav.DecodeWithoutResampling(bytes.NewReader(raudio.Jab_wav))
|
var r io.Reader
|
||||||
|
switch *flagBitsPerSample {
|
||||||
|
case 8:
|
||||||
|
r = bytes.NewReader(raudio.Jab8_wav)
|
||||||
|
default:
|
||||||
|
r = bytes.NewReader(raudio.Jab_wav)
|
||||||
|
}
|
||||||
|
d, err := wav.DecodeWithoutResampling(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -99,6 +112,7 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
g, err := NewGame()
|
g, err := NewGame()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user