mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-02 11:06:31 +00:00
utils.h: Add rounding to float conversion to int.
Quote from an audio engineer NR9V: There is a minor issue of a small amount of crossover distortion though as a result of `ast_slinear_saturated_multiply_float()` not rounding the float. This could result in some quiet but potentially audible distortion artifacts in lower volume parts of the signal. If you have for example a sign wave function with a max amplitude of just a few samples, all samples between -1 and 1 will be truncated to zero, resulting in the waveform no longer being a sine wave and in harmonic distortion. Resolves: #1176
This commit is contained in:
committed by
github-actions[bot]
parent
8149554e90
commit
d5ef09ea0c
@@ -495,8 +495,11 @@ static force_inline void ast_slinear_saturated_multiply_float(short *input, floa
|
||||
*input = 32767;
|
||||
else if (res < -32768)
|
||||
*input = -32768;
|
||||
else if (res > 0)
|
||||
*input = (short) (res + 0.5);
|
||||
else
|
||||
*input = (short) res;
|
||||
*input = (short) (res - 0.5);
|
||||
|
||||
}
|
||||
|
||||
static force_inline void ast_slinear_saturated_divide(short *input, short *value)
|
||||
@@ -511,8 +514,11 @@ static force_inline void ast_slinear_saturated_divide_float(short *input, float
|
||||
*input = 32767;
|
||||
else if (res < -32768)
|
||||
*input = -32768;
|
||||
else if (res > 0)
|
||||
*input = (short) (res + 0.5);
|
||||
else
|
||||
*input = (short) res;
|
||||
*input = (short) (res - 0.5);
|
||||
|
||||
}
|
||||
|
||||
#ifdef localtime_r
|
||||
|
Reference in New Issue
Block a user