1 /*
2 * Copyright (C) 2020 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 #include <limits>
18
19 #define LOG_TAG "EffectsFactory7.0"
20 #include <log/log.h>
21
22 #include "EqualizerEffect.h"
23
24 using ::android::hardware::hidl_string;
25 using ::android::hardware::hidl_vec;
26 using ::android::hardware::Return;
27 using ::android::hardware::Void;
28 using namespace ::android::hardware::audio::common::V7_0;
29
30 namespace android::hardware::audio::effect::V7_0::implementation {
31
getDescriptor()32 const EffectDescriptor& EqualizerEffect::getDescriptor() {
33 // Note: for VTS tests only 'type' and 'uuid' fields are required.
34 // The actual implementation must provide meaningful values
35 // for all fields of the descriptor.
36 static const EffectDescriptor descriptor = {
37 .type =
38 {// Same UUID as AudioEffect.EFFECT_TYPE_EQUALIZER in Java.
39 0x0bed4300, 0xddd6, 0x11db, 0x8f34,
40 std::array<uint8_t, 6>{{0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}},
41 .uuid = {0, 0, 0, 1, std::array<uint8_t, 6>{{0, 0, 0, 0, 0, 0}}}};
42 return descriptor;
43 }
44
EqualizerEffect()45 EqualizerEffect::EqualizerEffect() : mEffect(new Effect(getDescriptor())) {
46 mProperties.bandLevels.resize(kNumBands);
47 }
48
getNumBands(getNumBands_cb _hidl_cb)49 Return<void> EqualizerEffect::getNumBands(getNumBands_cb _hidl_cb) {
50 _hidl_cb(Result::OK, kNumBands);
51 return Void();
52 }
53
getLevelRange(getLevelRange_cb _hidl_cb)54 Return<void> EqualizerEffect::getLevelRange(getLevelRange_cb _hidl_cb) {
55 _hidl_cb(Result::OK, std::numeric_limits<int16_t>::min(), std::numeric_limits<int16_t>::max());
56 return Void();
57 }
58
setBandLevel(uint16_t band,int16_t level)59 Return<Result> EqualizerEffect::setBandLevel(uint16_t band, int16_t level) {
60 if (band < kNumBands) {
61 mProperties.bandLevels[band] = level;
62 return Result::OK;
63 } else {
64 return Result::INVALID_ARGUMENTS;
65 }
66 }
67
getBandLevel(uint16_t band,getBandLevel_cb _hidl_cb)68 Return<void> EqualizerEffect::getBandLevel(uint16_t band, getBandLevel_cb _hidl_cb) {
69 if (band < kNumBands) {
70 _hidl_cb(Result::OK, mProperties.bandLevels[band]);
71 } else {
72 _hidl_cb(Result::INVALID_ARGUMENTS, 0);
73 }
74 return Void();
75 }
76
getBandCenterFrequency(uint16_t band,getBandCenterFrequency_cb _hidl_cb)77 Return<void> EqualizerEffect::getBandCenterFrequency(uint16_t band,
78 getBandCenterFrequency_cb _hidl_cb) {
79 (void)band;
80 _hidl_cb(Result::OK, 0);
81 return Void();
82 }
83
getBandFrequencyRange(uint16_t band,getBandFrequencyRange_cb _hidl_cb)84 Return<void> EqualizerEffect::getBandFrequencyRange(uint16_t band,
85 getBandFrequencyRange_cb _hidl_cb) {
86 (void)band;
87 _hidl_cb(Result::OK, 0, 1);
88 return Void();
89 }
90
getBandForFrequency(uint32_t freq,getBandForFrequency_cb _hidl_cb)91 Return<void> EqualizerEffect::getBandForFrequency(uint32_t freq, getBandForFrequency_cb _hidl_cb) {
92 (void)freq;
93 _hidl_cb(Result::OK, 0);
94 return Void();
95 }
96
getPresetNames(getPresetNames_cb _hidl_cb)97 Return<void> EqualizerEffect::getPresetNames(getPresetNames_cb _hidl_cb) {
98 hidl_vec<hidl_string> presetNames;
99 presetNames.resize(kNumPresets);
100 presetNames[0] = "default";
101 _hidl_cb(Result::OK, presetNames);
102 return Void();
103 }
104
setCurrentPreset(uint16_t preset)105 Return<Result> EqualizerEffect::setCurrentPreset(uint16_t preset) {
106 if (preset < kNumPresets) {
107 mProperties.curPreset = preset;
108 return Result::OK;
109 } else {
110 return Result::INVALID_ARGUMENTS;
111 }
112 }
113
getCurrentPreset(getCurrentPreset_cb _hidl_cb)114 Return<void> EqualizerEffect::getCurrentPreset(getCurrentPreset_cb _hidl_cb) {
115 _hidl_cb(Result::OK, mProperties.curPreset);
116 return Void();
117 }
118
setAllProperties(const IEqualizerEffect::AllProperties & properties)119 Return<Result> EqualizerEffect::setAllProperties(
120 const IEqualizerEffect::AllProperties& properties) {
121 mProperties = properties;
122 return Result::OK;
123 }
124
getAllProperties(getAllProperties_cb _hidl_cb)125 Return<void> EqualizerEffect::getAllProperties(getAllProperties_cb _hidl_cb) {
126 _hidl_cb(Result::OK, mProperties);
127 return Void();
128 }
129
130 } // namespace android::hardware::audio::effect::V7_0::implementation
131