Enhancement: audio speakers (#44)

* refactor: active speakers

1. Observe the loudest adjusted with active ratio instead of linear average of decibel values
2. Follow RFC6465 to convert audio level from decibel to linear value.
3. Quantize audio level for stable slice comparison
4. Switch moving average algorithm from MMA to EMA to have the same center of mass with SMA
5. Minor: remove seenSids map allocation
6. Minor: minimize division arithmetic

* Update pkg/rtc/audiolevel.go

Co-authored-by: David Zhao <david@davidzhao.com>
This commit is contained in:
hn8
2021-07-09 09:46:24 -07:00
committed by GitHub
co-authored by David Zhao
parent 1fd858a16b
commit dcfe7eaf4f
12 changed files with 103 additions and 86 deletions
+5 -5
View File
@@ -8,7 +8,7 @@ import (
)
const (
samplesPerBatch = 30
samplesPerBatch = 25
defaultActiveLevel = 30
// requires two noisy samples to count
defaultPercentile = 10
@@ -36,7 +36,7 @@ func TestAudioLevel(t *testing.T) {
t.Run("not noisy when less than percentile samples are above threshold", func(t *testing.T) {
a := rtc.NewAudioLevel(defaultActiveLevel, defaultPercentile)
observeSamples(a, 35, samplesPerBatch-1)
observeSamples(a, 35, samplesPerBatch-2)
observeSamples(a, 25, 1)
observeSamples(a, 35, 1)
@@ -47,9 +47,9 @@ func TestAudioLevel(t *testing.T) {
t.Run("noisy when higher than percentile samples are above threshold", func(t *testing.T) {
a := rtc.NewAudioLevel(defaultActiveLevel, defaultPercentile)
observeSamples(a, 35, samplesPerBatch-4)
observeSamples(a, 25, 2)
observeSamples(a, 29, 2)
observeSamples(a, 35, samplesPerBatch-16)
observeSamples(a, 25, 8)
observeSamples(a, 29, 8)
level, noisy := a.GetLevel()
require.True(t, noisy)