From 7b320f2aeb68992aed7f0c04e8b184b8fa6f6532 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 5 Jun 2021 23:00:50 +0900 Subject: [PATCH] audio/internal/readerdriver: Adjust buffer size for low-spec machines (Linux) Updates #1549 --- audio/internal/readerdriver/driver_unix.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/audio/internal/readerdriver/driver_unix.go b/audio/internal/readerdriver/driver_unix.go index b359acd85..04159bd7f 100644 --- a/audio/internal/readerdriver/driver_unix.go +++ b/audio/internal/readerdriver/driver_unix.go @@ -56,6 +56,8 @@ type context struct { var theContext *context +const bufferSize = 4096 + func NewContext(sampleRate, channelNum, bitDepthInBytes int) (Context, chan struct{}, error) { ready := make(chan struct{}) close(ready) @@ -132,7 +134,7 @@ func NewContext(sampleRate, channelNum, bitDepthInBytes int) (Context, chan stru const defaultValue = 0xffffffff bufferAttr := C.pa_buffer_attr{ maxlength: defaultValue, - tlength: 2048, + tlength: bufferSize, prebuf: defaultValue, minreq: defaultValue, } @@ -247,7 +249,7 @@ func ebiten_readerdriver_streamWriteCallback(stream *C.pa_stream, requestedBytes var buf unsafe.Pointer var buf32 []float32 - var bytesToFill C.size_t = 256 + var bytesToFill C.size_t = bufferSize var players []*playerImpl for n := int(requestedBytes); n > 0; n -= int(bytesToFill) { c.cond.L.Lock()