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/v3/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(s *Stream) {
53 tick := time.Tick(vors.ScreenRefresh)
62 GUI.DeleteView(s.name)
63 GUI.DeleteView(s.name + "-vol")
67 " %s | %s | S/B/L/R: %s/%s/%s/%s",
68 humanize.Comma(s.stats.pkts),
69 humanize.IBytes(s.stats.bytes),
70 humanize.Comma(int64(s.actr-(s.ctr&0x00FFFF))/50),
71 humanize.Comma(s.stats.bads),
72 humanize.Comma(s.stats.lost),
73 humanize.Comma(s.stats.reorder),
75 peerFlags := []string{" ", " ", " "}
76 if s.name == *Name && Muted {
77 peerFlags[0] = vors.CRed + "M" + vors.CReset
80 peerFlags[2] = vors.CMagenta + "S" + vors.CReset
82 if s.stats.last.Add(vors.ScreenRefresh).After(now) {
83 peerFlags[1] = vors.CGreen + "T" + vors.CReset
86 peerFlags[0] = vors.CRed + "M" + vors.CReset
89 l = strings.Join(peerFlags, "") + l
90 v, err = GUI.View(s.name)
95 vol = float64(atomic.SwapUint64(&s.stats.vol, 0))
96 volN = float64(atomic.SwapUint64(&s.stats.volN, 0))
97 v, err = GUI.View(s.name + "-vol")
103 vol = math.Sqrt(vol / volN)
107 rep = int(float64(GUIMaxY) * vol / maxRMS)
111 v.Write([]byte(strings.Repeat("▒", rep)))