mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
audio: audio.NewContext now returns error
This commit is contained in:
parent
e631714a43
commit
1ec786f83a
@ -253,7 +253,10 @@ func main() {
|
|||||||
}
|
}
|
||||||
const sampleRate = 22050
|
const sampleRate = 22050
|
||||||
const bytesPerSample = 4 // TODO: This should be defined in audio package
|
const bytesPerSample = 4 // TODO: This should be defined in audio package
|
||||||
audioContext = audio.NewContext(sampleRate)
|
audioContext, err = audio.NewContext(sampleRate)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
go func() {
|
go func() {
|
||||||
s, err := wav.Decode(audioContext, wavF)
|
s, err := wav.Decode(audioContext, wavF)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -34,7 +34,11 @@ const (
|
|||||||
var audioContext *audio.Context
|
var audioContext *audio.Context
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
audioContext = audio.NewContext(sampleRate)
|
var err error
|
||||||
|
audioContext, err = audio.NewContext(sampleRate)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var frames = 0
|
var frames = 0
|
||||||
|
@ -36,7 +36,11 @@ const (
|
|||||||
var audioContext *audio.Context
|
var audioContext *audio.Context
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
audioContext = audio.NewContext(sampleRate)
|
var err error
|
||||||
|
audioContext, err = audio.NewContext(sampleRate)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var pcm = make([]float64, 4*sampleRate)
|
var pcm = make([]float64, 4*sampleRate)
|
||||||
|
@ -35,7 +35,11 @@ const (
|
|||||||
var audioContext *audio.Context
|
var audioContext *audio.Context
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
audioContext = audio.NewContext(sampleRate)
|
var err error
|
||||||
|
audioContext, err = audio.NewContext(sampleRate)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type stream struct {
|
type stream struct {
|
||||||
|
@ -112,7 +112,7 @@ type Context struct {
|
|||||||
sync.Mutex
|
sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewContext(sampleRate int) *Context {
|
func NewContext(sampleRate int) (*Context, error) {
|
||||||
// TODO: Panic if one context exists.
|
// TODO: Panic if one context exists.
|
||||||
c := &Context{
|
c := &Context{
|
||||||
sampleRate: sampleRate,
|
sampleRate: sampleRate,
|
||||||
@ -122,9 +122,9 @@ func NewContext(sampleRate int) *Context {
|
|||||||
context: c,
|
context: c,
|
||||||
}
|
}
|
||||||
if err := startPlaying(c.stream, c.sampleRate); err != nil {
|
if err := startPlaying(c.stream, c.sampleRate); err != nil {
|
||||||
panic(fmt.Sprintf("audio: NewContext error: %v", err))
|
return nil, fmt.Errorf("audio: NewContext error: %v", err)
|
||||||
}
|
}
|
||||||
return c
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update proceeds the inner (logical) time of the context by 1/60 second.
|
// Update proceeds the inner (logical) time of the context by 1/60 second.
|
||||||
|
Loading…
Reference in New Issue
Block a user