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.
|
||||
// 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.
|
||||
func NewContext(sampleRate int) (*Context, error) {
|
||||
func NewContext(sampleRate int) *Context {
|
||||
theContextLock.Lock()
|
||||
defer theContextLock.Unlock()
|
||||
if theContext != nil {
|
||||
@ -127,7 +125,7 @@ func NewContext(sampleRate int) (*Context, error) {
|
||||
return err
|
||||
})
|
||||
|
||||
return c, nil
|
||||
return c
|
||||
}
|
||||
|
||||
// CurrentContext returns the current context or nil if there is no context.
|
||||
|
@ -25,11 +25,7 @@ import (
|
||||
var context *Context
|
||||
|
||||
func setup() {
|
||||
var err error
|
||||
context, err = NewContext(44100)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
context = NewContext(44100)
|
||||
}
|
||||
|
||||
func teardown() {
|
||||
|
@ -23,15 +23,7 @@ import (
|
||||
. "github.com/hajimehoshi/ebiten/v2/audio/vorbis"
|
||||
)
|
||||
|
||||
var audioContext *audio.Context
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
audioContext, err = audio.NewContext(44100)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
var audioContext = audio.NewContext(44100)
|
||||
|
||||
func TestMono(t *testing.T) {
|
||||
bs := test_mono_ogg
|
||||
|
@ -267,10 +267,7 @@ type Game struct {
|
||||
}
|
||||
|
||||
func NewGame() (*Game, error) {
|
||||
audioContext, err := audio.NewContext(sampleRate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
audioContext := audio.NewContext(sampleRate)
|
||||
|
||||
m, err := NewPlayer(audioContext, typeOgg)
|
||||
if err != nil {
|
||||
|
@ -37,15 +37,7 @@ const (
|
||||
loopLengthInSecond = 4
|
||||
)
|
||||
|
||||
var audioContext *audio.Context
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
audioContext, err = audio.NewContext(sampleRate)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
var audioContext = audio.NewContext(sampleRate)
|
||||
|
||||
type Game struct {
|
||||
player *audio.Player
|
||||
|
@ -41,15 +41,7 @@ const (
|
||||
|
||||
var img *ebiten.Image
|
||||
|
||||
var audioContext *audio.Context
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
audioContext, err = audio.NewContext(sampleRate)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
var audioContext = audio.NewContext(sampleRate)
|
||||
|
||||
type Game struct {
|
||||
player *audio.Player
|
||||
|
@ -116,14 +116,12 @@ func init() {
|
||||
}
|
||||
|
||||
var (
|
||||
audioContext *audio.Context
|
||||
audioContext = audio.NewContext(44100)
|
||||
jumpPlayer *audio.Player
|
||||
hitPlayer *audio.Player
|
||||
)
|
||||
|
||||
func init() {
|
||||
audioContext, _ = audio.NewContext(44100)
|
||||
|
||||
jumpD, err := vorbis.Decode(audioContext, audio.BytesReadSeekCloser(raudio.Jump_ogg))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
@ -32,15 +32,7 @@ const (
|
||||
sampleRate = 44100
|
||||
)
|
||||
|
||||
var audioContext *audio.Context
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
audioContext, err = audio.NewContext(sampleRate)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
var audioContext = audio.NewContext(sampleRate)
|
||||
|
||||
const (
|
||||
freqA = 440.0
|
||||
|
@ -64,15 +64,7 @@ const (
|
||||
baseFreq = 220
|
||||
)
|
||||
|
||||
var audioContext *audio.Context
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
audioContext, err = audio.NewContext(sampleRate)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
var audioContext = audio.NewContext(sampleRate)
|
||||
|
||||
// pianoAt returns an i-th sample of piano with the given frequency.
|
||||
func pianoAt(i int, freq float64) float64 {
|
||||
|
@ -33,15 +33,7 @@ const (
|
||||
frequency = 440
|
||||
)
|
||||
|
||||
var audioContext *audio.Context
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
audioContext, err = audio.NewContext(sampleRate)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
var audioContext = audio.NewContext(sampleRate)
|
||||
|
||||
// stream is an infinite stream of 440 Hz sine wave.
|
||||
type stream struct {
|
||||
|
@ -42,10 +42,7 @@ var g Game
|
||||
func init() {
|
||||
var err error
|
||||
// Initialize audio context.
|
||||
g.audioContext, err = audio.NewContext(sampleRate)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
g.audioContext = audio.NewContext(sampleRate)
|
||||
|
||||
// In this example, embedded resource "Jab_wav" is used.
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user