diff --git a/src/CSoundInput.cpp b/src/CSoundInput.cpp index e408698..fe15b07 100644 --- a/src/CSoundInput.cpp +++ b/src/CSoundInput.cpp @@ -1,12 +1,20 @@ +#define NOMINMAX + #include #include #include +#include #include "CSoundInput.h" #include #include "alt-voice.h" #include +// https://github.com/mumble-voip/mumble/pull/5363/files +static short clampFloatSample(float v) { + return static_cast(std::min(std::max(v, static_cast(std::numeric_limits::min())), + static_cast(std::numeric_limits::max()))); +} CSoundInput::CSoundInput(int _bitRate) : encoder(new COpusEncoder(SAMPLE_RATE, AUDIO_CHANNELS, _bitRate)), bitrate(_bitRate) { @@ -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(floatBuffer[i]); + shortSamples[i] = static_cast(clampFloatSample(floatBuffer[i])); } }