Skip to content

Commit dadc01b

Browse files
committed
Audio: Volume: Fix a possible overflow in S24_LE format volume
The AE_SRAI32R() right shift with round could cause the value to go over S24_LE range by one if the gain would be over one or 0 dB (only possible in IPC3). The rounding shift is unnecessary because the gain product is already rounded in the multiply instruction. The SRAI32() instruction does just the shift. Fixes: f3e3403 ("Audio: Volume: Add IPC4 native Q1.31 mode and optimize") Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
1 parent d677107 commit dadc01b

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

src/audio/volume/volume_hifi3.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_strea
122122
out_sample = AE_MULFP32X2RS(volume, AE_SLAI32(in_sample, 8));
123123
#endif
124124

125-
/* Shift and round for S24_LE */
126-
out_sample = AE_SRAI32R(out_sample, 8);
125+
/* Shift to S24_LE */
126+
out_sample = AE_SRAI32(out_sample, 8);
127127

128128
/* Store the output sample */
129129
AE_SA32X2_IP(out_sample, outu, out);

src/audio/volume/volume_hifi3_with_peakvol.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_strea
9191
out_sample = AE_MULFP32X2RS(volume, AE_SLAI32(in_sample, 8));
9292
#endif
9393

94-
/* Shift and round for S24_LE */
95-
out_sample = AE_SRAI32R(out_sample, 8);
94+
/* Shift to S24_LE */
95+
out_sample = AE_SRAI32(out_sample, 8);
9696
/* Store the output sample */
9797
AE_S32_L_XP(out_sample, out, inc);
9898
}

src/audio/volume/volume_hifi4.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_strea
122122
out_sample = AE_MULFP32X2RS(volume, AE_SLAI32(in_sample, 8));
123123
#endif
124124

125-
/* Shift and round for S24_LE */
126-
out_sample = AE_SRAI32R(out_sample, 8);
125+
/* Shift to S24_LE */
126+
out_sample = AE_SRAI32(out_sample, 8);
127127

128128
/* Store the output sample */
129129
AE_SA32X2_IP(out_sample, outu, out);

src/audio/volume/volume_hifi4_with_peakvol.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_strea
120120
out_sample = AE_MULFP32X2RS(volume, AE_SLAI32(in_sample, 8));
121121
#endif
122122

123-
/* Shift and round for S24_LE */
124-
out_sample = AE_SRAI32R(out_sample, 8);
123+
/* Shift to S24_LE */
124+
out_sample = AE_SRAI32(out_sample, 8);
125125

126126
/* Store the output sample */
127127
AE_SA32X2_IP(out_sample, outu, out);

0 commit comments

Comments
 (0)