src/audio/SDL_audiotypecvt.c
changeset 11989 d194f4f41437
parent 11987 0c284754e25b
child 11990 ce0099c8d037
equal deleted inserted replaced
11988:8fa59be85dfb 11989:d194f4f41437
   169 
   169 
   170     LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_S8");
   170     LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_S8");
   171 
   171 
   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 = -127;
   178         } else {
   178         } else {
   179             *dst = (Sint8)(sample * 127.0f);
   179             *dst = (Sint8)(sample * 127.0f);
   180         }
   180         }
   181     }
   181     }
   195 
   195 
   196     LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_U8");
   196     LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_U8");
   197 
   197 
   198     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
   198     for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
   199         const float sample = *src;
   199         const float sample = *src;
   200         if (sample > 1.0f) {
   200         if (sample >= 1.0f) {
   201             *dst = 255;
   201             *dst = 255;
   202         } else if (sample < -1.0f) {
   202         } else if (sample <= -1.0f) {
   203             *dst = 0;
   203             *dst = 0;
   204         } else {
   204         } else {
   205             *dst = (Uint8)((sample + 1.0f) * 127.0f);
   205             *dst = (Uint8)((sample + 1.0f) * 127.0f);
   206         }
   206         }
   207     }
   207     }
   221 
   221 
   222     LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_S16");
   222     LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_S16");
   223 
   223 
   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 = -32767;
   230         } else {
   230         } else {
   231             *dst = (Sint16)(sample * 32767.0f);
   231             *dst = (Sint16)(sample * 32767.0f);
   232         }
   232         }
   233     }
   233     }
   247 
   247 
   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 = 65534;
   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         }
   259     }
   259     }
   273 
   273 
   274     LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_S32");
   274     LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_S32");
   275 
   275 
   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 = -2147483647;
   282         } else {
   282         } else {
   283             *dst = ((Sint32)(sample * 8388607.0f)) << 8;
   283             *dst = ((Sint32)(sample * 8388607.0f)) << 8;
   284         }
   284         }
   285     }
   285     }