From 8083e8c0de4d03985afe72f83bd9c76ce715ce41 Mon Sep 17 00:00:00 2001 From: Jens Arnold Date: Sun, 26 Mar 2006 17:41:36 +0000 Subject: Fixed potential sample overflow in variable stereo width > 100% and karaoke mode, both hwcodec and swcodec. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9263 a1c6a512-1295-4272-9138-f99709370657 --- apps/dsp.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'apps/dsp.c') diff --git a/apps/dsp.c b/apps/dsp.c index 1f477d3f70..e5696bc7cd 100644 --- a/apps/dsp.c +++ b/apps/dsp.c @@ -706,13 +706,14 @@ void stereo_width_set(int value) { long width, straight, cross; - width = value*0x7fffff/100; + width = value * 0x7fffff / 100; if (value <= 100) { - straight = (0x7fffff + width)/2; + straight = (0x7fffff + width) / 2; cross = straight - width; } else { - straight = 0x7fffff; - cross = 0x7fffff - ((int64_t)(2*width) << 23)/(0x7fffff + width); + /* straight = (1 + width) / (2 * width) */ + straight = ((int64_t)(0x7fffff + width) << 22) / width; + cross = straight - 0x7fffff; } sw_gain = straight << 8; sw_cross = cross << 8; @@ -752,10 +753,10 @@ static void channels_process(int32_t **src, int num) break; case SOUND_CHAN_KARAOKE: for (i = 0; i < num; i++) { - int32_t left_sample = sl[i]; + int32_t left_sample = sl[i]/2; - sl[i] -= sr[i]; - sr[i] -= left_sample; + sl[i] = left_sample - sr[i]/2; + sr[i] = sr[i]/2 - left_sample; } break; } -- cgit v1.2.3