blob: aa3a727040e8fb26fd1963fd3043bf2c2143e2ee [file] [log] [blame]
Shunkai Yaoea24c1a2022-09-28 17:39:23 +00001/*
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
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +000024#include "effect-impl/EffectContext.h"
25#include "effect-impl/EffectTypes.h"
26#include "effect-impl/EffectUUID.h"
27#include "effect-impl/EffectWorker.h"
Shunkai Yaoea24c1a2022-09-28 17:39:23 +000028
29namespace aidl::android::hardware::audio::effect {
30
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +000031class EqualizerSwContext : public EffectContext {
32 public:
33 EqualizerSwContext(int statusDepth, int inBufferSize, int outBufferSize)
34 : EffectContext(statusDepth, inBufferSize, outBufferSize) {
35 LOG(DEBUG) << __func__;
36 }
37
38 private:
39 // Add equalizer specific context for processing here
Shunkai Yaoea24c1a2022-09-28 17:39:23 +000040};
41
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +000042class EqualizerSw : public BnEffect, EffectWorker {
Shunkai Yaoea24c1a2022-09-28 17:39:23 +000043 public:
44 EqualizerSw() {
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +000045 Equalizer::Capability eqCap = {.bandFrequencies = mBandFrequency, .presets = mPresets};
46 mDesc.capability.set<Capability::equalizer>(eqCap);
Shunkai Yaoea24c1a2022-09-28 17:39:23 +000047 LOG(DEBUG) << __func__;
48 };
49 ~EqualizerSw() {
50 cleanUp();
51 LOG(DEBUG) << __func__;
52 };
53 ndk::ScopedAStatus open(const Parameter::Common& common, const Parameter::Specific& specific,
54 OpenEffectReturn* _aidl_return) override;
55 ndk::ScopedAStatus close() override;
56 ndk::ScopedAStatus getDescriptor(Descriptor* _aidl_return) override;
57
58 ndk::ScopedAStatus getState(State* _aidl_return) override;
59 ndk::ScopedAStatus command(CommandId in_commandId) override;
60 ndk::ScopedAStatus setParameter(const Parameter& in_param) override;
61 ndk::ScopedAStatus getParameter(const Parameter::Id& in_paramId,
62 Parameter* _aidl_return) override;
63
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +000064 IEffect::Status effectProcessImpl() override;
65
Shunkai Yaoea24c1a2022-09-28 17:39:23 +000066 private:
Shunkai Yaoea24c1a2022-09-28 17:39:23 +000067 // Effect descriptor.
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +000068 Descriptor mDesc = {.common = {.id = {.type = EqualizerTypeUUID, .uuid = EqualizerSwImplUUID}}};
Shunkai Yaoea24c1a2022-09-28 17:39:23 +000069
70 // Parameters.
71 Parameter::Common mCommonParam;
72 Equalizer mEqualizerParam; // TODO: the equalizer parameter needs to update
73
74 // Instance state INIT by default.
75 State mState = State::INIT;
76
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +000077 int mPreset = PRESET_CUSTOM; // the current preset
78 const std::vector<Equalizer::BandFrequency> mBandFrequency = {{0, 30000, 120000},
79 {1, 120001, 460000},
80 {2, 460001, 1800000},
81 {3, 1800001, 7000000},
82 {4, 7000001, 20000000}};
83 // preset band level
84 std::vector<Equalizer::BandLevel> mBandLevels = {{0, 3}, {1, 0}, {2, 0}, {3, 0}, {4, 3}};
85 // presets supported by the device
86 const std::vector<Equalizer::Preset> mPresets = {
87 {0, "Normal"}, {1, "Classical"}, {2, "Dance"}, {3, "Flat"}, {4, "Folk"},
88 {5, "Heavy Metal"}, {6, "Hip Hop"}, {7, "Jazz"}, {8, "Pop"}, {9, "Rock"}};
89 static const int NUM_OF_BANDS = 5;
90 static const int NUM_OF_PRESETS = 10;
91 static const int PRESET_CUSTOM = -1;
Shunkai Yaoea24c1a2022-09-28 17:39:23 +000092
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +000093 // Equalizer worker context
94 std::shared_ptr<EqualizerSwContext> mContext;
Shunkai Yaoea24c1a2022-09-28 17:39:23 +000095
96 ndk::ScopedAStatus setCommonParameter(const Parameter::Common& common_param);
97 ndk::ScopedAStatus setSpecificParameter(const Parameter::Specific& specific);
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +000098 ndk::ScopedAStatus getSpecificParameter(Parameter::Specific::Id id,
99 Parameter::Specific* specific);
100
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000101 void cleanUp();
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +0000102
103 IEffect::Status status(binder_status_t status, size_t consumed, size_t produced);
Shunkai Yaoea24c1a2022-09-28 17:39:23 +0000104};
105} // namespace aidl::android::hardware::audio::effect