From 77bef42aceeb1a2e0c3ef66c4fb8fcf217d093e3 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Mon, 21 Feb 2022 14:34:20 +0200 Subject: [PATCH] Use dynamic multiplier when bridging waveform --- portal.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/portal.go b/portal.go index a1ba454..4da13aa 100644 --- a/portal.go +++ b/portal.go @@ -1983,9 +1983,19 @@ func (portal *Portal) convertMediaMessageContent(intent *appservice.IntentAPI, m var waveform []int if audioMessage.Waveform != nil { waveform = make([]int, len(audioMessage.Waveform)) + max := 0 for i, part := range audioMessage.Waveform { - // TODO is 4 the right multiplier? - waveform[i] = int(part) * 4 + waveform[i] = int(part) + if waveform[i] > max { + max = waveform[i] + } + } + multiplier := 1024 / max + if multiplier > 32 { + multiplier = 32 + } + for i := range waveform { + waveform[i] *= multiplier } } extraContent["org.matrix.msc1767.audio"] = map[string]interface{}{