audio: Use runtime.Gosched() instead of time.Sleep(1)

This commit is contained in:
Hajime Hoshi 2016-03-10 03:27:51 +09:00
parent 83579a465e
commit 3cbcda1bb0
3 changed files with 8 additions and 6 deletions

View File

@ -18,7 +18,7 @@ package audio
import ( import (
"io" "io"
"time" "runtime"
"github.com/gopherjs/gopherjs/js" "github.com/gopherjs/gopherjs/js"
) )
@ -108,6 +108,7 @@ func (p *player) proceed() error {
if err != nil { if err != nil {
return err return err
} }
runtime.Gosched()
} }
return nil return nil
} }
@ -125,7 +126,7 @@ func (p *player) start() error {
// TODO: Record the last error // TODO: Record the last error
panic(err) panic(err)
} }
time.Sleep(1) runtime.Gosched()
} }
}() }()
return nil return nil

View File

@ -20,7 +20,6 @@ import (
"fmt" "fmt"
"io" "io"
"runtime" "runtime"
"time"
"golang.org/x/mobile/exp/audio/al" "golang.org/x/mobile/exp/audio/al"
) )
@ -136,7 +135,7 @@ func (p *player) start() error {
// TODO: Record the last error // TODO: Record the last error
panic(err) panic(err)
} }
time.Sleep(1) runtime.Gosched()
} }
}() }()
return nil return nil

View File

@ -27,6 +27,7 @@ import "C"
import ( import (
"fmt" "fmt"
"io" "io"
"runtime"
"time" "time"
"unsafe" "unsafe"
) )
@ -43,7 +44,7 @@ func newHeader(waveOut C.HWAVEOUT, bufferSize int) header {
h := header{ h := header{
buffer: buf, buffer: buf,
bufferSize: bufferSize, bufferSize: bufferSize,
waveHdr: C.WAVEHDR{ waveHdr: C.WAVEHDR{
lpData: C.LPSTR(buf), lpData: C.LPSTR(buf),
dwBufferLength: C.DWORD(bufferSize), dwBufferLength: C.DWORD(bufferSize),
}, },
@ -66,6 +67,7 @@ func (h *header) Write(waveOut C.HWAVEOUT, data []byte) {
} }
const numHeader = 8 const numHeader = 8
var sem = make(chan struct{}, numHeader) var sem = make(chan struct{}, numHeader)
//export releaseSemaphore //export releaseSemaphore
@ -117,7 +119,7 @@ func startPlaying(src io.Reader, sampleRate int) error {
// TODO: Propagate this error? // TODO: Propagate this error?
panic(err) panic(err)
} }
time.Sleep(1) runtime.Gosched()
} }
// TODO: Finalize the wave handler // TODO: Finalize the wave handler
}() }()