From 8021361bb431181cb495238aa7247965cf7a0901 Mon Sep 17 00:00:00 2001 From: liushuyu Date: Wed, 1 May 2019 15:35:20 -0600 Subject: [PATCH] audio_core: dsp_hle: use better f32 to s16... ... conversion by clamping and clipping sample to [-1,1] and use different masks for negative and positive samples --- src/audio_core/hle/ffmpeg_decoder.cpp | 1 + src/audio_core/hle/wmf_decoder.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/audio_core/hle/ffmpeg_decoder.cpp b/src/audio_core/hle/ffmpeg_decoder.cpp index 0bed4bbb48..6354f2c3ea 100644 --- a/src/audio_core/hle/ffmpeg_decoder.cpp +++ b/src/audio_core/hle/ffmpeg_decoder.cpp @@ -218,6 +218,7 @@ std::optional FFMPEGDecoder::Impl::Decode(const BinaryRequest& r for (std::size_t channel(0); channel < decoded_frame->channels; channel++) { std::memcpy(&val_float, decoded_frame->data[channel] + current_pos, sizeof(val_float)); + val_float = std::clamp(val_float, -1.0f, 1.0f); s16 val = static_cast(0x7FFF * val_float); out_streams[channel].push_back(val & 0xFF); out_streams[channel].push_back(val >> 8); diff --git a/src/audio_core/hle/wmf_decoder.cpp b/src/audio_core/hle/wmf_decoder.cpp index e78f24ca1f..a1507991b3 100644 --- a/src/audio_core/hle/wmf_decoder.cpp +++ b/src/audio_core/hle/wmf_decoder.cpp @@ -129,7 +129,7 @@ MFOutputState WMFDecoder::Impl::DecodingLoop(ADTSData adts_header, f32 val_f32; for (std::size_t i = 0; i < output_buffer->size();) { for (std::size_t channel = 0; channel < adts_header.channels; channel++) { - val_f32 = output_buffer->at(i); + val_f32 = std::clamp(output_buffer->at(i), -1.0f, 1.0f); s16 val = static_cast(0x7FFF * val_f32); out_streams[channel].push_back(val & 0xFF); out_streams[channel].push_back(val >> 8);