Commit 4e909934 authored by Edward Hervey's avatar Edward Hervey 🤘 Committed by Edward Hervey

rganalysis: Fix left shift of signed values

left shifting signed values is undefined.

Instead of doing "x << offs" which is undefined, do the equivalent
"x * (1 << offs)" which is well defined
parent d08e155e
......@@ -575,7 +575,7 @@ rg_analysis_analyze_mono_int16 (RgAnalysisCtx * ctx, gconstpointer data,
gint32 peak_sample = 0;
const gint16 *samples = (gint16 *) data;
guint n_samples = size / sizeof (gint16);
gint shift = sizeof (gint16) * 8 - depth;
gint shift = 1 << (sizeof (gint16) * 8 - depth);
gint i;
g_return_if_fail (depth <= (sizeof (gint16) * 8));
......@@ -586,7 +586,7 @@ rg_analysis_analyze_mono_int16 (RgAnalysisCtx * ctx, gconstpointer data,
n_samples -= n;
for (i = 0; i < n; i++) {
gint16 old_sample = samples[i] << shift;
gint16 old_sample = samples[i] * shift;
peak_sample = MAX (peak_sample, ABS ((gint32) old_sample));
conv_samples[i] = (gfloat) old_sample;
......@@ -607,7 +607,7 @@ rg_analysis_analyze_stereo_int16 (RgAnalysisCtx * ctx, gconstpointer data,
gint32 peak_sample = 0;
const gint16 *samples = (gint16 *) data;
guint n_frames = size / (sizeof (gint16) * 2);
gint shift = sizeof (gint16) * 8 - depth;
gint shift = 1 << (sizeof (gint16) * 8 - depth);
gint i;
g_return_if_fail (depth <= (sizeof (gint16) * 8));
......@@ -620,11 +620,11 @@ rg_analysis_analyze_stereo_int16 (RgAnalysisCtx * ctx, gconstpointer data,
for (i = 0; i < n; i++) {
gint16 old_sample;
old_sample = samples[2 * i] << shift;
old_sample = samples[2 * i] * shift;
peak_sample = MAX (peak_sample, ABS ((gint32) old_sample));
conv_samples_l[i] = (gfloat) old_sample;
old_sample = samples[2 * i + 1] << shift;
old_sample = samples[2 * i + 1] * shift;
peak_sample = MAX (peak_sample, ABS ((gint32) old_sample));
conv_samples_r[i] = (gfloat) old_sample;
}
......
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