Skip to content

Commit 18d37fb

Browse files
committed
fix(PrevDroppedPackets): use float division and round-off
1 parent 6074196 commit 18d37fb

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

pcm.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"encoding/binary"
2020
"fmt"
2121
"io"
22+
"math"
2223
"slices"
2324
"sync"
2425
"time"
@@ -206,7 +207,7 @@ func (w *sampleWriter[T]) WriteSample(in T) error {
206207
timeSinceLastWrite := time.Since(w.lastWrite)
207208
tolerance := w.sampleDur / 10
208209
if timeSinceLastWrite > w.sampleDur+tolerance {
209-
droppedPackets = uint16((timeSinceLastWrite - w.sampleDur) / w.sampleDur)
210+
droppedPackets = uint16(math.Round(float64(timeSinceLastWrite-w.sampleDur) / float64(w.sampleDur)))
210211
}
211212
}
212213

0 commit comments

Comments
 (0)