audio: Refactoring

This commit is contained in:
Hajime Hoshi 2016-02-08 01:52:36 +09:00
parent c94f94cc17
commit d1f46a92df
4 changed files with 12 additions and 16 deletions

View File

@ -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)

View File

@ -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{}

View File

@ -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{})

View File

@ -14,8 +14,5 @@
package audio
func withChannels(f func()) {
}
func initialize() {
}