Age | Commit message (Collapse) | Author |
|
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()`.
|
|
This makes use of two functions from this package:
- io.Copy()
- io.MultiWriter()
`io.Copy()` is used to move the data from whatever reader is provided.
`io.Multiwriter()` solves the issue that we need to stream to multiple
network connections at the same time (one for each soundbox).
|
|
This is recommended by the Go standard library. One reason is that a
Reader might deliver the last couple of bytes together with the EOF
error. This is only handled correctly if the returned bytes are
processed first and the error is handled later.
[1]: https://pkg.go.dev/io#Reader
|
|
This prepares the switch to adding more sources than web URLs.
Everything providing an io.Reader can then simply use this internal
function in the background to avoid code duplication.
|