mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
audio: At most one audio context can exist (#271)
This commit is contained in:
parent
2eac8dca8c
commit
61676616a7
@ -186,12 +186,22 @@ type Context struct {
|
||||
writtenBytes int
|
||||
}
|
||||
|
||||
var (
|
||||
theContext *Context
|
||||
theContextLock sync.Mutex
|
||||
)
|
||||
|
||||
// NewContext creates a new audio context with the given sample rate (e.g. 44100).
|
||||
func NewContext(sampleRate int) (*Context, error) {
|
||||
// TODO: Panic if one context exists.
|
||||
theContextLock.Lock()
|
||||
defer theContextLock.Unlock()
|
||||
if theContext != nil {
|
||||
return nil, errors.New("audio: context is already created")
|
||||
}
|
||||
c := &Context{
|
||||
sampleRate: sampleRate,
|
||||
}
|
||||
theContext = c
|
||||
c.players = &players{
|
||||
players: map[*Player]struct{}{},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user