mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38: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
|
||||
Jab_wav []byte
|
||||
|
||||
//go:embed jab8.wav
|
||||
Jab8_wav []byte
|
||||
|
||||
//go:embed jump.ogg
|
||||
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 (
|
||||
"bytes"
|
||||
"flag"
|
||||
"io"
|
||||
"log"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
@ -32,6 +34,10 @@ const (
|
||||
sampleRate = 48000
|
||||
)
|
||||
|
||||
var (
|
||||
flagBitsPerSample = flag.Int("bits", 16, "bits per sample")
|
||||
)
|
||||
|
||||
type Game struct {
|
||||
audioContext *audio.Context
|
||||
audioPlayer *audio.Player
|
||||
@ -59,7 +65,14 @@ func NewGame() (*Game, error) {
|
||||
// ...
|
||||
|
||||
// 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 {
|
||||
return nil, err
|
||||
}
|
||||
@ -99,6 +112,7 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
g, err := NewGame()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
Loading…
Reference in New Issue
Block a user