src/audio/SDL_audiotypecvt.c
changeset 11990 ce0099c8d037
parent 11989 d194f4f41437
child 11991 2a487acdb306
equal deleted inserted replaced
11989:d194f4f41437 11990:ce0099c8d037
   172     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
   172     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
   173         const float sample = *src;
   173         const float sample = *src;
   174         if (sample >= 1.0f) {
   174         if (sample >= 1.0f) {
   175             *dst = 127;
   175             *dst = 127;
   176         } else if (sample <= -1.0f) {
   176         } else if (sample <= -1.0f) {
   177             *dst = -127;
   177             *dst = -128;
   178         } else {
   178         } else {
   179             *dst = (Sint8)(sample * 127.0f);
   179             *dst = (Sint8)(sample * 127.0f);
   180         }
   180         }
   181     }
   181     }
   182 
   182 
   224     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
   224     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
   225         const float sample = *src;
   225         const float sample = *src;
   226         if (sample >= 1.0f) {
   226         if (sample >= 1.0f) {
   227             *dst = 32767;
   227             *dst = 32767;
   228         } else if (sample <= -1.0f) {
   228         } else if (sample <= -1.0f) {
   229             *dst = -32767;
   229             *dst = -32768;
   230         } else {
   230         } else {
   231             *dst = (Sint16)(sample * 32767.0f);
   231             *dst = (Sint16)(sample * 32767.0f);
   232         }
   232         }
   233     }
   233     }
   234 
   234 
   248     LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_U16");
   248     LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_U16");
   249 
   249 
   250     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
   250     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
   251         const float sample = *src;
   251         const float sample = *src;
   252         if (sample >= 1.0f) {
   252         if (sample >= 1.0f) {
   253             *dst = 65534;
   253             *dst = 65535;
   254         } else if (sample <= -1.0f) {
   254         } else if (sample <= -1.0f) {
   255             *dst = 0;
   255             *dst = 0;
   256         } else {
   256         } else {
   257             *dst = (Uint16)((sample + 1.0f) * 32767.0f);
   257             *dst = (Uint16)((sample + 1.0f) * 32767.0f);
   258         }
   258         }
   276     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
   276     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
   277         const float sample = *src;
   277         const float sample = *src;
   278         if (sample >= 1.0f) {
   278         if (sample >= 1.0f) {
   279             *dst = 2147483647;
   279             *dst = 2147483647;
   280         } else if (sample <= -1.0f) {
   280         } else if (sample <= -1.0f) {
   281             *dst = -2147483647;
   281             *dst = -2147483648;
   282         } else {
   282         } else {
   283             *dst = ((Sint32)(sample * 8388607.0f)) << 8;
   283             *dst = ((Sint32)(sample * 8388607.0f)) << 8;
   284         }
   284         }
   285     }
   285     }
   286 
   286