Do not send silence frames to the radio

This commit is contained in:
Akos Marton 2020-10-27 10:03:22 +02:00
parent b86459b244
commit 4f3734957c
2 changed files with 16 additions and 0 deletions

View file

@ -97,6 +97,10 @@ func (a *audioStruct) recLoop(deinitNeededChan, deinitFinishedChan chan bool) {
}
}
// Do not send silence frames to the radio unnecessarily
if allZero(frameBuf[:n]) {
continue
}
buf.Write(frameBuf[:n])
for buf.Len() >= len(frameBuf) {
@ -167,6 +171,7 @@ func (a *audioStruct) init(devName string) error {
a.sink.Rate = audioSampleRate
a.sink.Format = "s16le"
a.sink.Channels = 1
a.sink.UseSystemClockForTiming = true
a.sink.SetProperty("device.buffering.buffer_size", (audioSampleRate*16)/10)
a.sink.SetProperty("device.description", "kappanhang: "+devName)

11
util.go Normal file
View file

@ -0,0 +1,11 @@
package main
// Checks if all bytes are zeros
func allZero(s []byte) bool {
for _, v := range s {
if v != 0 {
return false
}
}
return true
}