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

Commit fc26d68c authored by jiabin's avatar jiabin
Browse files

EffectHG: fix issues when parameters is nan.

HapticGenerator is compiled with fast math flag, which will make
standard isnan always return false. In that case, use safe_isnan from
audio_utils instead.

Also, when the Q factor is nan, BSF zero Q should be initialized as
DEFAULT_BSF_ZERO_Q.

Bug: 312775078
Test: make, run HapticGenerator
Change-Id: I3fbf2e3b804ecb56019d3e08181852641bb74e4d
parent 97be1363
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -28,12 +28,12 @@

#include <errno.h>
#include <inttypes.h>
#include <math.h>

#include <android-base/parsedouble.h>
#include <android-base/properties.h>
#include <audio_effects/effect_hapticgenerator.h>
#include <audio_utils/format.h>
#include <audio_utils/safe_math.h>
#include <system/audio.h>

static constexpr float DEFAULT_RESONANT_FREQUENCY = 150.0f;
@@ -338,8 +338,9 @@ int HapticGenerator_SetParameter(struct HapticGeneratorContext *context,
        const float qFactor = *((float *) value + 1);
        const float maxAmplitude = *((float *) value + 2);
        context->param.resonantFrequency =
                isnan(resonantFrequency) ? DEFAULT_RESONANT_FREQUENCY : resonantFrequency;
        context->param.bsfZeroQ = isnan(qFactor) ? DEFAULT_BSF_POLE_Q : qFactor;
                audio_utils::safe_isnan(resonantFrequency) ? DEFAULT_RESONANT_FREQUENCY
                                                           : resonantFrequency;
        context->param.bsfZeroQ = audio_utils::safe_isnan(qFactor) ? DEFAULT_BSF_ZERO_Q : qFactor;
        context->param.bsfPoleQ = context->param.bsfZeroQ / 2.0f;
        context->param.maxHapticAmplitude = maxAmplitude;
        ALOGD("Updating vibrator info, resonantFrequency=%f, bsfZeroQ=%f, bsfPoleQ=%f, "