From 49dc5ae3c12f2c696302171b54b130d94dea05e0 Mon Sep 17 00:00:00 2001 From: xegineering Date: Fri, 29 Nov 2024 09:16:57 +0100 Subject: Fix variable buffer size The switch to `io.Copy()` to pump the data to the soundbox devices removed the control over the buffer size of this copy action. While for generic copy actions it is even an advantage when a big buffer is used this is a problem for the soundbox use case. A big buffer used during copy means that the first soundbox device gets audio data significantly earlier than the later ones since `io.MultiWriter()` works sequentially. Thus this commit switches to `io.CopyBuffer()` where a buffer has to provided. For that purpose the same buffer size is used as before the refactoring to use `io.Copy()`. --- soundbox/streaming.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'soundbox/streaming.go') diff --git a/soundbox/streaming.go b/soundbox/streaming.go index 1a2d89e..357fa30 100644 --- a/soundbox/streaming.go +++ b/soundbox/streaming.go @@ -33,7 +33,8 @@ func streamContext(ctx context.Context, r io.Reader, targets []net.HardwareAddr) mw := io.MultiWriter(writers...) - _, err := io.Copy(mw, r) + buf := make([]byte, bufferSize) + _, err := io.CopyBuffer(mw, r, buf) return err } -- cgit v1.2.3-70-g09d2