Skip to content

Commit

Permalink
FEAT(client): Industry standard for hold time
Browse files Browse the repository at this point in the history
As request in #2453, this commit implements the industry standard
for microphone hold time for voice activation detection. The calculation
that yields hold time (s) from the iVoiceHold setting is described and
comments are added to describe the function of related fields.

Implements #2453.
  • Loading branch information
ajamesonwright committed Jan 19, 2022
1 parent a517b06 commit 5a3f678
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/mumble/AudioInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,7 @@ void AudioInput::encodeAudioFrame(AudioChunk chunk) {
if (!bIsSpeech) {
iHoldFrames++;
if (iHoldFrames < Global::get().s.iVoiceHold)
// Hold mic open until iVoiceHold threshold is reached
bIsSpeech = true;
} else {
iHoldFrames = 0;
Expand Down
6 changes: 5 additions & 1 deletion src/mumble/AudioInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,12 @@ class AudioInput : public QThread {

bool bEchoMulti;
Settings::NoiseCancel noiseCancel;
// Standard microphone sample rate (samples/s)
static const unsigned int iSampleRate = SAMPLE_RATE;
static const int iFrameSize = SAMPLE_RATE / 100;
/// Based the sample rate, 48,000 samples/s = 48 samples/ms.
/// For each 10 ms, this yields 480 samples. This corresponds numerically with the calculation:
/// iFrameSize = 48000 / 100 = 480 samples, allowing a consistent 10ms of audio data per frame.
static const int iFrameSize = SAMPLE_RATE / 100;

QMutex qmSpeex;
SpeexPreprocessState *sppPreprocess;
Expand Down
8 changes: 5 additions & 3 deletions src/mumble/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,11 @@ Settings::Settings() {
bOnlyAttenuateSameOutput = false;
bAttenuateLoopbacks = false;
iMinLoudness = 1000;
iVoiceHold = 50;
iJitterBufferSize = 1;
iFramesPerPacket = 2;
/// Actual mic hold time is (iVoiceHold / 100) seconds, where iVoiceHold is specified in 'frames',
/// each of which is has a size of iFrameSize (see AudioInput.h)
iVoiceHold = 20;
iJitterBufferSize = 1;
iFramesPerPacket = 2;
#ifdef USE_RNNOISE
noiseCancelMode = NoiseCancelRNN;
#else
Expand Down

0 comments on commit 5a3f678

Please sign in to comment.