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
|
package audio
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
var audioEnabled = false
|
var audioEnabled = false
|
||||||
|
|
||||||
const SampleRate = 44100
|
const SampleRate = 44100
|
||||||
@ -39,6 +43,14 @@ func Init() {
|
|||||||
initialize()
|
initialize()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var channelsMutex = sync.Mutex{}
|
||||||
|
|
||||||
|
func withChannels(f func()) {
|
||||||
|
channelsMutex.Lock()
|
||||||
|
defer channelsMutex.Unlock()
|
||||||
|
f()
|
||||||
|
}
|
||||||
|
|
||||||
func isPlaying(channel int) bool {
|
func isPlaying(channel int) bool {
|
||||||
ch := channels[channel]
|
ch := channels[channel]
|
||||||
return ch.nextInsertionPosition < len(ch.buffer)
|
return ch.nextInsertionPosition < len(ch.buffer)
|
||||||
|
@ -20,10 +20,6 @@ import (
|
|||||||
"github.com/gopherjs/gopherjs/js"
|
"github.com/gopherjs/gopherjs/js"
|
||||||
)
|
)
|
||||||
|
|
||||||
func withChannels(f func()) {
|
|
||||||
f()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Keep this so as not to be destroyed by GC.
|
// Keep this so as not to be destroyed by GC.
|
||||||
var (
|
var (
|
||||||
nodes = []*js.Object{}
|
nodes = []*js.Object{}
|
||||||
|
@ -19,20 +19,11 @@ package audio
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/mobile/exp/audio/al"
|
"golang.org/x/mobile/exp/audio/al"
|
||||||
)
|
)
|
||||||
|
|
||||||
var channelsMutex = sync.Mutex{}
|
|
||||||
|
|
||||||
func withChannels(f func()) {
|
|
||||||
channelsMutex.Lock()
|
|
||||||
defer channelsMutex.Unlock()
|
|
||||||
f()
|
|
||||||
}
|
|
||||||
|
|
||||||
func initialize() {
|
func initialize() {
|
||||||
// Creating OpenAL device must be done after initializing UI. I'm not sure the reason.
|
// Creating OpenAL device must be done after initializing UI. I'm not sure the reason.
|
||||||
ch := make(chan struct{})
|
ch := make(chan struct{})
|
||||||
|
@ -14,8 +14,5 @@
|
|||||||
|
|
||||||
package audio
|
package audio
|
||||||
|
|
||||||
func withChannels(f func()) {
|
|
||||||
}
|
|
||||||
|
|
||||||
func initialize() {
|
func initialize() {
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user