summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2006-03-26 17:41:36 +0000
committerJens Arnold <amiconn@rockbox.org>2006-03-26 17:41:36 +0000
commit8083e8c0de4d03985afe72f83bd9c76ce715ce41 (patch)
tree5ba6353ce6476919b0e1ab9434be8622d865d3c7
parentd9ef5980df35fa4c7dc60fddf781cd71463c9746 (diff)
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
-rw-r--r--apps/dsp.c15
-rw-r--r--firmware/sound.c18
2 files changed, 17 insertions, 16 deletions
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;
}
diff --git a/firmware/sound.c b/firmware/sound.c
index 88412c4094..70f7346599 100644
--- a/firmware/sound.c
+++ b/firmware/sound.c
@@ -504,12 +504,12 @@ static void set_channel_config(void)
}
else
{
- fp_straight = - (1<<19);
- fp_cross = ((2 * fp_width / (((1<<19) + fp_width) >> 10))
- << 9) - (1<<19);
+ /* straight = - (1 + width) / (2 * width) */
+ fp_straight = - ((((1<<19) + fp_width) / (fp_width >> 9)) << 9);
+ fp_cross = (1<<19) + fp_straight;
}
- val_ll = val_rr = fp_straight & 0xFFFFF;
- val_lr = val_rl = fp_cross & 0xFFFFF;
+ val_ll = val_rr = fp_straight & 0xfffff;
+ val_lr = val_rl = fp_cross & 0xfffff;
}
break;
@@ -528,10 +528,10 @@ static void set_channel_config(void)
break;
case SOUND_CHAN_KARAOKE:
- val_ll = 0x80001;
- val_lr = 0x7ffff;
- val_rl = 0x7ffff;
- val_rr = 0x80001;
+ val_ll = 0xc0000;
+ val_lr = 0x40000;
+ val_rl = 0x40000;
+ val_rr = 0xc0000;
break;
}