From d1f46a92df0e5aae14264f12731a4751588ad6d0 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 8 Feb 2016 01:52:36 +0900 Subject: [PATCH] audio: Refactoring --- internal/audio/audio.go | 12 ++++++++++++ internal/audio/audio_js.go | 4 ---- internal/audio/audio_openal.go | 9 --------- internal/audio/audio_windows.go | 3 --- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/internal/audio/audio.go b/internal/audio/audio.go index fb8f0e96e..06a22d1cf 100644 --- a/internal/audio/audio.go +++ b/internal/audio/audio.go @@ -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) diff --git a/internal/audio/audio_js.go b/internal/audio/audio_js.go index 66572b012..4e9a4a94b 100644 --- a/internal/audio/audio_js.go +++ b/internal/audio/audio_js.go @@ -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{} diff --git a/internal/audio/audio_openal.go b/internal/audio/audio_openal.go index 21f233aaa..01ae57b44 100644 --- a/internal/audio/audio_openal.go +++ b/internal/audio/audio_openal.go @@ -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{}) diff --git a/internal/audio/audio_windows.go b/internal/audio/audio_windows.go index a8c14273f..e470c85af 100644 --- a/internal/audio/audio_windows.go +++ b/internal/audio/audio_windows.go @@ -14,8 +14,5 @@ package audio -func withChannels(f func()) { -} - func initialize() { }