Avoid division by zero in audio envelope processing. Fixes sound FX on android in some games.

This commit is contained in:
Henrik Rydgard 2013-06-11 11:04:51 +02:00
parent ea2b923ddf
commit a581e0d180

View File

@ -646,9 +646,15 @@ static int durationFromRate(int rate)
const short expCurveReference = 0x7000;
// This needs a rewrite / rethink. Doing all this per sample is insane.
static int getExpCurveAt(int index, int duration) {
const short curveLength = sizeof(expCurve) / sizeof(short);
if (duration == 0) {
// Avoid division by zero, and thus undefined behaviour in conversion to int.
return 0;
}
float curveIndex = (index * curveLength) / (float) duration;
int curveIndex1 = (int) curveIndex;
int curveIndex2 = curveIndex1 + 1;