[igt-dev] [PATCH i-g-t] lib/igt_audio: normalize samples when extracting channel

Simon Ser
2019-05-13T14:11:28Z

audio_extract_channel_s32_le converts S32 samples to double. Prior to this
patch, the output samples weren't normalized, resulting in values up to
INT32_MAX.

Future amplitude tests need to be format-agnostic (ie. shouldn't care whether
the format used is S16 or S32). Thus, it is preferable to always use normalized
double values.

The current tests don't check the amplitude (or check it relative to the max.
on the whole buffer), so they still pass without any modification.

Signed-off-by: Simon Ser <simon.ser@intel.com>
---
lib/igt_audio.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/igt_audio.c b/lib/igt_audio.c
index fd8cf07c0de3..f4b169595f6c 100644
--- a/lib/igt_audio.c
+++ b/lib/igt_audio.c
@@ -389,7 +389,7 @@ size_t audio_extract_channel_s32_le(double *dst, size_t dst_cap,
dst_len = src_len / n_channels;
igt_assert(dst_len <= dst_cap);
for (i = 0; i < dst_len; i++)
- dst[i] = (double) src[i * n_channels + channel];
+ dst[i] = (double) src[i * n_channels + channel] / INT32_MAX;

return dst_len;
}
--
2.21.0