• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <aidl/android/hardware/audio/effect/BnEffect.h>
20 #include <fmq/AidlMessageQueue.h>
21 #include <cstdlib>
22 #include <memory>
23 
24 #include "effect-impl/EffectImpl.h"
25 
26 namespace aidl::android::hardware::audio::effect {
27 
28 class VirtualizerSwContext final : public EffectContext {
29   public:
VirtualizerSwContext(int statusDepth,const Parameter::Common & common)30     VirtualizerSwContext(int statusDepth, const Parameter::Common& common)
31         : EffectContext(statusDepth, common) {
32         LOG(DEBUG) << __func__;
33     }
34     RetCode setVrStrength(int strength);
getVrStrength()35     int getVrStrength() const { return mStrength; }
setForcedDevice(const::aidl::android::media::audio::common::AudioDeviceDescription & device)36     RetCode setForcedDevice(
37             const ::aidl::android::media::audio::common::AudioDeviceDescription& device) {
38         mForceDevice = device;
39         return RetCode::SUCCESS;
40     }
getForcedDevice()41     aidl::android::media::audio::common::AudioDeviceDescription getForcedDevice() const {
42         return mForceDevice;
43     }
44 
45   private:
46     int mStrength = 0;
47     ::aidl::android::media::audio::common::AudioDeviceDescription mForceDevice;
48 };
49 
50 class VirtualizerSw final : public EffectImpl {
51   public:
52     static const std::string kEffectName;
53     static const Capability kCapability;
54     static const Descriptor kDescriptor;
VirtualizerSw()55     VirtualizerSw() { LOG(DEBUG) << __func__; }
~VirtualizerSw()56     ~VirtualizerSw() {
57         cleanUp();
58         LOG(DEBUG) << __func__;
59     }
60 
61     ndk::ScopedAStatus getDescriptor(Descriptor* _aidl_return) override;
62     ndk::ScopedAStatus setParameterSpecific(const Parameter::Specific& specific)
63             REQUIRES(mImplMutex) override;
64     ndk::ScopedAStatus getParameterSpecific(const Parameter::Id& id, Parameter::Specific* specific)
65             REQUIRES(mImplMutex) override;
66 
67     std::shared_ptr<EffectContext> createContext(const Parameter::Common& common)
68             REQUIRES(mImplMutex) override;
69     RetCode releaseContext() REQUIRES(mImplMutex) override;
70 
71     IEffect::Status effectProcessImpl(float* in, float* out, int samples) override;
getEffectName()72     std::string getEffectName() override { return kEffectName; }
73 
74   private:
75     static const std::vector<Range::VirtualizerRange> kRanges;
76     std::shared_ptr<VirtualizerSwContext> mContext GUARDED_BY(mImplMutex);
77 
78     ndk::ScopedAStatus getParameterVirtualizer(const Virtualizer::Tag& tag,
79                                                Parameter::Specific* specific) REQUIRES(mImplMutex);
80     ndk::ScopedAStatus getSpeakerAngles(const Virtualizer::SpeakerAnglesPayload payload,
81                                         Parameter::Specific* specific) REQUIRES(mImplMutex);
82 };
83 }  // namespace aidl::android::hardware::audio::effect
84