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
+8 -8
View File
@@ -338,7 +338,7 @@ func TestActiveSpeakers(t *testing.T) {
})
t.Run("audio level is smoothed", func(t *testing.T) {
rm := newRoomWithParticipants(t, testRoomOpts{num: 2, protocol: types.DefaultProtocol, audioSmoothSamples: 3})
rm := newRoomWithParticipants(t, testRoomOpts{num: 2, protocol: types.DefaultProtocol, audioSmoothIntervals: 3})
defer rm.Close()
participants := rm.GetParticipants()
p := participants[0].(*typesfakes.FakeParticipant)
@@ -355,7 +355,7 @@ func TestActiveSpeakers(t *testing.T) {
if len(lastSpeakers) == 0 {
return false
}
if lastSpeakers[0].Level < convertedLevel/2 {
if lastSpeakers[0].Level > convertedLevel {
return true
}
return false
@@ -370,7 +370,7 @@ func TestActiveSpeakers(t *testing.T) {
if len(lastSpeakers) == 0 {
return false
}
if lastSpeakers[0].Level > convertedLevel*0.99 {
if lastSpeakers[0].Level > convertedLevel {
return true
}
return false
@@ -456,9 +456,9 @@ func TestDataChannel(t *testing.T) {
}
type testRoomOpts struct {
num int
protocol types.ProtocolVersion
audioSmoothSamples uint32
num int
protocol types.ProtocolVersion
audioSmoothIntervals uint32
}
func newRoomWithParticipants(t *testing.T, opts testRoomOpts) *rtc.Room {
@@ -473,8 +473,8 @@ func newRoomWithParticipants(t *testing.T, opts testRoomOpts) *rtc.Room {
},
},
&config.AudioConfig{
UpdateInterval: audioUpdateInterval,
SmoothSamples: opts.audioSmoothSamples,
UpdateInterval: audioUpdateInterval,
SmoothIntervals: opts.audioSmoothIntervals,
},
)
for i := 0; i < opts.num; i++ {