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

View File

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

View File

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