1 // VoRS -- Vo(IP) Really Simple
2 // Copyright (C) 2024 Sergey Matveev <stargrave@stargrave.org>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, version 3 of the License.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU Affero General Public License for more details.
13 // You should have received a copy of the GNU Affero General Public License
14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
25 "github.com/dustin/go-humanize"
26 "github.com/jroimartin/gocui"
27 vors "go.stargrave.org/vors/internal"
42 func (stats *Stats) AddRMS(pcm []int16) {
44 for _, s := range pcm {
45 vol += uint64(int64(s) * int64(s))
47 atomic.AddUint64(&stats.vol, vol)
48 atomic.AddUint64(&stats.volN, uint64(len(pcm)))
51 func statsDrawer(stats *Stats, name string) {
53 tick := time.Tick(vors.ScreenRefresh)
62 GUI.DeleteView(name + "-vol")
66 "%s | %s | B/L/R: %s/%s/%s",
67 humanize.Comma(stats.pkts),
68 humanize.IBytes(stats.bytes),
69 humanize.Comma(stats.bads),
70 humanize.Comma(stats.lost),
71 humanize.Comma(stats.reorder),
73 if name == *Name && Muted {
74 s += " | " + vors.CRed + "MUTE" + vors.CReset
76 if stats.last.Add(vors.ScreenRefresh).After(now) {
77 s += " | " + vors.CGreen + "TALK" + vors.CReset
80 v, err = GUI.View(name)
85 vol = float64(atomic.SwapUint64(&stats.vol, 0))
86 volN = float64(atomic.SwapUint64(&stats.volN, 0))
87 v, err = GUI.View(name + "-vol")
93 vol = math.Sqrt(vol / volN)
94 rep = int(float64(GUIMaxY) * vol / 5000)
95 v.Write([]byte(strings.Repeat("▒", rep)))