mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
audio: Use variables instead of channels to avoid GopherJS bugs
This commit is contained in:
parent
40ae782a67
commit
80b10b2d49
@ -173,7 +173,7 @@ func (p *players) hasSource(src ReadSeekCloser) bool {
|
|||||||
type Context struct {
|
type Context struct {
|
||||||
players *players
|
players *players
|
||||||
errCh chan error
|
errCh chan error
|
||||||
pingCh chan struct{}
|
pingCount int
|
||||||
sampleRate int
|
sampleRate int
|
||||||
frames int64
|
frames int64
|
||||||
framesReadOnly int64
|
framesReadOnly int64
|
||||||
@ -200,7 +200,6 @@ func NewContext(sampleRate int) (*Context, error) {
|
|||||||
c := &Context{
|
c := &Context{
|
||||||
sampleRate: sampleRate,
|
sampleRate: sampleRate,
|
||||||
errCh: make(chan error, 1),
|
errCh: make(chan error, 1),
|
||||||
pingCh: make(chan struct{}),
|
|
||||||
}
|
}
|
||||||
theContext = c
|
theContext = c
|
||||||
c.players = &players{
|
c.players = &players{
|
||||||
@ -229,10 +228,9 @@ func (c *Context) Frame() int64 {
|
|||||||
|
|
||||||
// Internal Only?
|
// Internal Only?
|
||||||
func (c *Context) Ping() {
|
func (c *Context) Ping() {
|
||||||
select {
|
c.m.Lock()
|
||||||
case c.pingCh <- struct{}{}:
|
c.pingCount = 5
|
||||||
default:
|
c.m.Unlock()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) loop() {
|
func (c *Context) loop() {
|
||||||
@ -254,10 +252,13 @@ func (c *Context) loop() {
|
|||||||
for {
|
for {
|
||||||
c.m.Lock()
|
c.m.Lock()
|
||||||
c.framesReadOnly = c.frames
|
c.framesReadOnly = c.frames
|
||||||
c.m.Unlock()
|
if c.pingCount == 0 {
|
||||||
if c.frames%10 == 0 {
|
c.m.Unlock()
|
||||||
<-c.pingCh
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
c.pingCount--
|
||||||
|
c.m.Unlock()
|
||||||
c.frames++
|
c.frames++
|
||||||
bytesPerFrame := c.sampleRate * bytesPerSample * channelNum / FPS
|
bytesPerFrame := c.sampleRate * bytesPerSample * channelNum / FPS
|
||||||
l := (c.frames * int64(bytesPerFrame)) - c.writtenBytes
|
l := (c.frames * int64(bytesPerFrame)) - c.writtenBytes
|
||||||
|
Loading…
Reference in New Issue
Block a user