From 719e5ba6d24e1efb1a288329dc62cf405890ff21 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 10 Feb 2016 00:09:23 +0900 Subject: [PATCH] audio: Remove audio.Tick --- internal/audio/audio.go | 15 --------------- internal/audio/audio_js.go | 28 ++++++++++++++++------------ internal/audio/audio_openal.go | 3 --- run.go | 3 --- 4 files changed, 16 insertions(+), 33 deletions(-) diff --git a/internal/audio/audio.go b/internal/audio/audio.go index dbdf70214..774aacc37 100644 --- a/internal/audio/audio.go +++ b/internal/audio/audio.go @@ -59,10 +59,6 @@ func emptyChannel() *channel { return nil } -func Tick() { - tick() -} - // TODO: Accept sample rate func Queue(data []byte) bool { result := true @@ -121,14 +117,3 @@ func loadChannelBuffer(channel int, bufferSize int) []byte { }) return r } - -func IsPlaying(channel int) bool { - result := false - withChannels(func() { - if !audioEnabled { - return - } - result = isPlaying(channel) - }) - return result -} diff --git a/internal/audio/audio_js.go b/internal/audio/audio_js.go index a25c46feb..819978916 100644 --- a/internal/audio/audio_js.go +++ b/internal/audio/audio_js.go @@ -17,6 +17,8 @@ package audio import ( + "time" + "github.com/gopherjs/gopherjs/js" ) @@ -73,18 +75,6 @@ func isPlaying(channel int) bool { return c < a.position } -func tick() { - const bufferSize = 1024 - c := context.Get("currentTime").Float() - for _, a := range audioProcessors { - if a.position < c { - a.position = c - } - // TODO: 4 is a magic number - a.playChunk(loadChannelBuffer(a.channel, bufferSize*4)) - } -} - func initialize() { // Do nothing in node.js. if js.Global.Get("require") != js.Undefined { @@ -107,4 +97,18 @@ func initialize() { position: 0, } } + go func() { + for { + const bufferSize = 1024 + c := context.Get("currentTime").Float() + for _, a := range audioProcessors { + if a.position < c { + a.position = c + } + // TODO: 4 is a magic number + a.playChunk(loadChannelBuffer(a.channel, bufferSize*4)) + } + time.Sleep(0) + } + }() } diff --git a/internal/audio/audio_openal.go b/internal/audio/audio_openal.go index 11fc3c559..afc4d5fa9 100644 --- a/internal/audio/audio_openal.go +++ b/internal/audio/audio_openal.go @@ -29,9 +29,6 @@ func isPlaying(channel int) bool { return 0 < len(ch.buffer) } -func tick() { -} - func initialize() { // Creating OpenAL device must be done after initializing UI. I'm not sure the reason. ch := make(chan struct{}) diff --git a/run.go b/run.go index 901e759ec..8fb77b850 100644 --- a/run.go +++ b/run.go @@ -17,7 +17,6 @@ package ebiten import ( "time" - "github.com/hajimehoshi/ebiten/internal/audio" "github.com/hajimehoshi/ebiten/internal/ui" ) @@ -93,8 +92,6 @@ func Run(f func(*Image) error, width, height, scale int, title string) error { runContext.newScreenHeight = 0 runContext.newScreenScale = 0 - audio.Tick() - if err := ui.DoEvents(); err != nil { return err }