Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f97b682f authored by Krystian Turczyn's avatar Krystian Turczyn Committed by Zoran Jovanovic
Browse files

Fix for tone glitch produced in ToneGenerator

Delay line samples of ToneGenerator::WaveGenerator are saved between
getSamples() calls. The value of such sample may overflow short integer
range due to amplitude fluctuation. Therefore long field must be used
to store those samples in order to prevent tone corruption.

Change-Id: I987058ca4615ea64deedcbd8167e75393ecaf2de
parent bf1e74ed
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -304,7 +304,7 @@ private:


        short mA1_Q14;  // Q14 coefficient
        short mA1_Q14;  // Q14 coefficient
        // delay line of full amplitude generator
        // delay line of full amplitude generator
        short mS1, mS2;  // delay line S2 oldest
        long mS1, mS2;  // delay line S2 oldest
        short mS2_0;  // saved value for reinitialisation
        short mS2_0;  // saved value for reinitialisation
        short mAmplitude_Q15;  // Q15 amplitude
        short mAmplitude_Q15;  // Q15 amplitude
    };
    };
+4 −4
Original line number Original line Diff line number Diff line
@@ -1567,8 +1567,8 @@ void ToneGenerator::WaveGenerator::getSamples(short *outBuffer,
        lS1 = (long)0;
        lS1 = (long)0;
        lS2 = (long)mS2_0;
        lS2 = (long)mS2_0;
    } else {
    } else {
        lS1 = (long)mS1;
        lS1 = mS1;
        lS2 = (long)mS2;
        lS2 = mS2;
    }
    }
    lA1 = (long)mA1_Q14;
    lA1 = (long)mA1_Q14;
    lAmplitude = (long)mAmplitude_Q15;
    lAmplitude = (long)mAmplitude_Q15;
@@ -1604,8 +1604,8 @@ void ToneGenerator::WaveGenerator::getSamples(short *outBuffer,
    }
    }


    // save status
    // save status
    mS1 = (short)lS1;
    mS1 = lS1;
    mS2 = (short)lS2;
    mS2 = lS2;
}
}


}  // end namespace android
}  // end namespace android