audio: Remove audio.Tick

This commit is contained in:
Hajime Hoshi 2016-02-10 00:09:23 +09:00
parent c5de32297f
commit 719e5ba6d2
4 changed files with 16 additions and 33 deletions

View File

@ -59,10 +59,6 @@ func emptyChannel() *channel {
return nil return nil
} }
func Tick() {
tick()
}
// TODO: Accept sample rate // TODO: Accept sample rate
func Queue(data []byte) bool { func Queue(data []byte) bool {
result := true result := true
@ -121,14 +117,3 @@ func loadChannelBuffer(channel int, bufferSize int) []byte {
}) })
return r return r
} }
func IsPlaying(channel int) bool {
result := false
withChannels(func() {
if !audioEnabled {
return
}
result = isPlaying(channel)
})
return result
}

View File

@ -17,6 +17,8 @@
package audio package audio
import ( import (
"time"
"github.com/gopherjs/gopherjs/js" "github.com/gopherjs/gopherjs/js"
) )
@ -73,18 +75,6 @@ func isPlaying(channel int) bool {
return c < a.position 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() { func initialize() {
// Do nothing in node.js. // Do nothing in node.js.
if js.Global.Get("require") != js.Undefined { if js.Global.Get("require") != js.Undefined {
@ -107,4 +97,18 @@ func initialize() {
position: 0, 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)
}
}()
} }

View File

@ -29,9 +29,6 @@ func isPlaying(channel int) bool {
return 0 < len(ch.buffer) return 0 < len(ch.buffer)
} }
func tick() {
}
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{})

3
run.go
View File

@ -17,7 +17,6 @@ package ebiten
import ( import (
"time" "time"
"github.com/hajimehoshi/ebiten/internal/audio"
"github.com/hajimehoshi/ebiten/internal/ui" "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.newScreenHeight = 0
runContext.newScreenScale = 0 runContext.newScreenScale = 0
audio.Tick()
if err := ui.DoEvents(); err != nil { if err := ui.DoEvents(); err != nil {
return err return err
} }