Commit b344246d authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

audio_format: stick to single precision arithmethic (except for FL64)

parent f5e117e3
...@@ -185,7 +185,7 @@ static block_t *S16toFl32(filter_t *filter, block_t *bsrc) ...@@ -185,7 +185,7 @@ static block_t *S16toFl32(filter_t *filter, block_t *bsrc)
* of 19 seconds for the above division. */ * of 19 seconds for the above division. */
union { float f; int32_t i; } u; union { float f; int32_t i; } u;
u.i = *src++ + 0x43c00000; u.i = *src++ + 0x43c00000;
*dst++ = u.f - 384.0; *dst++ = u.f - 384.f;
} }
#endif #endif
out: out:
...@@ -265,7 +265,7 @@ static block_t *Fl32toS16(filter_t *filter, block_t *b) ...@@ -265,7 +265,7 @@ static block_t *Fl32toS16(filter_t *filter, block_t *b)
#else #else
/* This is Walken's trick based on IEEE float format. */ /* This is Walken's trick based on IEEE float format. */
union { float f; int32_t i; } u; union { float f; int32_t i; } u;
u.f = *src++ + 384.0; u.f = *src++ + 384.f;
if (u.i > 0x43c07fff) if (u.i > 0x43c07fff)
*dst++ = 32767; *dst++ = 32767;
else if (u.i < 0x43bf8000) else if (u.i < 0x43bf8000)
...@@ -375,11 +375,11 @@ static block_t *Fl64toU8(filter_t *filter, block_t *b) ...@@ -375,11 +375,11 @@ static block_t *Fl64toU8(filter_t *filter, block_t *b)
uint8_t *dst = (uint8_t *)src; uint8_t *dst = (uint8_t *)src;
for (size_t i = b->i_buffer / 8; i--;) for (size_t i = b->i_buffer / 8; i--;)
{ {
float s = *(src++) * 128.f; float s = *(src++) * 128.;
if (s >= 127.) if (s >= 127.f)
*(dst++) = 255; *(dst++) = 255;
else else
if (s <= -128.) if (s <= -128.f)
*(dst++) = 0; *(dst++) = 0;
else else
*(dst++) = lround(s) + 128; *(dst++) = lround(s) + 128;
...@@ -426,10 +426,10 @@ static block_t *Fl64toS32(filter_t *filter, block_t *b) ...@@ -426,10 +426,10 @@ static block_t *Fl64toS32(filter_t *filter, block_t *b)
for (size_t i = b->i_buffer / 8; i--;) for (size_t i = b->i_buffer / 8; i--;)
{ {
float s = *(src++) * 2147483648.; float s = *(src++) * 2147483648.;
if (s >= 2147483647.) if (s >= 2147483647.f)
*(dst++) = 2147483647; *(dst++) = 2147483647;
else else
if (s <= -2147483648.) if (s <= -2147483648.f)
*(dst++) = -2147483648; *(dst++) = -2147483648;
else else
*(dst++) = lround(s); *(dst++) = lround(s);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment