mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2024-12-20 22:16:49 +01:00
audio: Fix range on float-to-int data clamping.
I can't tell if there was a good reason for this or it was just me getting numbers wrong due to exhaustion.
This commit is contained in:
parent
7832cb652e
commit
a07e5815a5
@ -174,7 +174,7 @@ SDL_Convert_F32_to_S8_Scalar(SDL_AudioCVT *cvt, SDL_AudioFormat format)
|
|||||||
if (sample >= 1.0f) {
|
if (sample >= 1.0f) {
|
||||||
*dst = 127;
|
*dst = 127;
|
||||||
} else if (sample <= -1.0f) {
|
} else if (sample <= -1.0f) {
|
||||||
*dst = -127;
|
*dst = -128;
|
||||||
} else {
|
} else {
|
||||||
*dst = (Sint8)(sample * 127.0f);
|
*dst = (Sint8)(sample * 127.0f);
|
||||||
}
|
}
|
||||||
@ -226,7 +226,7 @@ SDL_Convert_F32_to_S16_Scalar(SDL_AudioCVT *cvt, SDL_AudioFormat format)
|
|||||||
if (sample >= 1.0f) {
|
if (sample >= 1.0f) {
|
||||||
*dst = 32767;
|
*dst = 32767;
|
||||||
} else if (sample <= -1.0f) {
|
} else if (sample <= -1.0f) {
|
||||||
*dst = -32767;
|
*dst = -32768;
|
||||||
} else {
|
} else {
|
||||||
*dst = (Sint16)(sample * 32767.0f);
|
*dst = (Sint16)(sample * 32767.0f);
|
||||||
}
|
}
|
||||||
@ -250,7 +250,7 @@ SDL_Convert_F32_to_U16_Scalar(SDL_AudioCVT *cvt, SDL_AudioFormat format)
|
|||||||
for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
|
for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
|
||||||
const float sample = *src;
|
const float sample = *src;
|
||||||
if (sample >= 1.0f) {
|
if (sample >= 1.0f) {
|
||||||
*dst = 65534;
|
*dst = 65535;
|
||||||
} else if (sample <= -1.0f) {
|
} else if (sample <= -1.0f) {
|
||||||
*dst = 0;
|
*dst = 0;
|
||||||
} else {
|
} else {
|
||||||
@ -278,7 +278,7 @@ SDL_Convert_F32_to_S32_Scalar(SDL_AudioCVT *cvt, SDL_AudioFormat format)
|
|||||||
if (sample >= 1.0f) {
|
if (sample >= 1.0f) {
|
||||||
*dst = 2147483647;
|
*dst = 2147483647;
|
||||||
} else if (sample <= -1.0f) {
|
} else if (sample <= -1.0f) {
|
||||||
*dst = -2147483647;
|
*dst = -2147483648;
|
||||||
} else {
|
} else {
|
||||||
*dst = ((Sint32)(sample * 8388607.0f)) << 8;
|
*dst = ((Sint32)(sample * 8388607.0f)) << 8;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user