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 General Public License for more details.
13 // You should have received a copy of the GNU 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"
41 func (stats *Stats) AddRMS(pcm []int16) {
43 for _, s := range pcm {
44 vol += uint64(int64(s) * int64(s))
46 atomic.AddUint64(&stats.vol, vol)
47 atomic.AddUint64(&stats.volN, uint64(len(pcm)))
50 func statsDrawer(stats *Stats, name string) {
52 tick := time.Tick(vors.ScreenRefresh)
61 GUI.DeleteView(name + "-vol")
65 "%s | %s | L/R: %s / %s",
66 humanize.Comma(stats.pkts),
67 humanize.IBytes(stats.bytes),
68 humanize.Comma(stats.lost),
69 humanize.Comma(stats.reorder),
71 if name == *Name && Muted {
72 s += " | " + vors.CRed + "MUTE" + vors.CReset
74 if stats.last.Add(time.Second).After(now) {
75 s += " | " + vors.CGreen + "TALK" + vors.CReset
78 v, err = GUI.View(name)
83 vol = float64(atomic.SwapUint64(&stats.vol, 0))
84 volN = float64(atomic.SwapUint64(&stats.volN, 0))
85 v, err = GUI.View(name + "-vol")
91 vol = math.Sqrt(vol / volN)
92 rep = int(float64(GUIMaxY) * vol / 5000)
93 v.Write([]byte(strings.Repeat("▒", rep)))