mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +01:00
parent
29b4087ebf
commit
944a19c6f7
@ -84,10 +84,8 @@ var (
|
|||||||
// Other values might not work.
|
// Other values might not work.
|
||||||
// For example, 22050 causes error on Safari when decoding MP3.
|
// For example, 22050 causes error on Safari when decoding MP3.
|
||||||
//
|
//
|
||||||
// Error returned by NewContext is always nil as of 1.5.0-alpha.
|
|
||||||
//
|
|
||||||
// NewContext panics when an audio context is already created.
|
// NewContext panics when an audio context is already created.
|
||||||
func NewContext(sampleRate int) (*Context, error) {
|
func NewContext(sampleRate int) *Context {
|
||||||
theContextLock.Lock()
|
theContextLock.Lock()
|
||||||
defer theContextLock.Unlock()
|
defer theContextLock.Unlock()
|
||||||
if theContext != nil {
|
if theContext != nil {
|
||||||
@ -127,7 +125,7 @@ func NewContext(sampleRate int) (*Context, error) {
|
|||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
|
|
||||||
return c, nil
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
// CurrentContext returns the current context or nil if there is no context.
|
// CurrentContext returns the current context or nil if there is no context.
|
||||||
|
@ -25,11 +25,7 @@ import (
|
|||||||
var context *Context
|
var context *Context
|
||||||
|
|
||||||
func setup() {
|
func setup() {
|
||||||
var err error
|
context = NewContext(44100)
|
||||||
context, err = NewContext(44100)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func teardown() {
|
func teardown() {
|
||||||
|
@ -23,15 +23,7 @@ import (
|
|||||||
. "github.com/hajimehoshi/ebiten/v2/audio/vorbis"
|
. "github.com/hajimehoshi/ebiten/v2/audio/vorbis"
|
||||||
)
|
)
|
||||||
|
|
||||||
var audioContext *audio.Context
|
var audioContext = audio.NewContext(44100)
|
||||||
|
|
||||||
func init() {
|
|
||||||
var err error
|
|
||||||
audioContext, err = audio.NewContext(44100)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMono(t *testing.T) {
|
func TestMono(t *testing.T) {
|
||||||
bs := test_mono_ogg
|
bs := test_mono_ogg
|
||||||
|
@ -267,10 +267,7 @@ type Game struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewGame() (*Game, error) {
|
func NewGame() (*Game, error) {
|
||||||
audioContext, err := audio.NewContext(sampleRate)
|
audioContext := audio.NewContext(sampleRate)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
m, err := NewPlayer(audioContext, typeOgg)
|
m, err := NewPlayer(audioContext, typeOgg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -37,15 +37,7 @@ const (
|
|||||||
loopLengthInSecond = 4
|
loopLengthInSecond = 4
|
||||||
)
|
)
|
||||||
|
|
||||||
var audioContext *audio.Context
|
var audioContext = audio.NewContext(sampleRate)
|
||||||
|
|
||||||
func init() {
|
|
||||||
var err error
|
|
||||||
audioContext, err = audio.NewContext(sampleRate)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type Game struct {
|
type Game struct {
|
||||||
player *audio.Player
|
player *audio.Player
|
||||||
|
@ -41,15 +41,7 @@ const (
|
|||||||
|
|
||||||
var img *ebiten.Image
|
var img *ebiten.Image
|
||||||
|
|
||||||
var audioContext *audio.Context
|
var audioContext = audio.NewContext(sampleRate)
|
||||||
|
|
||||||
func init() {
|
|
||||||
var err error
|
|
||||||
audioContext, err = audio.NewContext(sampleRate)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type Game struct {
|
type Game struct {
|
||||||
player *audio.Player
|
player *audio.Player
|
||||||
|
@ -116,14 +116,12 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
audioContext *audio.Context
|
audioContext = audio.NewContext(44100)
|
||||||
jumpPlayer *audio.Player
|
jumpPlayer *audio.Player
|
||||||
hitPlayer *audio.Player
|
hitPlayer *audio.Player
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
audioContext, _ = audio.NewContext(44100)
|
|
||||||
|
|
||||||
jumpD, err := vorbis.Decode(audioContext, audio.BytesReadSeekCloser(raudio.Jump_ogg))
|
jumpD, err := vorbis.Decode(audioContext, audio.BytesReadSeekCloser(raudio.Jump_ogg))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@ -32,15 +32,7 @@ const (
|
|||||||
sampleRate = 44100
|
sampleRate = 44100
|
||||||
)
|
)
|
||||||
|
|
||||||
var audioContext *audio.Context
|
var audioContext = audio.NewContext(sampleRate)
|
||||||
|
|
||||||
func init() {
|
|
||||||
var err error
|
|
||||||
audioContext, err = audio.NewContext(sampleRate)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
freqA = 440.0
|
freqA = 440.0
|
||||||
|
@ -64,15 +64,7 @@ const (
|
|||||||
baseFreq = 220
|
baseFreq = 220
|
||||||
)
|
)
|
||||||
|
|
||||||
var audioContext *audio.Context
|
var audioContext = audio.NewContext(sampleRate)
|
||||||
|
|
||||||
func init() {
|
|
||||||
var err error
|
|
||||||
audioContext, err = audio.NewContext(sampleRate)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// pianoAt returns an i-th sample of piano with the given frequency.
|
// pianoAt returns an i-th sample of piano with the given frequency.
|
||||||
func pianoAt(i int, freq float64) float64 {
|
func pianoAt(i int, freq float64) float64 {
|
||||||
|
@ -33,15 +33,7 @@ const (
|
|||||||
frequency = 440
|
frequency = 440
|
||||||
)
|
)
|
||||||
|
|
||||||
var audioContext *audio.Context
|
var audioContext = audio.NewContext(sampleRate)
|
||||||
|
|
||||||
func init() {
|
|
||||||
var err error
|
|
||||||
audioContext, err = audio.NewContext(sampleRate)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// stream is an infinite stream of 440 Hz sine wave.
|
// stream is an infinite stream of 440 Hz sine wave.
|
||||||
type stream struct {
|
type stream struct {
|
||||||
|
@ -42,10 +42,7 @@ var g Game
|
|||||||
func init() {
|
func init() {
|
||||||
var err error
|
var err error
|
||||||
// Initialize audio context.
|
// Initialize audio context.
|
||||||
g.audioContext, err = audio.NewContext(sampleRate)
|
g.audioContext = audio.NewContext(sampleRate)
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// In this example, embedded resource "Jab_wav" is used.
|
// In this example, embedded resource "Jab_wav" is used.
|
||||||
//
|
//
|
||||||
|
Loading…
Reference in New Issue
Block a user