Skip to content

Commit

Permalink
Fixed distortion with noise suppression enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
emcifuntik committed Oct 24, 2023
1 parent ae4b63e commit 07b6cb4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/CSoundInput.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
#define NOMINMAX

#include <chrono>
#include <fstream>
#include <algorithm>
#include <limits>
#include "CSoundInput.h"
#include <bass_fx.h>

#include "alt-voice.h"
#include <iostream>

// https://github.com/mumble-voip/mumble/pull/5363/files
static short clampFloatSample(float v) {
return static_cast<short>(std::min(std::max(v, static_cast<float>(std::numeric_limits<short>::min())),
static_cast<float>(std::numeric_limits<short>::max())));
}

CSoundInput::CSoundInput(int _bitRate) : encoder(new COpusEncoder(SAMPLE_RATE, AUDIO_CHANNELS, _bitRate)), bitrate(_bitRate)
{
Expand Down Expand Up @@ -266,7 +274,7 @@ void CSoundInput::NoiseSuppressionProcess(void* buffer, DWORD length)
// Convert the floating-point samples back to 16-bit integer samples
for (int i = 0; i < FRAME_SIZE_SAMPLES; i++)
{
shortSamples[i] = static_cast<int16_t>(floatBuffer[i]);
shortSamples[i] = static_cast<int16_t>(clampFloatSample(floatBuffer[i]));
}
}

Expand Down

0 comments on commit 07b6cb4

Please sign in to comment.