diff options
author | Wohlstand <admin@wohlnet.ru> | 2017-02-17 10:57:23 +0300 |
---|---|---|
committer | Wohlstand <admin@wohlnet.ru> | 2017-02-17 10:57:23 +0300 |
commit | 3e66410de0bf006c4b90eeb259d59da7ff8e8355 (patch) | |
tree | 9159d3ec398485aef351a0b101e4811c341f05c0 /src/adlmidi.cpp | |
parent | 57911fca4a7179677174cea7449af9687232e473 (diff) | |
download | libADLMIDI-3e66410de0bf006c4b90eeb259d59da7ff8e8355.tar.gz libADLMIDI-3e66410de0bf006c4b90eeb259d59da7ff8e8355.tar.bz2 libADLMIDI-3e66410de0bf006c4b90eeb259d59da7ff8e8355.zip |
Better audio clipping while mixing
Diffstat (limited to 'src/adlmidi.cpp')
-rw-r--r-- | src/adlmidi.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/adlmidi.cpp b/src/adlmidi.cpp index d54ce9a..07efea3 100644 --- a/src/adlmidi.cpp +++ b/src/adlmidi.cpp @@ -274,6 +274,9 @@ ADLMIDI_EXPORT void adl_reset(ADL_MIDIPlayer *device) } #ifdef ADLMIDI_USE_DOSBOX_OPL + +#define ADLMIDI_CLAMP(V, MIN, MAX) std::max(std::min(V, (MAX)), (MIN)) + inline static void SendStereoAudio(ADL_MIDIPlayer *device, int &samples_requested, ssize_t &in_size, @@ -296,7 +299,7 @@ inline static void SendStereoAudio(ADL_MIDIPlayer *device, offset = pos + p * 2 + w; if(offset < samples_requested) - _out[offset] = static_cast<short>(out); + _out[offset] = static_cast<short>(ADLMIDI_CLAMP(out, INT16_MIN, INT16_MAX)); else { device->backup_samples[device->backup_samples_size] = static_cast<short>(out); |