Skip to content

Commit 59412be

Browse files
committed
Round instead of truncating in float audio converter
This is mainly to make the tests {float,double}_conversion more robust, previously they could fail depending on the target CPU type (e.g. with gcc -m32 -march=i386). In principle this is now inconsistent with the other converters which all still truncate, but this doesn't really make a difference in practice, and making them round would add additional branching and (if implemented naively) break some other tests, so this is probably fine. Fixes #274.
1 parent a40f865 commit 59412be

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

libaegisub/audio/provider_convert.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ class FloatConvertAudioProvider final : public AudioProviderWrapper {
9494
for (size_t i = 0; i < static_cast<size_t>(count * channels); ++i) {
9595
Source expanded;
9696
if (src_buf[i] < 0)
97-
expanded = static_cast<Target>(-src_buf[i] * std::numeric_limits<Target>::min());
97+
expanded = static_cast<Target>(-src_buf[i] * std::numeric_limits<Target>::min() - 0.5);
9898
else
99-
expanded = static_cast<Target>(src_buf[i] * std::numeric_limits<Target>::max());
99+
expanded = static_cast<Target>(src_buf[i] * std::numeric_limits<Target>::max() + 0.5);
100100

101101
dest[i] = expanded < std::numeric_limits<Target>::min() ? std::numeric_limits<Target>::min() :
102102
expanded > std::numeric_limits<Target>::max() ? std::numeric_limits<Target>::max() :

0 commit comments

Comments
 (0)