Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/normalization_fix'
Browse files Browse the repository at this point in the history
  • Loading branch information
martonp96 committed Oct 26, 2023
2 parents bcebd84 + cf13427 commit e49ec28
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
8 changes: 3 additions & 5 deletions src/CSoundInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,15 +311,13 @@ void CSoundInput::Normalize(void* buffer, DWORD sampleCount)
desiredGain = std::fmin(desiredGain, 10.0f);

// Smooth the transition of gain
static float currentGain = 1.0f;
float smoothingFactor = 0.05f;
currentNormalizationGain = (1 - smoothingFactor) * currentNormalizationGain + smoothingFactor * desiredGain;
currentNormalizationGain = (1 - NORMALIZE_SMOOTHING_FACTOR) * currentNormalizationGain + NORMALIZE_SMOOTHING_FACTOR * desiredGain;

const auto shortSamples = static_cast<short*>(buffer);
auto shortSamples = static_cast<short*>(buffer);

for (int i = 0; i < sampleCount; ++i)
{
float processedSample = (float)shortSamples[i] * currentGain;
float processedSample = (float)shortSamples[i] * currentNormalizationGain;
shortSamples[i] = static_cast<int16_t>(clampFloatSample(processedSample));
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/CSoundInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class CSoundInput : public ISoundInput
{
static constexpr int RNNoiseFrameSize = 480;
static constexpr float MaxShortFloatValue = 32768.0f;
static constexpr int NORMALIZE_FRAME_COUNT = 20;
static constexpr int NORMALIZE_FRAME_COUNT = 50;
static constexpr float NORMALIZE_SMOOTHING_FACTOR = 0.05f;

HRECORD recordChannel = 0;
HSTREAM levelChannel = 0;
Expand Down

0 comments on commit e49ec28

Please sign in to comment.