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

Commit 341ee734 authored by jiabin's avatar jiabin
Browse files

Read vendor distortion output gain.

As the motor may be various on different devices, it makes sense to have
different distortion output gain for HapticGenerator effect so that the
generated data will not be harmful to motor.

Bug: 188025353
Test: manual
Change-Id: I74faef55005447f66410f173d8b41909a7ae87d2
parent fea6ac81
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ cc_library_shared {

    shared_libs: [
        "libaudioutils",
        "libbase",
        "libbinder",
        "liblog",
        "libutils",
+16 −1
Original line number Diff line number Diff line
@@ -22,12 +22,15 @@

#include <algorithm>
#include <memory>
#include <string>
#include <utility>

#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 <system/audio.h>
@@ -35,6 +38,7 @@
static constexpr float DEFAULT_RESONANT_FREQUENCY = 150.0f;
static constexpr float DEFAULT_BSF_ZERO_Q = 8.0f;
static constexpr float DEFAULT_BSF_POLE_Q = 4.0f;
static constexpr float DEFAULT_DISTORTION_OUTPUT_GAIN = 1.5f;

// This is the only symbol that needs to be exported
__attribute__ ((visibility ("default")))
@@ -81,6 +85,15 @@ static const effect_descriptor_t gHgDescriptor = {

namespace {

float getFloatProperty(const std::string& key, float defaultValue) {
    float result;
    std::string value = android::base::GetProperty(key, "");
    if (!value.empty() && android::base::ParseFloat(value, &result)) {
        return result;
    }
    return defaultValue;
}

int HapticGenerator_Init(struct HapticGeneratorContext *context) {
    context->itfe = &gHapticGeneratorInterface;

@@ -114,7 +127,9 @@ int HapticGenerator_Init(struct HapticGeneratorContext *context) {
    context->param.distortionCornerFrequency = 300.0f;
    context->param.distortionInputGain = 0.3f;
    context->param.distortionCubeThreshold = 0.1f;
    context->param.distortionOutputGain = 1.5f;
    context->param.distortionOutputGain = getFloatProperty(
            "vendor.audio.hapticgenerator.distortion.output.gain", DEFAULT_DISTORTION_OUTPUT_GAIN);
    ALOGD("Using distortion output gain as %f", context->param.distortionOutputGain);

    context->state = HAPTICGENERATOR_STATE_INITIALIZED;
    return 0;