mirror of
https://gitee.com/openharmony/third_party_libsnd
synced 2024-11-26 19:40:24 +00:00
Fix clipping of non-int32 numbers
Thanks @umlaeute.
This commit is contained in:
parent
c59207ef9e
commit
d8503a6645
@ -1692,18 +1692,14 @@ psf_f2s_clip_array (const float *src, short *dest, int count, int normalize)
|
||||
|
||||
for (int i = 0 ; i < count ; i++)
|
||||
{ scaled_value = src [i] * normfact ;
|
||||
#if CPU_CLIPS_POSITIVE == 0
|
||||
if (scaled_value >= (1.0 * 0x7FFF))
|
||||
{ dest [i] = 0x7FFF ;
|
||||
continue ;
|
||||
} ;
|
||||
#endif
|
||||
#if CPU_CLIPS_NEGATIVE == 0
|
||||
if (scaled_value <= (-8.0 * 0x1000))
|
||||
{ dest [i] = -0x7FFF - 1 ;
|
||||
continue ;
|
||||
} ;
|
||||
#endif
|
||||
|
||||
dest [i] = psf_lrintf (scaled_value) ;
|
||||
} ;
|
||||
@ -1730,18 +1726,14 @@ psf_d2s_clip_array (const double *src, short *dest, int count, int normalize)
|
||||
|
||||
for (int i = 0 ; i < count ; i++)
|
||||
{ scaled_value = src [i] * normfact ;
|
||||
#if CPU_CLIPS_POSITIVE == 0
|
||||
if (scaled_value >= (1.0 * 0x7FFF))
|
||||
{ dest [i] = 0x7FFF ;
|
||||
continue ;
|
||||
} ;
|
||||
#endif
|
||||
#if CPU_CLIPS_NEGATIVE == 0
|
||||
if (scaled_value <= (-8.0 * 0x1000))
|
||||
{ dest [i] = -0x7FFF - 1 ;
|
||||
continue ;
|
||||
} ;
|
||||
#endif
|
||||
|
||||
dest [i] = psf_lrint (scaled_value) ;
|
||||
} ;
|
||||
|
@ -496,9 +496,9 @@ d2s_clip_array (const double *src, int count, short *dest, double scale)
|
||||
{ for (int i = 0 ; i < count ; i++)
|
||||
{ double tmp = scale * src [i] ;
|
||||
|
||||
if (CPU_CLIPS_POSITIVE == 0 && tmp > 32767.0)
|
||||
if (tmp > 32767.0)
|
||||
dest [i] = SHRT_MAX ;
|
||||
else if (CPU_CLIPS_NEGATIVE == 0 && tmp < -32768.0)
|
||||
else if (tmp < -32768.0)
|
||||
dest [i] = SHRT_MIN ;
|
||||
else
|
||||
dest [i] = psf_lrint (tmp) ;
|
||||
|
24
src/flac.c
24
src/flac.c
@ -1191,11 +1191,11 @@ f2flac8_clip_array (const float *src, int32_t *dest, int count, int normalize)
|
||||
|
||||
for (int i = 0 ; i < count ; i++)
|
||||
{ scaled_value = src [i] * normfact ;
|
||||
if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7F))
|
||||
if (scaled_value >= (1.0 * 0x7F))
|
||||
{ dest [i] = 0x7F ;
|
||||
continue ;
|
||||
} ;
|
||||
if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x10))
|
||||
if (scaled_value <= (-8.0 * 0x10))
|
||||
{ dest [i] = -0x80 ;
|
||||
continue ;
|
||||
} ;
|
||||
@ -1213,11 +1213,11 @@ f2flac16_clip_array (const float *src, int32_t *dest, int count, int normalize)
|
||||
|
||||
for (int i = 0 ; i < count ; i++)
|
||||
{ scaled_value = src [i] * normfact ;
|
||||
if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFF))
|
||||
if (scaled_value >= (1.0 * 0x7FFF))
|
||||
{ dest [i] = 0x7FFF ;
|
||||
continue ;
|
||||
} ;
|
||||
if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x1000))
|
||||
if (scaled_value <= (-8.0 * 0x1000))
|
||||
{ dest [i] = -0x8000 ;
|
||||
continue ;
|
||||
} ;
|
||||
@ -1233,12 +1233,12 @@ f2flac24_clip_array (const float *src, int32_t *dest, int count, int normalize)
|
||||
|
||||
for (int i = 0 ; i < count ; i++)
|
||||
{ scaled_value = src [i] * normfact ;
|
||||
if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFFFF))
|
||||
if (scaled_value >= (1.0 * 0x7FFFFF))
|
||||
{ dest [i] = 0x7FFFFF ;
|
||||
continue ;
|
||||
} ;
|
||||
|
||||
if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x100000))
|
||||
if (scaled_value <= (-8.0 * 0x100000))
|
||||
{ dest [i] = -0x800000 ;
|
||||
continue ;
|
||||
}
|
||||
@ -1322,11 +1322,11 @@ d2flac8_clip_array (const double *src, int32_t *dest, int count, int normalize)
|
||||
|
||||
for (int i = 0 ; i < count ; i++)
|
||||
{ scaled_value = src [i] * normfact ;
|
||||
if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7F))
|
||||
if (scaled_value >= (1.0 * 0x7F))
|
||||
{ dest [i] = 0x7F ;
|
||||
continue ;
|
||||
} ;
|
||||
if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x10))
|
||||
if (scaled_value <= (-8.0 * 0x10))
|
||||
{ dest [i] = -0x80 ;
|
||||
continue ;
|
||||
} ;
|
||||
@ -1344,11 +1344,11 @@ d2flac16_clip_array (const double *src, int32_t *dest, int count, int normalize)
|
||||
|
||||
for (int i = 0 ; i < count ; i++)
|
||||
{ scaled_value = src [i] * normfact ;
|
||||
if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFF))
|
||||
if (scaled_value >= (1.0 * 0x7FFF))
|
||||
{ dest [i] = 0x7FFF ;
|
||||
continue ;
|
||||
} ;
|
||||
if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x1000))
|
||||
if (scaled_value <= (-8.0 * 0x1000))
|
||||
{ dest [i] = -0x8000 ;
|
||||
continue ;
|
||||
} ;
|
||||
@ -1366,11 +1366,11 @@ d2flac24_clip_array (const double *src, int32_t *dest, int count, int normalize)
|
||||
|
||||
for (int i = 0 ; i < count ; i++)
|
||||
{ scaled_value = src [i] * normfact ;
|
||||
if (CPU_CLIPS_POSITIVE == 0 && scaled_value >= (1.0 * 0x7FFFFF))
|
||||
if (scaled_value >= (1.0 * 0x7FFFFF))
|
||||
{ dest [i] = 0x7FFFFF ;
|
||||
continue ;
|
||||
} ;
|
||||
if (CPU_CLIPS_NEGATIVE == 0 && scaled_value <= (-8.0 * 0x100000))
|
||||
if (scaled_value <= (-8.0 * 0x100000))
|
||||
{ dest [i] = -0x800000 ;
|
||||
continue ;
|
||||
} ;
|
||||
|
@ -447,9 +447,9 @@ f2s_clip_array (const float *src, int count, short *dest, float scale)
|
||||
{ for (int i = 0 ; i < count ; i++)
|
||||
{ float tmp = scale * src [i] ;
|
||||
|
||||
if (CPU_CLIPS_POSITIVE == 0 && tmp > 32767.0)
|
||||
if (tmp > 32767.0)
|
||||
dest [i] = SHRT_MAX ;
|
||||
else if (CPU_CLIPS_NEGATIVE == 0 && tmp < -32768.0)
|
||||
else if (tmp < -32768.0)
|
||||
dest [i] = SHRT_MIN ;
|
||||
else
|
||||
dest [i] = psf_lrintf (tmp) ;
|
||||
|
32
src/pcm.c
32
src/pcm.c
@ -1786,18 +1786,14 @@ f2sc_clip_array (const float *src, signed char *dest, int count, int normalize)
|
||||
|
||||
for (int i = 0 ; i < count ; i++)
|
||||
{ scaled_value = src [i] * normfact ;
|
||||
#if CPU_CLIPS_POSITIVE == 0
|
||||
if (scaled_value >= (1.0 * 0x7FFFFFFF))
|
||||
{ dest [i] = 127 ;
|
||||
continue ;
|
||||
} ;
|
||||
#endif
|
||||
#if CPU_CLIPS_NEGATIVE == 0
|
||||
if (scaled_value <= (-8.0 * 0x10000000))
|
||||
{ dest [i] = -128 ;
|
||||
continue ;
|
||||
} ;
|
||||
#endif
|
||||
|
||||
dest [i] = psf_lrintf (scaled_value) >> 24 ;
|
||||
} ;
|
||||
@ -1849,18 +1845,14 @@ f2uc_clip_array (const float *src, unsigned char *dest, int count, int normalize
|
||||
|
||||
for (int i = 0 ; i < count ; i++)
|
||||
{ scaled_value = src [i] * normfact ;
|
||||
#if CPU_CLIPS_POSITIVE == 0
|
||||
if (scaled_value >= (1.0 * 0x7FFFFFFF))
|
||||
{ dest [i] = 0xFF ;
|
||||
continue ;
|
||||
} ;
|
||||
#endif
|
||||
#if CPU_CLIPS_NEGATIVE == 0
|
||||
if (scaled_value <= (-8.0 * 0x10000000))
|
||||
{ dest [i] = 0 ;
|
||||
continue ;
|
||||
} ;
|
||||
#endif
|
||||
|
||||
dest [i] = (psf_lrintf (scaled_value) >> 24) + 128 ;
|
||||
} ;
|
||||
@ -1920,20 +1912,16 @@ f2bes_clip_array (const float *src, short *dest, int count, int normalize)
|
||||
for (int i = 0 ; i < count ; i++)
|
||||
{ ucptr = (unsigned char*) &dest [i] ;
|
||||
scaled_value = src [i] * normfact ;
|
||||
#if CPU_CLIPS_POSITIVE == 0
|
||||
if (scaled_value >= (1.0 * 0x7FFFFFFF))
|
||||
{ ucptr [1] = 0xFF ;
|
||||
ucptr [0] = 0x7F ;
|
||||
continue ;
|
||||
} ;
|
||||
#endif
|
||||
#if CPU_CLIPS_NEGATIVE == 0
|
||||
if (scaled_value <= (-8.0 * 0x10000000))
|
||||
{ ucptr [1] = 0x00 ;
|
||||
ucptr [0] = 0x80 ;
|
||||
continue ;
|
||||
} ;
|
||||
#endif
|
||||
|
||||
value = psf_lrintf (scaled_value) ;
|
||||
ucptr [1] = value >> 16 ;
|
||||
@ -1995,20 +1983,16 @@ f2les_clip_array (const float *src, short *dest, int count, int normalize)
|
||||
for (int i = 0 ; i < count ; i++)
|
||||
{ ucptr = (unsigned char*) &dest [i] ;
|
||||
scaled_value = src [i] * normfact ;
|
||||
#if CPU_CLIPS_POSITIVE == 0
|
||||
if (scaled_value >= (1.0 * 0x7FFFFFFF))
|
||||
{ ucptr [0] = 0xFF ;
|
||||
ucptr [1] = 0x7F ;
|
||||
continue ;
|
||||
} ;
|
||||
#endif
|
||||
#if CPU_CLIPS_NEGATIVE == 0
|
||||
if (scaled_value <= (-8.0 * 0x10000000))
|
||||
{ ucptr [0] = 0x00 ;
|
||||
ucptr [1] = 0x80 ;
|
||||
continue ;
|
||||
} ;
|
||||
#endif
|
||||
|
||||
value = psf_lrintf (scaled_value) ;
|
||||
ucptr [0] = value >> 16 ;
|
||||
@ -2378,18 +2362,14 @@ d2sc_clip_array (const double *src, signed char *dest, int count, int normalize)
|
||||
|
||||
for (int i = 0 ; i < count ; i++)
|
||||
{ scaled_value = src [i] * normfact ;
|
||||
#if CPU_CLIPS_POSITIVE == 0
|
||||
if (scaled_value >= (1.0 * 0x7FFFFFFF))
|
||||
{ dest [i] = 127 ;
|
||||
continue ;
|
||||
} ;
|
||||
#endif
|
||||
#if CPU_CLIPS_NEGATIVE == 0
|
||||
if (scaled_value <= (-8.0 * 0x10000000))
|
||||
{ dest [i] = -128 ;
|
||||
continue ;
|
||||
} ;
|
||||
#endif
|
||||
|
||||
dest [i] = psf_lrintf (scaled_value) >> 24 ;
|
||||
} ;
|
||||
@ -2441,18 +2421,14 @@ d2uc_clip_array (const double *src, unsigned char *dest, int count, int normaliz
|
||||
|
||||
for (int i = 0 ; i < count ; i++)
|
||||
{ scaled_value = src [i] * normfact ;
|
||||
#if CPU_CLIPS_POSITIVE == 0
|
||||
if (scaled_value >= (1.0 * 0x7FFFFFFF))
|
||||
{ dest [i] = 255 ;
|
||||
continue ;
|
||||
} ;
|
||||
#endif
|
||||
#if CPU_CLIPS_NEGATIVE == 0
|
||||
if (scaled_value <= (-8.0 * 0x10000000))
|
||||
{ dest [i] = 0 ;
|
||||
continue ;
|
||||
} ;
|
||||
#endif
|
||||
|
||||
dest [i] = (psf_lrint (src [i] * normfact) >> 24) + 128 ;
|
||||
} ;
|
||||
@ -2512,20 +2488,16 @@ d2bes_clip_array (const double *src, short *dest, int count, int normalize)
|
||||
for (int i = 0 ; i < count ; i++)
|
||||
{ ucptr = (unsigned char*) &dest [i] ;
|
||||
scaled_value = src [i] * normfact ;
|
||||
#if CPU_CLIPS_POSITIVE == 0
|
||||
if (scaled_value >= (1.0 * 0x7FFFFFFF))
|
||||
{ ucptr [1] = 0xFF ;
|
||||
ucptr [0] = 0x7F ;
|
||||
continue ;
|
||||
} ;
|
||||
#endif
|
||||
#if CPU_CLIPS_NEGATIVE == 0
|
||||
if (scaled_value <= (-8.0 * 0x10000000))
|
||||
{ ucptr [1] = 0x00 ;
|
||||
ucptr [0] = 0x80 ;
|
||||
continue ;
|
||||
} ;
|
||||
#endif
|
||||
|
||||
value = psf_lrint (scaled_value) ;
|
||||
ucptr [1] = value >> 16 ;
|
||||
@ -2587,20 +2559,16 @@ d2les_clip_array (const double *src, short *dest, int count, int normalize)
|
||||
for (int i = 0 ; i < count ; i++)
|
||||
{ ucptr = (unsigned char*) &dest [i] ;
|
||||
scaled_value = src [i] * normfact ;
|
||||
#if CPU_CLIPS_POSITIVE == 0
|
||||
if (scaled_value >= (1.0 * 0x7FFFFFFF))
|
||||
{ ucptr [0] = 0xFF ;
|
||||
ucptr [1] = 0x7F ;
|
||||
continue ;
|
||||
} ;
|
||||
#endif
|
||||
#if CPU_CLIPS_NEGATIVE == 0
|
||||
if (scaled_value <= (-8.0 * 0x10000000))
|
||||
{ ucptr [0] = 0x00 ;
|
||||
ucptr [1] = 0x80 ;
|
||||
continue ;
|
||||
} ;
|
||||
#endif
|
||||
|
||||
value = psf_lrint (scaled_value) ;
|
||||
ucptr [0] = value >> 16 ;
|
||||
|
Loading…
Reference in New Issue
Block a user