Skip to content

Commit

Permalink
use RMS for mic level
Browse files Browse the repository at this point in the history
  • Loading branch information
martonp96 committed Sep 13, 2023
1 parent 5763375 commit f786093
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/CSoundInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,8 @@ void CSoundInput::SoundFrameCaptured(HRECORD handle, const void* buffer, DWORD l
NoiseSuppressionProcess(writableBuffer, FRAME_SIZE_SAMPLES);

// Get current microphone noise level
const DWORD currentMicLevel = BASS_ChannelGetLevel(handle);

// Get left channel noise level from it (because it's mono so right = left)
const uint16_t leftChannelLevel = LOWORD(currentMicLevel);

// Convert to float from 0.f to 1.f
micLevel = static_cast<float>(leftChannelLevel) / MaxShortFloatValue;
BASS_ChannelGetLevelEx(handle, &micLevel, 0.05, BASS_LEVEL_MONO | BASS_LEVEL_RMS | BASS_LEVEL_NOREMOVE);
micLevel = std::clamp(micLevel * 2.0f, 0.0f, 1.0f);

if (VoiceCallback)
{
Expand Down

0 comments on commit f786093

Please sign in to comment.