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)
63 GUI.DeleteView(name + "-vol")
67 "%s | %s | B/L/R: %s/%s/%s",
68 humanize.Comma(stats.pkts),
69 humanize.IBytes(stats.bytes),
70 humanize.Comma(stats.bads),
71 humanize.Comma(stats.lost),
72 humanize.Comma(stats.reorder),
74 if name == *Name && Muted {
75 s += " | " + vors.CRed + "MUTE" + vors.CReset
77 if stats.last.Add(vors.ScreenRefresh).After(now) {
78 s += " | " + vors.CGreen + "TALK" + vors.CReset
81 v, err = GUI.View(name)
86 vol = float64(atomic.SwapUint64(&stats.vol, 0))
87 volN = float64(atomic.SwapUint64(&stats.volN, 0))
88 v, err = GUI.View(name + "-vol")
94 vol = math.Sqrt(vol / volN)
98 rep = int(float64(GUIMaxY) * vol / maxRMS)
99 v.Write([]byte(strings.Repeat("▒", rep)))