1export const VOICE_WAVEFORM_SAMPLE_COUNT = 64;
2
3const VOICE_NOISE_FLOOR_DECIBELS = -60;
4const VOICE_NOISE_FLOOR_AMPLITUDE = 10 ** (VOICE_NOISE_FLOOR_DECIBELS / 20);
5
6/** Converts measured decibels to compressed amplitude, reserving full height for 0 dB. */
7export function normalizeVoiceInputDecibels(decibels: number | undefined) {
8 if (decibels === undefined || !Number.isFinite(decibels)) return 0;
9 if (decibels <= VOICE_NOISE_FLOOR_DECIBELS) return 0;
10 if (decibels >= 0) return 1;
11
12 const amplitude = 10 ** (decibels / 20);
13 return Math.sqrt((amplitude - VOICE_NOISE_FLOOR_AMPLITUDE) / (1 - VOICE_NOISE_FLOOR_AMPLITUDE));
14}