mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
audio: Use runtime.Gosched() instead of time.Sleep(1)
This commit is contained in:
parent
83579a465e
commit
3cbcda1bb0
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}()
|
||||
|
Loading…
Reference in New Issue
Block a user