Dynamic audio level indicator

This commit is contained in:
Fedor Indutny
2022-05-18 20:28:51 -07:00
committed by GitHub
parent ac59dec5aa
commit e6223b6a11
24 changed files with 323 additions and 123 deletions

View File

@@ -1,8 +1,8 @@
// Copyright 2020-2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
export const AUDIO_LEVEL_INTERVAL_MS = 250;
export const DEFAULT_AUDIO_LEVEL_FOR_SPEAKING = 0.15;
// See `TICK_INTERVAL` in group_call.rs in RingRTC
export const AUDIO_LEVEL_INTERVAL_MS = 200;
export const REQUESTED_VIDEO_WIDTH = 640;
export const REQUESTED_VIDEO_HEIGHT = 480;

View File

@@ -1,20 +0,0 @@
// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type * as RemoteConfig from '../RemoteConfig';
import { DEFAULT_AUDIO_LEVEL_FOR_SPEAKING } from './constants';
export function getAudioLevelForSpeaking(
getValueFromRemoteConfig: typeof RemoteConfig.getValue
): number {
const configValue = getValueFromRemoteConfig(
'desktop.calling.audioLevelForSpeaking'
);
if (typeof configValue !== 'string') {
return DEFAULT_AUDIO_LEVEL_FOR_SPEAKING;
}
const result = parseFloat(configValue);
const isResultValid = result > 0 && result <= 1;
return isResultValid ? result : DEFAULT_AUDIO_LEVEL_FOR_SPEAKING;
}

View File

@@ -0,0 +1,24 @@
// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
// See https://github.com/signalapp/Signal-Android/blob/b527b2ffb94fb82a7508c3b33ddbffef28085349/app/src/main/java/org/thoughtcrime/securesms/events/CallParticipant.kt#L87-L100
const LOWEST = 500 / 32767;
const LOW = 1000 / 32767;
const MEDIUM = 5000 / 32767;
const HIGH = 16000 / 32767;
export function truncateAudioLevel(audioLevel: number): number {
if (audioLevel < LOWEST) {
return 0;
}
if (audioLevel < LOW) {
return 0.25;
}
if (audioLevel < MEDIUM) {
return 0.5;
}
if (audioLevel < HIGH) {
return 0.75;
}
return 1;
}