citra-emu
/
citra-canary
Archived
1
0
Fork 0

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
This commit is contained in:
liushuyu 2019-05-01 15:35:20 -06:00
parent 623b0621ab
commit 8021361bb4
No known key found for this signature in database
GPG Key ID: 23D1CE4534419437
2 changed files with 2 additions and 1 deletions

View File

@ -218,6 +218,7 @@ std::optional<BinaryResponse> FFMPEGDecoder::Impl::Decode(const BinaryRequest& r
for (std::size_t channel(0); channel < decoded_frame->channels; channel++) { for (std::size_t channel(0); channel < decoded_frame->channels; channel++) {
std::memcpy(&val_float, decoded_frame->data[channel] + current_pos, std::memcpy(&val_float, decoded_frame->data[channel] + current_pos,
sizeof(val_float)); sizeof(val_float));
val_float = std::clamp(val_float, -1.0f, 1.0f);
s16 val = static_cast<s16>(0x7FFF * val_float); s16 val = static_cast<s16>(0x7FFF * val_float);
out_streams[channel].push_back(val & 0xFF); out_streams[channel].push_back(val & 0xFF);
out_streams[channel].push_back(val >> 8); out_streams[channel].push_back(val >> 8);

View File

@ -129,7 +129,7 @@ MFOutputState WMFDecoder::Impl::DecodingLoop(ADTSData adts_header,
f32 val_f32; f32 val_f32;
for (std::size_t i = 0; i < output_buffer->size();) { for (std::size_t i = 0; i < output_buffer->size();) {
for (std::size_t channel = 0; channel < adts_header.channels; channel++) { 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<s16>(0x7FFF * val_f32); s16 val = static_cast<s16>(0x7FFF * val_f32);
out_streams[channel].push_back(val & 0xFF); out_streams[channel].push_back(val & 0xFF);
out_streams[channel].push_back(val >> 8); out_streams[channel].push_back(val >> 8);