audio: Fix range on float-to-int data clamping.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 15 May 2018 01:40:05 -0400
changeset 11990ce0099c8d037
parent 11989 d194f4f41437
child 11991 2a487acdb306
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.
src/audio/SDL_audiotypecvt.c
     1.1 --- a/src/audio/SDL_audiotypecvt.c	Tue May 15 01:35:53 2018 -0400
     1.2 +++ b/src/audio/SDL_audiotypecvt.c	Tue May 15 01:40:05 2018 -0400
     1.3 @@ -174,7 +174,7 @@
     1.4          if (sample >= 1.0f) {
     1.5              *dst = 127;
     1.6          } else if (sample <= -1.0f) {
     1.7 -            *dst = -127;
     1.8 +            *dst = -128;
     1.9          } else {
    1.10              *dst = (Sint8)(sample * 127.0f);
    1.11          }
    1.12 @@ -226,7 +226,7 @@
    1.13          if (sample >= 1.0f) {
    1.14              *dst = 32767;
    1.15          } else if (sample <= -1.0f) {
    1.16 -            *dst = -32767;
    1.17 +            *dst = -32768;
    1.18          } else {
    1.19              *dst = (Sint16)(sample * 32767.0f);
    1.20          }
    1.21 @@ -250,7 +250,7 @@
    1.22      for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
    1.23          const float sample = *src;
    1.24          if (sample >= 1.0f) {
    1.25 -            *dst = 65534;
    1.26 +            *dst = 65535;
    1.27          } else if (sample <= -1.0f) {
    1.28              *dst = 0;
    1.29          } else {
    1.30 @@ -278,7 +278,7 @@
    1.31          if (sample >= 1.0f) {
    1.32              *dst = 2147483647;
    1.33          } else if (sample <= -1.0f) {
    1.34 -            *dst = -2147483647;
    1.35 +            *dst = -2147483648;
    1.36          } else {
    1.37              *dst = ((Sint32)(sample * 8388607.0f)) << 8;
    1.38          }