shithub: sox

Download patch

ref: f0574854aff841d3be65f82bf74eb46272cd8588
parent: d338b60386001aea63fe036a7a81d2dae405ec88
author: Mans Rullgard <mans@mansr.com>
date: Wed Feb 6 08:46:39 EST 2019

make SOX_FLOAT_32BIT_TO_SAMPLE alias of SOX_FLOAT_64BIT_TO_SAMPLE

Conversions from floating-point formats should use the same formula.
The C language conversion from float to integer truncates the fractional
part toward zero.  To get the nearest integer, an adjustment by 0.5 away
from zero is thus needed.  The "64-bit" macro does this while the
"32-bit" one does not.  Fix this discrepancy by making the latter an
alias of the former.

--- a/src/sox.h
+++ b/src/sox.h
@@ -917,18 +917,7 @@
 @param clips Variable to increment if the input sample is too large or too small.
 @returns SoX native sample value.
 */
-#define SOX_FLOAT_32BIT_TO_SAMPLE(d,clips)                      \
-  (sox_sample_t)(                                               \
-    LSX_USE_VAR(sox_macro_temp_sample),                         \
-    sox_macro_temp_double = (d) * (SOX_SAMPLE_MAX + 1.0),       \
-    sox_macro_temp_double < SOX_SAMPLE_MIN ?                    \
-      ++(clips), SOX_SAMPLE_MIN :                               \
-      sox_macro_temp_double >= SOX_SAMPLE_MAX + 1.0 ?           \
-        sox_macro_temp_double > SOX_SAMPLE_MAX + 1.0 ?          \
-          ++(clips), SOX_SAMPLE_MAX :                           \
-          SOX_SAMPLE_MAX :                                      \
-        sox_macro_temp_double                                   \
-  )
+#define SOX_FLOAT_32BIT_TO_SAMPLE(d,clips) SOX_FLOAT_64BIT_TO_SAMPLE(d, clips)
 
 /**
 Client API: