mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
audio: Refactoring
This commit is contained in:
parent
c94f94cc17
commit
d1f46a92df
@ -14,6 +14,10 @@
|
||||
|
||||
package audio
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
var audioEnabled = false
|
||||
|
||||
const SampleRate = 44100
|
||||
@ -39,6 +43,14 @@ func Init() {
|
||||
initialize()
|
||||
}
|
||||
|
||||
var channelsMutex = sync.Mutex{}
|
||||
|
||||
func withChannels(f func()) {
|
||||
channelsMutex.Lock()
|
||||
defer channelsMutex.Unlock()
|
||||
f()
|
||||
}
|
||||
|
||||
func isPlaying(channel int) bool {
|
||||
ch := channels[channel]
|
||||
return ch.nextInsertionPosition < len(ch.buffer)
|
||||
|
@ -20,10 +20,6 @@ import (
|
||||
"github.com/gopherjs/gopherjs/js"
|
||||
)
|
||||
|
||||
func withChannels(f func()) {
|
||||
f()
|
||||
}
|
||||
|
||||
// Keep this so as not to be destroyed by GC.
|
||||
var (
|
||||
nodes = []*js.Object{}
|
||||
|
@ -19,20 +19,11 @@ package audio
|
||||
import (
|
||||
"log"
|
||||
"runtime"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"golang.org/x/mobile/exp/audio/al"
|
||||
)
|
||||
|
||||
var channelsMutex = sync.Mutex{}
|
||||
|
||||
func withChannels(f func()) {
|
||||
channelsMutex.Lock()
|
||||
defer channelsMutex.Unlock()
|
||||
f()
|
||||
}
|
||||
|
||||
func initialize() {
|
||||
// Creating OpenAL device must be done after initializing UI. I'm not sure the reason.
|
||||
ch := make(chan struct{})
|
||||
|
@ -14,8 +14,5 @@
|
||||
|
||||
package audio
|
||||
|
||||
func withChannels(f func()) {
|
||||
}
|
||||
|
||||
func initialize() {
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user