summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxegineering <me@xegineering.eu>2024-11-29 09:16:57 +0100
committerxegineering <me@xegineering.eu>2024-11-29 09:16:57 +0100
commit49dc5ae3c12f2c696302171b54b130d94dea05e0 (patch)
tree92b8ee24f25dc65e3035b3d67b6a3211c1ceb24c
parent99031596efbcf004188217d2a9e53ac5ce33b511 (diff)
downloadsoundbox-go-49dc5ae3c12f2c696302171b54b130d94dea05e0.tar
soundbox-go-49dc5ae3c12f2c696302171b54b130d94dea05e0.tar.zst
soundbox-go-49dc5ae3c12f2c696302171b54b130d94dea05e0.zip
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()`.
-rw-r--r--soundbox/streaming.go3
1 files changed, 2 insertions, 1 deletions
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
}