1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:07:35 +00:00

LibAudio: Fix 24-bit PCM rescaling

This code was so totally wrong I can't even explain it.
This commit is contained in:
kleines Filmröllchen 2022-10-14 12:44:26 +02:00 committed by Andrew Kaster
parent 5f71c81e1b
commit e6ea49d10b

View file

@ -72,10 +72,13 @@ static ErrorOr<double> read_sample_int24(Core::Stream::Stream& stream)
i32 sample3 = byte;
i32 value = 0;
value = sample1 << 8;
value |= sample2 << 16;
value |= sample3 << 24;
return static_cast<double>(value) / static_cast<double>((1 << 24) - 1);
value = sample1;
value |= sample2 << 8;
value |= sample3 << 16;
// Sign extend the value, as it can currently not have the correct sign.
value = (value << 8) >> 8;
// Range of value is now -2^23 to 2^23-1 and we can rescale normally.
return static_cast<double>(value) / static_cast<double>((1 << 23) - 1);
}
template<typename T>