diff options
-rw-r--r-- | soundbox/pipewire.go | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/soundbox/pipewire.go b/soundbox/pipewire.go index 476d2e4..bb672f8 100644 --- a/soundbox/pipewire.go +++ b/soundbox/pipewire.go @@ -54,12 +54,20 @@ func (pwc pwCapture) Read(p []byte) (int, error) { func s16leDropSilence(input []byte) []byte { output := make([]byte, 0) - for i := 0; i < (len(input) - 1); i += 2 { - if input[i] == byte(0) && input[i+1] == byte(0) { + cut := len(input) % 4 + length := len(input) - cut // s16 raw audio is 4 bytes per sample + + for i := 0; i < length; i += 4 { + if input[i+0] == byte(0) && + input[i+1] == byte(0) && + input[i+2] == byte(0) && + input[i+3] == byte(0) { continue } - output = append(output, input[i]) + output = append(output, input[i+0]) output = append(output, input[i+1]) + output = append(output, input[i+2]) + output = append(output, input[i+3]) } return output |