1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <cstdlib> 20 #include <map> 21 #include <memory> 22 23 #include <aidl/android/hardware/audio/effect/BnEffect.h> 24 #include <fmq/AidlMessageQueue.h> 25 26 #include "effect-impl/EffectImpl.h" 27 28 namespace aidl::android::hardware::audio::effect { 29 30 class HapticGeneratorSwContext final : public EffectContext { 31 public: HapticGeneratorSwContext(int statusDepth,const Parameter::Common & common)32 HapticGeneratorSwContext(int statusDepth, const Parameter::Common& common) 33 : EffectContext(statusDepth, common) { 34 LOG(DEBUG) << __func__; 35 } 36 37 RetCode setHgHapticScales(const std::vector<HapticGenerator::HapticScale>& hapticScales); 38 std::vector<HapticGenerator::HapticScale> getHgHapticScales() const; 39 setHgVibratorInformation(const HapticGenerator::VibratorInformation & vibratorInfo)40 RetCode setHgVibratorInformation(const HapticGenerator::VibratorInformation& vibratorInfo) { 41 // All float values are valid for resonantFrequencyHz, qFactor, maxAmplitude 42 mVibratorInformation = vibratorInfo; 43 return RetCode::SUCCESS; 44 } 45 getHgVibratorInformation()46 HapticGenerator::VibratorInformation getHgVibratorInformation() const { 47 return mVibratorInformation; 48 } 49 50 private: 51 static constexpr float DEFAULT_RESONANT_FREQUENCY = 150.0f; 52 static constexpr float DEFAULT_Q_FACTOR = 1.0f; 53 static constexpr float DEFAULT_MAX_AMPLITUDE = 0.0f; 54 std::map<int /* trackID */, HapticGenerator::HapticScale> mHapticScales; 55 HapticGenerator::VibratorInformation mVibratorInformation = { 56 DEFAULT_RESONANT_FREQUENCY, DEFAULT_Q_FACTOR, DEFAULT_MAX_AMPLITUDE}; 57 }; 58 59 class HapticGeneratorSw final : public EffectImpl { 60 public: 61 static const std::string kEffectName; 62 static const Descriptor kDescriptor; HapticGeneratorSw()63 HapticGeneratorSw() { LOG(DEBUG) << __func__; } ~HapticGeneratorSw()64 ~HapticGeneratorSw() { 65 cleanUp(); 66 LOG(DEBUG) << __func__; 67 } 68 69 ndk::ScopedAStatus getDescriptor(Descriptor* _aidl_return) override; 70 ndk::ScopedAStatus setParameterSpecific(const Parameter::Specific& specific) 71 REQUIRES(mImplMutex) override; 72 ndk::ScopedAStatus getParameterSpecific(const Parameter::Id& id, Parameter::Specific* specific) 73 REQUIRES(mImplMutex) override; 74 75 std::shared_ptr<EffectContext> createContext(const Parameter::Common& common) 76 REQUIRES(mImplMutex) override; 77 RetCode releaseContext() REQUIRES(mImplMutex) override; 78 79 IEffect::Status effectProcessImpl(float* in, float* out, int samples) 80 REQUIRES(mImplMutex) override; getEffectName()81 std::string getEffectName() override { return kEffectName; } 82 83 private: 84 std::shared_ptr<HapticGeneratorSwContext> mContext GUARDED_BY(mImplMutex); 85 86 ndk::ScopedAStatus getParameterHapticGenerator(const HapticGenerator::Tag& tag, 87 Parameter::Specific* specific) 88 REQUIRES(mImplMutex); 89 }; 90 } // namespace aidl::android::hardware::audio::effect 91