aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/convert/gen_convert_general.py
diff options
context:
space:
mode:
authorAaron Rossetto <aaron.rossetto@ni.com>2022-01-19 13:43:26 -0600
committerAaron Rossetto <aaron.rossetto@ni.com>2022-02-28 14:47:47 -0600
commit67478d43167c9e03751f63daf7359616566291f1 (patch)
tree098d9d1271a637e61f3843e71effdc50deed9f50 /host/lib/convert/gen_convert_general.py
parentb93a2bbf8253e3138c40dcb7527829d091818472 (diff)
downloaduhd-67478d43167c9e03751f63daf7359616566291f1.tar.gz
uhd-67478d43167c9e03751f63daf7359616566291f1.tar.bz2
uhd-67478d43167c9e03751f63daf7359616566291f1.zip
convert: Make narrowing conversions saturate
This commit modifies the explicitly written narrowing conversions to clamp the results to the limits of the signed integer type.
Diffstat (limited to 'host/lib/convert/gen_convert_general.py')
-rw-r--r--host/lib/convert/gen_convert_general.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/host/lib/convert/gen_convert_general.py b/host/lib/convert/gen_convert_general.py
index 40ea1c7ba..eb4330119 100644
--- a/host/lib/convert/gen_convert_general.py
+++ b/host/lib/convert/gen_convert_general.py
@@ -43,8 +43,9 @@ DECLARE_CONVERTER({fctype}, 1, sc16_chdr, 1, PRIORITY_GENERAL) {{
int16_t* output = reinterpret_cast<int16_t*>(outputs[0]);
for (size_t i = 0; i < nsamps * 2; i += 2) {{
- output[i] = static_cast<int16_t>(input[i] * {fptype}(scale_factor));
- output[i+1] = static_cast<int16_t>(input[i+1] * {fptype}(scale_factor));
+ output[i] = clamp<int16_t>(input[i] * {fptype}(scale_factor));
+ output[i+1] = clamp<int16_t>(input[i + 1] * {fptype}(scale_factor));
+
}}
}}