blob: 3ed9ed20f2977977240f317e46638c3ffc4c3c3f [file] [log] [blame]
Ram Mohane4064ce2022-12-20 18:05:14 +05301/*
2 * Copyright (C) 2023 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
Ram Mohane4064ce2022-12-20 18:05:14 +053017#include <set>
18#include <string>
Ram Mohane4064ce2022-12-20 18:05:14 +053019#include <unordered_set>
20
Mikhail Naganov872d4a62023-03-09 18:19:01 -080021#define LOG_TAG "VtsHalDynamicsProcessingTest"
22#include <android-base/logging.h>
23
Ram Mohane4064ce2022-12-20 18:05:14 +053024#include <Utils.h>
Mikhail Naganov872d4a62023-03-09 18:19:01 -080025
Ram Mohane4064ce2022-12-20 18:05:14 +053026#include "EffectHelper.h"
Ram Mohanafdf90b2023-03-23 08:48:25 +053027#include "EffectRangeSpecific.h"
Ram Mohane4064ce2022-12-20 18:05:14 +053028
29using namespace android;
Ram Mohanafdf90b2023-03-23 08:48:25 +053030using namespace aidl::android::hardware::audio::effect::DynamicsProcessingRanges;
Ram Mohane4064ce2022-12-20 18:05:14 +053031
Ram Mohane4064ce2022-12-20 18:05:14 +053032using aidl::android::hardware::audio::effect::Descriptor;
33using aidl::android::hardware::audio::effect::DynamicsProcessing;
Shunkai Yaof8be1ac2023-03-06 18:41:27 +000034using aidl::android::hardware::audio::effect::getEffectTypeUuidDynamicsProcessing;
Ram Mohane4064ce2022-12-20 18:05:14 +053035using aidl::android::hardware::audio::effect::IEffect;
36using aidl::android::hardware::audio::effect::IFactory;
Ram Mohane4064ce2022-12-20 18:05:14 +053037using aidl::android::hardware::audio::effect::Parameter;
Jaideep Sharma74498412023-09-13 15:25:25 +053038using android::hardware::audio::common::testing::detail::TestExecutionTracer;
Ram Mohane4064ce2022-12-20 18:05:14 +053039
40/**
41 * Here we focus on specific parameter checking, general IEffect interfaces testing performed in
42 * VtsAudioEffectTargetTest.
43 */
44class DynamicsProcessingTestHelper : public EffectHelper {
45 public:
46 DynamicsProcessingTestHelper(std::pair<std::shared_ptr<IFactory>, Descriptor> pair,
47 int32_t channelLayOut = AudioChannelLayout::LAYOUT_STEREO) {
48 std::tie(mFactory, mDescriptor) = pair;
49 mChannelLayout = channelLayOut;
Mikhail Naganov872d4a62023-03-09 18:19:01 -080050 mChannelCount = ::aidl::android::hardware::audio::common::getChannelCount(
Ram Mohane4064ce2022-12-20 18:05:14 +053051 AudioChannelLayout::make<AudioChannelLayout::layoutMask>(mChannelLayout));
52 }
53
54 // setup
55 void SetUpDynamicsProcessingEffect() {
56 ASSERT_NE(nullptr, mFactory);
57 ASSERT_NO_FATAL_FAILURE(create(mFactory, mEffect, mDescriptor));
58
59 Parameter::Specific specific = getDefaultParamSpecific();
60 Parameter::Common common = EffectHelper::createParamCommon(
61 0 /* session */, 1 /* ioHandle */, 44100 /* iSampleRate */, 44100 /* oSampleRate */,
62 0x100 /* iFrameCount */, 0x100 /* oFrameCount */,
63 AudioChannelLayout::make<AudioChannelLayout::layoutMask>(mChannelLayout),
64 AudioChannelLayout::make<AudioChannelLayout::layoutMask>(mChannelLayout));
65 IEffect::OpenEffectReturn ret;
66 ASSERT_NO_FATAL_FAILURE(open(mEffect, common, specific, &ret, EX_NONE));
67 ASSERT_NE(nullptr, mEffect);
68 mEngineConfigApplied = mEngineConfigPreset;
69 }
70
71 Parameter::Specific getDefaultParamSpecific() {
72 DynamicsProcessing dp = DynamicsProcessing::make<DynamicsProcessing::engineArchitecture>(
73 mEngineConfigPreset);
74 Parameter::Specific specific =
75 Parameter::Specific::make<Parameter::Specific::dynamicsProcessing>(dp);
76 return specific;
77 }
78
79 // teardown
80 void TearDownDynamicsProcessingEffect() {
81 ASSERT_NO_FATAL_FAILURE(close(mEffect));
82 ASSERT_NO_FATAL_FAILURE(destroy(mFactory, mEffect));
83 }
84
85 // utils functions for parameter checking
Ram Mohane4064ce2022-12-20 18:05:14 +053086 bool isParamEqual(const DynamicsProcessing::Tag& tag, const DynamicsProcessing& dpRef,
87 const DynamicsProcessing& dpTest);
Ram Mohane4064ce2022-12-20 18:05:14 +053088 bool isEngineConfigEqual(const DynamicsProcessing::EngineArchitecture& refCfg,
89 const DynamicsProcessing::EngineArchitecture& testCfg);
90
91 template <typename T>
92 std::vector<T> filterEnabledVector(const std::vector<T>& vec);
93
94 template <typename T>
95 bool isAidlVectorEqualAfterFilter(const std::vector<T>& source, const std::vector<T>& target);
96
97 template <typename T>
98 bool isAidlVectorEqual(const std::vector<T>& source, const std::vector<T>& target);
99
Ram Mohanafdf90b2023-03-23 08:48:25 +0530100 template <typename T>
101 bool isChannelConfigValid(const std::vector<T>& cfgs) {
102 auto& channelCount = mChannelCount;
103 return std::all_of(cfgs.cbegin(), cfgs.cend(), [channelCount](const T& cfg) {
104 return (cfg.channel >= 0 && cfg.channel < channelCount);
105 });
106 }
107
108 template <typename T>
109 bool isBandConfigValid(const std::vector<T>& cfgs, int bandCount);
110
111 bool isParamValid(const DynamicsProcessing::Tag& tag, const DynamicsProcessing& dp);
112
Ram Mohane4064ce2022-12-20 18:05:14 +0530113 // get set params and validate
114 void SetAndGetDynamicsProcessingParameters();
115
116 // enqueue test parameters
117 void addEngineConfig(const DynamicsProcessing::EngineArchitecture& cfg);
118 void addPreEqChannelConfig(const std::vector<DynamicsProcessing::ChannelConfig>& cfg);
119 void addPostEqChannelConfig(const std::vector<DynamicsProcessing::ChannelConfig>& cfg);
120 void addMbcChannelConfig(const std::vector<DynamicsProcessing::ChannelConfig>& cfg);
121 void addPreEqBandConfigs(const std::vector<DynamicsProcessing::EqBandConfig>& cfgs);
122 void addPostEqBandConfigs(const std::vector<DynamicsProcessing::EqBandConfig>& cfgs);
123 void addMbcBandConfigs(const std::vector<DynamicsProcessing::MbcBandConfig>& cfgs);
124 void addLimiterConfig(const std::vector<DynamicsProcessing::LimiterConfig>& cfg);
125 void addInputGain(const std::vector<DynamicsProcessing::InputGain>& inputGain);
126
127 static constexpr float kPreferredProcessingDurationMs = 10.0f;
128 static constexpr int kBandCount = 5;
129 std::shared_ptr<IFactory> mFactory;
130 std::shared_ptr<IEffect> mEffect;
131 Descriptor mDescriptor;
132 DynamicsProcessing::EngineArchitecture mEngineConfigApplied;
133 DynamicsProcessing::EngineArchitecture mEngineConfigPreset{
134 .resolutionPreference =
135 DynamicsProcessing::ResolutionPreference::FAVOR_FREQUENCY_RESOLUTION,
136 .preferredProcessingDurationMs = kPreferredProcessingDurationMs,
137 .preEqStage = {.inUse = true, .bandCount = kBandCount},
138 .postEqStage = {.inUse = true, .bandCount = kBandCount},
139 .mbcStage = {.inUse = true, .bandCount = kBandCount},
140 .limiterInUse = true,
141 };
142
143 std::unordered_set<int /* channelId */> mPreEqChannelEnable;
144 std::unordered_set<int /* channelId */> mPostEqChannelEnable;
145 std::unordered_set<int /* channelId */> mMbcChannelEnable;
146 std::unordered_set<int /* channelId */> mLimiterChannelEnable;
147 static const std::set<std::vector<DynamicsProcessing::ChannelConfig>> kChannelConfigTestSet;
148 static const std::set<DynamicsProcessing::StageEnablement> kStageEnablementTestSet;
149 static const std::set<std::vector<DynamicsProcessing::InputGain>> kInputGainTestSet;
150
Ram Mohanafdf90b2023-03-23 08:48:25 +0530151 protected:
152 int mChannelCount;
153
Ram Mohane4064ce2022-12-20 18:05:14 +0530154 private:
155 int32_t mChannelLayout;
Ram Mohane4064ce2022-12-20 18:05:14 +0530156 std::vector<std::pair<DynamicsProcessing::Tag, DynamicsProcessing>> mTags;
157 void CleanUp() {
158 mTags.clear();
159 mPreEqChannelEnable.clear();
160 mPostEqChannelEnable.clear();
161 mMbcChannelEnable.clear();
162 mLimiterChannelEnable.clear();
163 }
164};
165
166// test value set for DynamicsProcessing::StageEnablement
167const std::set<DynamicsProcessing::StageEnablement>
168 DynamicsProcessingTestHelper::kStageEnablementTestSet = {
169 {.inUse = true, .bandCount = DynamicsProcessingTestHelper::kBandCount},
170 {.inUse = true, .bandCount = 0},
171 {.inUse = true, .bandCount = -1},
Ram Mohanafdf90b2023-03-23 08:48:25 +0530172 {.inUse = false, .bandCount = 0},
173 {.inUse = false, .bandCount = -1},
Ram Mohane4064ce2022-12-20 18:05:14 +0530174 {.inUse = false, .bandCount = DynamicsProcessingTestHelper::kBandCount}};
175
176// test value set for DynamicsProcessing::ChannelConfig
177const std::set<std::vector<DynamicsProcessing::ChannelConfig>>
178 DynamicsProcessingTestHelper::kChannelConfigTestSet = {
179 {{.channel = -1, .enable = false},
180 {.channel = 0, .enable = true},
181 {.channel = 1, .enable = false},
182 {.channel = 2, .enable = true}},
Ram Mohane4064ce2022-12-20 18:05:14 +0530183 {{.channel = -1, .enable = false}, {.channel = 2, .enable = true}},
Ram Mohane4064ce2022-12-20 18:05:14 +0530184 {{.channel = 0, .enable = true}, {.channel = 1, .enable = true}}};
185
186// test value set for DynamicsProcessing::InputGain
187const std::set<std::vector<DynamicsProcessing::InputGain>>
188 DynamicsProcessingTestHelper::kInputGainTestSet = {
189 {{.channel = 0, .gainDb = 10.f},
190 {.channel = 1, .gainDb = 0.f},
191 {.channel = 2, .gainDb = -10.f}},
Ram Mohane4064ce2022-12-20 18:05:14 +0530192 {{.channel = -1, .gainDb = -10.f}, {.channel = -2, .gainDb = 10.f}},
Ram Mohanafdf90b2023-03-23 08:48:25 +0530193 {{.channel = -1, .gainDb = 10.f}, {.channel = 0, .gainDb = -10.f}},
194 {{.channel = 0, .gainDb = 10.f}, {.channel = 1, .gainDb = -10.f}}};
Ram Mohane4064ce2022-12-20 18:05:14 +0530195
Ram Mohanafdf90b2023-03-23 08:48:25 +0530196template <typename T>
197bool DynamicsProcessingTestHelper::isBandConfigValid(const std::vector<T>& cfgs, int bandCount) {
Shunkai Yao972b4652024-03-29 23:09:04 +0000198 std::unordered_set<int> freqs;
Ram Mohanafdf90b2023-03-23 08:48:25 +0530199 for (auto cfg : cfgs) {
200 if (cfg.channel < 0 || cfg.channel >= mChannelCount) return false;
201 if (cfg.band < 0 || cfg.band >= bandCount) return false;
Shunkai Yao972b4652024-03-29 23:09:04 +0000202 // duplicated band index
203 if (freqs.find(cfg.band) != freqs.end()) return false;
204 freqs.insert(cfg.band);
Ram Mohanafdf90b2023-03-23 08:48:25 +0530205 }
Shunkai Yao972b4652024-03-29 23:09:04 +0000206 return true;
Ram Mohanafdf90b2023-03-23 08:48:25 +0530207}
208
209bool DynamicsProcessingTestHelper::isParamValid(const DynamicsProcessing::Tag& tag,
210 const DynamicsProcessing& dp) {
211 switch (tag) {
212 case DynamicsProcessing::preEq: {
Ram Mohanafdf90b2023-03-23 08:48:25 +0530213 return isChannelConfigValid(dp.get<DynamicsProcessing::preEq>());
214 }
215 case DynamicsProcessing::postEq: {
Ram Mohanafdf90b2023-03-23 08:48:25 +0530216 return isChannelConfigValid(dp.get<DynamicsProcessing::postEq>());
217 }
218 case DynamicsProcessing::mbc: {
Ram Mohanafdf90b2023-03-23 08:48:25 +0530219 return isChannelConfigValid(dp.get<DynamicsProcessing::mbc>());
220 }
221 case DynamicsProcessing::preEqBand: {
Ram Mohanafdf90b2023-03-23 08:48:25 +0530222 return isBandConfigValid(dp.get<DynamicsProcessing::preEqBand>(),
223 mEngineConfigApplied.preEqStage.bandCount);
224 }
225 case DynamicsProcessing::postEqBand: {
Ram Mohanafdf90b2023-03-23 08:48:25 +0530226 return isBandConfigValid(dp.get<DynamicsProcessing::postEqBand>(),
227 mEngineConfigApplied.postEqStage.bandCount);
228 }
229 case DynamicsProcessing::mbcBand: {
Ram Mohanafdf90b2023-03-23 08:48:25 +0530230 return isBandConfigValid(dp.get<DynamicsProcessing::mbcBand>(),
231 mEngineConfigApplied.mbcStage.bandCount);
232 }
233 case DynamicsProcessing::limiter: {
Ram Mohanafdf90b2023-03-23 08:48:25 +0530234 return isChannelConfigValid(dp.get<DynamicsProcessing::limiter>());
235 }
236 case DynamicsProcessing::inputGain: {
237 return isChannelConfigValid(dp.get<DynamicsProcessing::inputGain>());
238 }
239 default: {
240 return true;
241 }
242 }
243 return true;
244}
Ram Mohane4064ce2022-12-20 18:05:14 +0530245
Ram Mohane4064ce2022-12-20 18:05:14 +0530246bool DynamicsProcessingTestHelper::isParamEqual(const DynamicsProcessing::Tag& tag,
247 const DynamicsProcessing& dpRef,
248 const DynamicsProcessing& dpTest) {
249 switch (tag) {
250 case DynamicsProcessing::engineArchitecture: {
251 return isEngineConfigEqual(dpRef.get<DynamicsProcessing::engineArchitecture>(),
252 dpTest.get<DynamicsProcessing::engineArchitecture>());
253 }
254 case DynamicsProcessing::preEq: {
255 const auto& source = dpRef.get<DynamicsProcessing::preEq>();
256 const auto& target = dpTest.get<DynamicsProcessing::preEq>();
257 return isAidlVectorEqualAfterFilter<DynamicsProcessing::ChannelConfig>(source, target);
258 }
259 case DynamicsProcessing::postEq: {
260 return isAidlVectorEqualAfterFilter<DynamicsProcessing::ChannelConfig>(
261 dpRef.get<DynamicsProcessing::postEq>(),
262 dpTest.get<DynamicsProcessing::postEq>());
263 }
264 case DynamicsProcessing::mbc: {
265 return isAidlVectorEqualAfterFilter<DynamicsProcessing::ChannelConfig>(
266 dpRef.get<DynamicsProcessing::mbc>(), dpTest.get<DynamicsProcessing::mbc>());
267 }
268 case DynamicsProcessing::preEqBand: {
269 return isAidlVectorEqualAfterFilter<DynamicsProcessing::EqBandConfig>(
270 dpRef.get<DynamicsProcessing::preEqBand>(),
271 dpTest.get<DynamicsProcessing::preEqBand>());
272 }
273 case DynamicsProcessing::postEqBand: {
274 return isAidlVectorEqualAfterFilter<DynamicsProcessing::EqBandConfig>(
275 dpRef.get<DynamicsProcessing::postEqBand>(),
276 dpTest.get<DynamicsProcessing::postEqBand>());
277 }
278 case DynamicsProcessing::mbcBand: {
279 return isAidlVectorEqualAfterFilter<DynamicsProcessing::MbcBandConfig>(
280 dpRef.get<DynamicsProcessing::mbcBand>(),
281 dpTest.get<DynamicsProcessing::mbcBand>());
282 }
283 case DynamicsProcessing::limiter: {
284 return isAidlVectorEqualAfterFilter<DynamicsProcessing::LimiterConfig>(
285 dpRef.get<DynamicsProcessing::limiter>(),
286 dpTest.get<DynamicsProcessing::limiter>());
287 }
288 case DynamicsProcessing::inputGain: {
289 return isAidlVectorEqual<DynamicsProcessing::InputGain>(
290 dpRef.get<DynamicsProcessing::inputGain>(),
291 dpTest.get<DynamicsProcessing::inputGain>());
292 }
Shunkai Yaob2325e52023-03-03 19:34:47 +0000293 case DynamicsProcessing::vendor: {
Ram Mohane4064ce2022-12-20 18:05:14 +0530294 return false;
295 }
296 }
297}
298
Ram Mohane4064ce2022-12-20 18:05:14 +0530299bool DynamicsProcessingTestHelper::isEngineConfigEqual(
300 const DynamicsProcessing::EngineArchitecture& ref,
301 const DynamicsProcessing::EngineArchitecture& test) {
302 return ref == test;
303}
304
305template <typename T>
306std::vector<T> DynamicsProcessingTestHelper::filterEnabledVector(const std::vector<T>& vec) {
307 std::vector<T> ret;
308 std::copy_if(vec.begin(), vec.end(), std::back_inserter(ret),
309 [](const auto& v) { return v.enable; });
310 return ret;
311}
312
313template <typename T>
314bool DynamicsProcessingTestHelper::isAidlVectorEqual(const std::vector<T>& source,
315 const std::vector<T>& target) {
316 if (source.size() != target.size()) return false;
317
318 auto tempS = source;
319 auto tempT = target;
320 std::sort(tempS.begin(), tempS.end());
321 std::sort(tempT.begin(), tempT.end());
322 return tempS == tempT;
323}
324
325template <typename T>
326bool DynamicsProcessingTestHelper::isAidlVectorEqualAfterFilter(const std::vector<T>& source,
327 const std::vector<T>& target) {
328 return isAidlVectorEqual<T>(filterEnabledVector<T>(source), filterEnabledVector<T>(target));
329}
330
331void DynamicsProcessingTestHelper::SetAndGetDynamicsProcessingParameters() {
332 for (auto& it : mTags) {
333 auto& tag = it.first;
334 auto& dp = it.second;
335
336 // validate parameter
337 Descriptor desc;
338 ASSERT_STATUS(EX_NONE, mEffect->getDescriptor(&desc));
Ram Mohanafdf90b2023-03-23 08:48:25 +0530339 bool valid = isParamInRange(dp, desc.capability.range.get<Range::dynamicsProcessing>());
340 if (valid) valid = isParamValid(tag, dp);
Ram Mohane4064ce2022-12-20 18:05:14 +0530341 const binder_exception_t expected = valid ? EX_NONE : EX_ILLEGAL_ARGUMENT;
342
343 // set parameter
344 Parameter expectParam;
345 Parameter::Specific specific;
346 specific.set<Parameter::Specific::dynamicsProcessing>(dp);
347 expectParam.set<Parameter::specific>(specific);
Shunkai Yao0a0c45e2023-02-13 17:41:11 +0000348 ASSERT_STATUS(expected, mEffect->setParameter(expectParam))
349 << "\n"
350 << expectParam.toString() << "\n"
351 << desc.toString();
Ram Mohane4064ce2022-12-20 18:05:14 +0530352
353 // only get if parameter in range and set success
354 if (expected == EX_NONE) {
355 Parameter getParam;
356 Parameter::Id id;
357 DynamicsProcessing::Id dpId;
358 dpId.set<DynamicsProcessing::Id::commonTag>(tag);
359 id.set<Parameter::Id::dynamicsProcessingTag>(dpId);
360 // if set success, then get should match
361 EXPECT_STATUS(expected, mEffect->getParameter(id, &getParam));
362 Parameter::Specific specificTest = getParam.get<Parameter::specific>();
363 const auto& target = specificTest.get<Parameter::Specific::dynamicsProcessing>();
364 EXPECT_TRUE(isParamEqual(tag, dp, target)) << dp.toString() << "\n"
365 << target.toString();
366 // update mEngineConfigApplied after setting successfully
367 if (tag == DynamicsProcessing::engineArchitecture) {
368 mEngineConfigApplied = target.get<DynamicsProcessing::engineArchitecture>();
369 }
370 }
371 }
372}
373
374void DynamicsProcessingTestHelper::addEngineConfig(
375 const DynamicsProcessing::EngineArchitecture& cfg) {
376 DynamicsProcessing dp;
377 dp.set<DynamicsProcessing::engineArchitecture>(cfg);
378 mTags.push_back({DynamicsProcessing::engineArchitecture, dp});
379}
380
381void DynamicsProcessingTestHelper::addPreEqChannelConfig(
382 const std::vector<DynamicsProcessing::ChannelConfig>& cfgs) {
383 DynamicsProcessing dp;
384 dp.set<DynamicsProcessing::preEq>(cfgs);
385 mTags.push_back({DynamicsProcessing::preEq, dp});
386 for (auto& cfg : cfgs) {
387 if (cfg.enable) mPreEqChannelEnable.insert(cfg.channel);
388 }
389}
390
391void DynamicsProcessingTestHelper::addPostEqChannelConfig(
392 const std::vector<DynamicsProcessing::ChannelConfig>& cfgs) {
393 DynamicsProcessing dp;
394 dp.set<DynamicsProcessing::postEq>(cfgs);
395 mTags.push_back({DynamicsProcessing::postEq, dp});
396 for (auto& cfg : cfgs) {
397 if (cfg.enable) mPostEqChannelEnable.insert(cfg.channel);
398 }
399}
400
401void DynamicsProcessingTestHelper::addMbcChannelConfig(
402 const std::vector<DynamicsProcessing::ChannelConfig>& cfgs) {
403 DynamicsProcessing dp;
404 dp.set<DynamicsProcessing::mbc>(cfgs);
405 mTags.push_back({DynamicsProcessing::mbc, dp});
406 for (auto& cfg : cfgs) {
407 if (cfg.enable) mMbcChannelEnable.insert(cfg.channel);
408 }
409}
410
411void DynamicsProcessingTestHelper::addPreEqBandConfigs(
412 const std::vector<DynamicsProcessing::EqBandConfig>& cfgs) {
413 DynamicsProcessing dp;
414 dp.set<DynamicsProcessing::preEqBand>(cfgs);
415 mTags.push_back({DynamicsProcessing::preEqBand, dp});
416}
417
418void DynamicsProcessingTestHelper::addPostEqBandConfigs(
419 const std::vector<DynamicsProcessing::EqBandConfig>& cfgs) {
420 DynamicsProcessing dp;
421 dp.set<DynamicsProcessing::postEqBand>(cfgs);
422 mTags.push_back({DynamicsProcessing::postEqBand, dp});
423}
424
425void DynamicsProcessingTestHelper::addMbcBandConfigs(
426 const std::vector<DynamicsProcessing::MbcBandConfig>& cfgs) {
427 DynamicsProcessing dp;
428 dp.set<DynamicsProcessing::mbcBand>(cfgs);
429 mTags.push_back({DynamicsProcessing::mbcBand, dp});
430}
431
432void DynamicsProcessingTestHelper::addLimiterConfig(
433 const std::vector<DynamicsProcessing::LimiterConfig>& cfgs) {
434 DynamicsProcessing dp;
435 dp.set<DynamicsProcessing::limiter>(cfgs);
436 mTags.push_back({DynamicsProcessing::limiter, dp});
437 for (auto& cfg : cfgs) {
438 if (cfg.enable) mLimiterChannelEnable.insert(cfg.channel);
439 }
440}
441
442void DynamicsProcessingTestHelper::addInputGain(
443 const std::vector<DynamicsProcessing::InputGain>& inputGains) {
444 DynamicsProcessing dp;
445 dp.set<DynamicsProcessing::inputGain>(inputGains);
446 mTags.push_back({DynamicsProcessing::inputGain, dp});
447}
448
449/**
450 * Test DynamicsProcessing Engine Configuration
451 */
452enum EngineArchitectureTestParamName {
453 ENGINE_TEST_INSTANCE_NAME,
454 ENGINE_TEST_RESOLUTION_PREFERENCE,
455 ENGINE_TEST_PREFERRED_DURATION,
456 ENGINE_TEST_STAGE_ENABLEMENT,
457 ENGINE_TEST_LIMITER_IN_USE
458};
459using EngineArchitectureTestParams = std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor>,
460 DynamicsProcessing::ResolutionPreference, float,
461 DynamicsProcessing::StageEnablement, bool>;
462
463void fillEngineArchConfig(DynamicsProcessing::EngineArchitecture& cfg,
464 const EngineArchitectureTestParams& params) {
465 cfg.resolutionPreference = std::get<ENGINE_TEST_RESOLUTION_PREFERENCE>(params);
466 cfg.preferredProcessingDurationMs = std::get<ENGINE_TEST_PREFERRED_DURATION>(params);
467 cfg.preEqStage = cfg.postEqStage = cfg.mbcStage =
468 std::get<ENGINE_TEST_STAGE_ENABLEMENT>(params);
469 cfg.limiterInUse = std::get<ENGINE_TEST_LIMITER_IN_USE>(params);
470}
471
472class DynamicsProcessingTestEngineArchitecture
473 : public ::testing::TestWithParam<EngineArchitectureTestParams>,
474 public DynamicsProcessingTestHelper {
475 public:
476 DynamicsProcessingTestEngineArchitecture()
477 : DynamicsProcessingTestHelper(std::get<ENGINE_TEST_INSTANCE_NAME>(GetParam())) {
478 fillEngineArchConfig(mCfg, GetParam());
479 };
480
481 void SetUp() override { SetUpDynamicsProcessingEffect(); }
482
483 void TearDown() override { TearDownDynamicsProcessingEffect(); }
484
485 DynamicsProcessing::EngineArchitecture mCfg;
486};
487
488TEST_P(DynamicsProcessingTestEngineArchitecture, SetAndGetEngineArch) {
489 EXPECT_NO_FATAL_FAILURE(addEngineConfig(mCfg));
490 SetAndGetDynamicsProcessingParameters();
491}
492
493INSTANTIATE_TEST_SUITE_P(
494 DynamicsProcessingTest, DynamicsProcessingTestEngineArchitecture,
495 ::testing::Combine(
496 testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
Shunkai Yaof8be1ac2023-03-06 18:41:27 +0000497 IFactory::descriptor, getEffectTypeUuidDynamicsProcessing())),
Ram Mohanafdf90b2023-03-23 08:48:25 +0530498 testing::Values(
499 DynamicsProcessing::ResolutionPreference::FAVOR_TIME_RESOLUTION,
500 DynamicsProcessing::ResolutionPreference::FAVOR_FREQUENCY_RESOLUTION,
501 static_cast<DynamicsProcessing::ResolutionPreference>(-1)), // variant
502 testing::Values(-10.f, 0.f, 10.f), // processing duration
Ram Mohane4064ce2022-12-20 18:05:14 +0530503 testing::ValuesIn(
504 DynamicsProcessingTestHelper::kStageEnablementTestSet), // preEQ/postEQ/mbc
505 testing::Bool()), // limiter enable
506 [](const auto& info) {
507 auto descriptor = std::get<ENGINE_TEST_INSTANCE_NAME>(info.param).second;
508 DynamicsProcessing::EngineArchitecture cfg;
509 fillEngineArchConfig(cfg, info.param);
Jaideep Sharmae4c7a962023-06-14 19:14:44 +0530510 std::string name = getPrefix(descriptor) + "_Cfg_" + cfg.toString();
Ram Mohane4064ce2022-12-20 18:05:14 +0530511 std::replace_if(
512 name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
513 return name;
514 });
515GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(DynamicsProcessingTestEngineArchitecture);
516
517/**
518 * Test DynamicsProcessing Input Gain
519 */
520enum InputGainTestParamName {
521 INPUT_GAIN_INSTANCE_NAME,
522 INPUT_GAIN_PARAM,
523};
524class DynamicsProcessingTestInputGain
525 : public ::testing::TestWithParam<std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor>,
526 std::vector<DynamicsProcessing::InputGain>>>,
527 public DynamicsProcessingTestHelper {
528 public:
529 DynamicsProcessingTestInputGain()
530 : DynamicsProcessingTestHelper(std::get<INPUT_GAIN_INSTANCE_NAME>(GetParam())),
531 mInputGain(std::get<INPUT_GAIN_PARAM>(GetParam())){};
532
533 void SetUp() override { SetUpDynamicsProcessingEffect(); }
534
535 void TearDown() override { TearDownDynamicsProcessingEffect(); }
536
537 const std::vector<DynamicsProcessing::InputGain> mInputGain;
538};
539
540TEST_P(DynamicsProcessingTestInputGain, SetAndGetInputGain) {
541 EXPECT_NO_FATAL_FAILURE(addInputGain(mInputGain));
542 SetAndGetDynamicsProcessingParameters();
543}
544
545INSTANTIATE_TEST_SUITE_P(
546 DynamicsProcessingTest, DynamicsProcessingTestInputGain,
547 ::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
Shunkai Yaof8be1ac2023-03-06 18:41:27 +0000548 IFactory::descriptor, getEffectTypeUuidDynamicsProcessing())),
Ram Mohane4064ce2022-12-20 18:05:14 +0530549 testing::ValuesIn(DynamicsProcessingTestInputGain::kInputGainTestSet)),
550 [](const auto& info) {
551 auto descriptor = std::get<INPUT_GAIN_INSTANCE_NAME>(info.param).second;
552 std::string gains =
553 ::android::internal::ToString(std::get<INPUT_GAIN_PARAM>(info.param));
554 std::string name = "Implementor_" + descriptor.common.implementor + "_name_" +
555 descriptor.common.name + "_UUID_" +
Shunkai Yaofb8f3942024-03-29 18:45:30 +0000556 toString(descriptor.common.id.uuid) + "_inputGains_" + gains;
Ram Mohane4064ce2022-12-20 18:05:14 +0530557 std::replace_if(
558 name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
559 return name;
560 });
561GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(DynamicsProcessingTestInputGain);
562
563/**
564 * Test DynamicsProcessing Limiter Config
565 */
566enum LimiterConfigTestParamName {
567 LIMITER_INSTANCE_NAME,
568 LIMITER_CHANNEL,
569 LIMITER_ENABLE,
570 LIMITER_LINK_GROUP,
571 LIMITER_ENGINE_IN_USE,
572 LIMITER_ADDITIONAL,
573};
574enum LimiterConfigTestAdditionalParam {
575 LIMITER_ATTACK_TIME,
576 LIMITER_RELEASE_TIME,
577 LIMITER_RATIO,
578 LIMITER_THRESHOLD,
579 LIMITER_POST_GAIN,
580 LIMITER_MAX_NUM,
581};
582using LimiterConfigTestAdditional = std::array<float, LIMITER_MAX_NUM>;
Ram Mohanafdf90b2023-03-23 08:48:25 +0530583// attackTime, releaseTime, ratio, thresh, postGain
Ram Mohane4064ce2022-12-20 18:05:14 +0530584static constexpr std::array<LimiterConfigTestAdditional, 4> kLimiterConfigTestAdditionalParam = {
585 {{-1, -60, -2.5, -2, -3.14},
586 {-1, 60, -2.5, 2, -3.14},
587 {1, -60, 2.5, -2, 3.14},
Ram Mohanafdf90b2023-03-23 08:48:25 +0530588 {1, 60, 2.5, -2, 3.14}}};
Ram Mohane4064ce2022-12-20 18:05:14 +0530589
590using LimiterConfigTestParams =
591 std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor>, int32_t, bool, int32_t, bool,
592 LimiterConfigTestAdditional>;
593
594void fillLimiterConfig(DynamicsProcessing::LimiterConfig& cfg,
595 const LimiterConfigTestParams& params) {
596 const std::array<float, LIMITER_MAX_NUM> additional = std::get<LIMITER_ADDITIONAL>(params);
597 cfg.channel = std::get<LIMITER_CHANNEL>(params);
598 cfg.enable = std::get<LIMITER_ENABLE>(params);
599 cfg.linkGroup = std::get<LIMITER_LINK_GROUP>(params);
600 cfg.attackTimeMs = additional[LIMITER_ATTACK_TIME];
601 cfg.releaseTimeMs = additional[LIMITER_RELEASE_TIME];
602 cfg.ratio = additional[LIMITER_RATIO];
603 cfg.thresholdDb = additional[LIMITER_THRESHOLD];
604 cfg.postGainDb = additional[LIMITER_POST_GAIN];
605}
606
607class DynamicsProcessingTestLimiterConfig
608 : public ::testing::TestWithParam<LimiterConfigTestParams>,
609 public DynamicsProcessingTestHelper {
610 public:
611 DynamicsProcessingTestLimiterConfig()
612 : DynamicsProcessingTestHelper(std::get<LIMITER_INSTANCE_NAME>(GetParam())),
613 mLimiterInUseEngine(std::get<LIMITER_ENGINE_IN_USE>(GetParam())) {
614 fillLimiterConfig(mCfg, GetParam());
615 }
616
617 void SetUp() override { SetUpDynamicsProcessingEffect(); }
618
619 void TearDown() override { TearDownDynamicsProcessingEffect(); }
620
621 DynamicsProcessing::LimiterConfig mCfg;
622 bool mLimiterInUseEngine;
623};
624
625TEST_P(DynamicsProcessingTestLimiterConfig, SetAndGetLimiterConfig) {
626 mEngineConfigPreset.limiterInUse = mLimiterInUseEngine;
627 EXPECT_NO_FATAL_FAILURE(addEngineConfig(mEngineConfigPreset));
628 EXPECT_NO_FATAL_FAILURE(addLimiterConfig({mCfg}));
629 SetAndGetDynamicsProcessingParameters();
630}
631
632INSTANTIATE_TEST_SUITE_P(
633 DynamicsProcessingTest, DynamicsProcessingTestLimiterConfig,
634 ::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
Shunkai Yaof8be1ac2023-03-06 18:41:27 +0000635 IFactory::descriptor, getEffectTypeUuidDynamicsProcessing())),
Ram Mohane4064ce2022-12-20 18:05:14 +0530636 testing::Values(-1, 0, 1, 2), // channel count
637 testing::Bool(), // enable
638 testing::Values(3), // link group
639 testing::Bool(), // engine limiter enable
640 testing::ValuesIn(kLimiterConfigTestAdditionalParam)), // Additional
641 [](const auto& info) {
642 auto descriptor = std::get<LIMITER_INSTANCE_NAME>(info.param).second;
643 DynamicsProcessing::LimiterConfig cfg;
644 fillLimiterConfig(cfg, info.param);
645 std::string engineLimiterInUse =
646 std::to_string(std::get<LIMITER_ENGINE_IN_USE>(info.param));
647 std::string name = "Implementor_" + descriptor.common.implementor + "_name_" +
648 descriptor.common.name + "_UUID_" +
Shunkai Yaofb8f3942024-03-29 18:45:30 +0000649 toString(descriptor.common.id.uuid) + "_limiterConfig_" +
Ram Mohane4064ce2022-12-20 18:05:14 +0530650 cfg.toString() + "_engineSetting_" + engineLimiterInUse;
651 std::replace_if(
652 name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
653 return name;
654 });
655GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(DynamicsProcessingTestLimiterConfig);
656
657/**
658 * Test DynamicsProcessing ChannelConfig
659 */
660enum ChannelConfigTestParamName {
661 BAND_CHANNEL_TEST_INSTANCE_NAME,
662 BAND_CHANNEL_TEST_CHANNEL_CONFIG,
663 BAND_CHANNEL_TEST_ENGINE_IN_USE
664};
665using ChannelConfigTestParams = std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor>,
666 std::vector<DynamicsProcessing::ChannelConfig>, bool>;
667
668class DynamicsProcessingTestChannelConfig
669 : public ::testing::TestWithParam<ChannelConfigTestParams>,
670 public DynamicsProcessingTestHelper {
671 public:
672 DynamicsProcessingTestChannelConfig()
673 : DynamicsProcessingTestHelper(std::get<BAND_CHANNEL_TEST_INSTANCE_NAME>(GetParam())),
674 mCfg(std::get<BAND_CHANNEL_TEST_CHANNEL_CONFIG>(GetParam())),
675 mInUseEngine(std::get<BAND_CHANNEL_TEST_ENGINE_IN_USE>(GetParam())) {}
676
677 void SetUp() override { SetUpDynamicsProcessingEffect(); }
678
679 void TearDown() override { TearDownDynamicsProcessingEffect(); }
680
681 std::vector<DynamicsProcessing::ChannelConfig> mCfg;
682 const bool mInUseEngine;
683};
684
685TEST_P(DynamicsProcessingTestChannelConfig, SetAndGetPreEqChannelConfig) {
686 mEngineConfigPreset.preEqStage.inUse = mInUseEngine;
687 EXPECT_NO_FATAL_FAILURE(addEngineConfig(mEngineConfigPreset));
688 EXPECT_NO_FATAL_FAILURE(addPreEqChannelConfig(mCfg));
689 SetAndGetDynamicsProcessingParameters();
690}
691
692TEST_P(DynamicsProcessingTestChannelConfig, SetAndGetPostEqChannelConfig) {
693 mEngineConfigPreset.postEqStage.inUse = mInUseEngine;
694 EXPECT_NO_FATAL_FAILURE(addEngineConfig(mEngineConfigPreset));
695 EXPECT_NO_FATAL_FAILURE(addPostEqChannelConfig(mCfg));
696 SetAndGetDynamicsProcessingParameters();
697}
698
699TEST_P(DynamicsProcessingTestChannelConfig, SetAndGetMbcChannelConfig) {
700 mEngineConfigPreset.mbcStage.inUse = mInUseEngine;
701 EXPECT_NO_FATAL_FAILURE(addEngineConfig(mEngineConfigPreset));
702 EXPECT_NO_FATAL_FAILURE(addMbcChannelConfig(mCfg));
703 SetAndGetDynamicsProcessingParameters();
704}
705
706INSTANTIATE_TEST_SUITE_P(
707 DynamicsProcessingTest, DynamicsProcessingTestChannelConfig,
708 ::testing::Combine(
709 testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
Shunkai Yaof8be1ac2023-03-06 18:41:27 +0000710 IFactory::descriptor, getEffectTypeUuidDynamicsProcessing())),
Ram Mohane4064ce2022-12-20 18:05:14 +0530711 testing::ValuesIn(
712 DynamicsProcessingTestHelper::kChannelConfigTestSet), // channel config
713 testing::Bool()), // Engine inUse
714 [](const auto& info) {
715 auto descriptor = std::get<BAND_CHANNEL_TEST_INSTANCE_NAME>(info.param).second;
716 std::string engineInUse =
717 std::to_string(std::get<BAND_CHANNEL_TEST_ENGINE_IN_USE>(info.param));
718 std::string channelConfig = ::android::internal::ToString(
719 std::get<BAND_CHANNEL_TEST_CHANNEL_CONFIG>(info.param));
720
721 std::string name = "Implementor_" + descriptor.common.implementor + "_name_" +
722 descriptor.common.name + "_UUID_" +
Shunkai Yaofb8f3942024-03-29 18:45:30 +0000723 toString(descriptor.common.id.uuid) + "_" + channelConfig +
Ram Mohane4064ce2022-12-20 18:05:14 +0530724 "_engineInUse_" + engineInUse;
725 std::replace_if(
726 name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
727 return name;
728 });
729GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(DynamicsProcessingTestChannelConfig);
730
731/**
732 * Test DynamicsProcessing EqBandConfig
733 */
734enum EqBandConfigTestParamName {
735 EQ_BAND_INSTANCE_NAME,
736 EQ_BAND_CHANNEL,
Ram Mohane4064ce2022-12-20 18:05:14 +0530737 EQ_BAND_ENABLE,
738 EQ_BAND_CUT_OFF_FREQ,
739 EQ_BAND_GAIN,
740 EQ_BAND_STAGE_IN_USE
741};
742using EqBandConfigTestParams = std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor>, int32_t,
Ram Mohanafdf90b2023-03-23 08:48:25 +0530743 bool, std::vector<std::pair<int, float>>, float, bool>;
Ram Mohane4064ce2022-12-20 18:05:14 +0530744
745void fillEqBandConfig(std::vector<DynamicsProcessing::EqBandConfig>& cfgs,
746 const EqBandConfigTestParams& params) {
747 const std::vector<std::pair<int, float>> cutOffFreqs = std::get<EQ_BAND_CUT_OFF_FREQ>(params);
748 int bandCount = cutOffFreqs.size();
749 cfgs.resize(bandCount);
750 for (int i = 0; i < bandCount; i++) {
751 cfgs[i].channel = std::get<EQ_BAND_CHANNEL>(params);
752 cfgs[i].band = cutOffFreqs[i].first;
753 cfgs[i].enable = std::get<EQ_BAND_ENABLE>(params);
754 cfgs[i].cutoffFrequencyHz = cutOffFreqs[i].second;
755 cfgs[i].gainDb = std::get<EQ_BAND_GAIN>(params);
756 }
757}
758
759class DynamicsProcessingTestEqBandConfig : public ::testing::TestWithParam<EqBandConfigTestParams>,
760 public DynamicsProcessingTestHelper {
761 public:
762 DynamicsProcessingTestEqBandConfig()
763 : DynamicsProcessingTestHelper(std::get<EQ_BAND_INSTANCE_NAME>(GetParam())),
Ram Mohanafdf90b2023-03-23 08:48:25 +0530764 mStageInUse(std::get<EQ_BAND_STAGE_IN_USE>(GetParam())) {
Ram Mohane4064ce2022-12-20 18:05:14 +0530765 fillEqBandConfig(mCfgs, GetParam());
766 }
767
768 void SetUp() override { SetUpDynamicsProcessingEffect(); }
769
770 void TearDown() override { TearDownDynamicsProcessingEffect(); }
771
772 std::vector<DynamicsProcessing::EqBandConfig> mCfgs;
773 const bool mStageInUse;
Ram Mohane4064ce2022-12-20 18:05:14 +0530774};
775
776TEST_P(DynamicsProcessingTestEqBandConfig, SetAndGetPreEqBandConfig) {
777 mEngineConfigPreset.preEqStage.inUse = mStageInUse;
778 mEngineConfigPreset.preEqStage.bandCount = mCfgs.size();
779 EXPECT_NO_FATAL_FAILURE(addEngineConfig(mEngineConfigPreset));
Ram Mohanafdf90b2023-03-23 08:48:25 +0530780 std::vector<DynamicsProcessing::ChannelConfig> cfgs(mChannelCount);
781 for (int i = 0; i < mChannelCount; i++) {
782 cfgs[i].channel = i;
783 cfgs[i].enable = true;
784 }
785 EXPECT_NO_FATAL_FAILURE(addPreEqChannelConfig(cfgs));
Ram Mohane4064ce2022-12-20 18:05:14 +0530786 EXPECT_NO_FATAL_FAILURE(addPreEqBandConfigs(mCfgs));
787 SetAndGetDynamicsProcessingParameters();
788}
789
790TEST_P(DynamicsProcessingTestEqBandConfig, SetAndGetPostEqBandConfig) {
791 mEngineConfigPreset.postEqStage.inUse = mStageInUse;
792 mEngineConfigPreset.postEqStage.bandCount = mCfgs.size();
793 EXPECT_NO_FATAL_FAILURE(addEngineConfig(mEngineConfigPreset));
Ram Mohanafdf90b2023-03-23 08:48:25 +0530794 std::vector<DynamicsProcessing::ChannelConfig> cfgs(mChannelCount);
795 for (int i = 0; i < mChannelCount; i++) {
796 cfgs[i].channel = i;
797 cfgs[i].enable = true;
798 }
799 EXPECT_NO_FATAL_FAILURE(addPostEqChannelConfig(cfgs));
Ram Mohane4064ce2022-12-20 18:05:14 +0530800 EXPECT_NO_FATAL_FAILURE(addPostEqBandConfigs(mCfgs));
801 SetAndGetDynamicsProcessingParameters();
802}
803
804std::vector<std::vector<std::pair<int, float>>> kBands{
805 {
806 {0, 600},
807 {1, 2000},
808 {2, 6000},
809 {3, 10000},
810 {4, 16000},
811 }, // 5 bands
812 {
813 {0, 800},
814 {3, 15000},
815 {2, 6000},
816 {1, 2000},
817 }, // 4 bands, unsorted
818 {
819 {0, 650},
820 {1, 2000},
821 {2, 6000},
822 {3, 10000},
823 {3, 16000},
824 }, // 5 bands, missing band
825 {
826 {0, 900},
827 {1, 8000},
828 {2, 4000},
829 {3, 12000},
830 }, // 4 bands, cutoff freq not increasing
831 {
832 {0, 450},
833 {1, 2000},
834 {7, 6000},
835 {3, 10000},
836 {4, 16000},
837 }, // bad band index
838 {
839 {0, 1},
840 {1, 8000},
841 }, // too low cutoff freq
842 {
843 {0, 1200},
844 {1, 80000},
845 }, // too high cutoff freq
846};
847
848INSTANTIATE_TEST_SUITE_P(
849 DynamicsProcessingTest, DynamicsProcessingTestEqBandConfig,
Ram Mohanafdf90b2023-03-23 08:48:25 +0530850 ::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
851 IFactory::descriptor, getEffectTypeUuidDynamicsProcessing())),
852 testing::Values(-1, 0, 10), // channel ID
853 testing::Bool(), // band enable
854 testing::ValuesIn(kBands), // cut off frequencies
855 testing::Values(-3.14f, 3.14f), // gain
856 testing::Values(true)), // stage in use
Ram Mohane4064ce2022-12-20 18:05:14 +0530857 [](const auto& info) {
858 auto descriptor = std::get<EQ_BAND_INSTANCE_NAME>(info.param).second;
859 std::vector<DynamicsProcessing::EqBandConfig> cfgs;
860 fillEqBandConfig(cfgs, info.param);
Ram Mohane4064ce2022-12-20 18:05:14 +0530861 std::string bands = ::android::internal::ToString(cfgs);
862 std::string stageInUse = std::to_string(std::get<EQ_BAND_STAGE_IN_USE>(info.param));
863 std::string name = "Implementor_" + descriptor.common.implementor + "_name_" +
864 descriptor.common.name + "_UUID_" +
Shunkai Yaofb8f3942024-03-29 18:45:30 +0000865 toString(descriptor.common.id.uuid) + "_bands_" + bands +
Ram Mohanafdf90b2023-03-23 08:48:25 +0530866 "_stageInUse_" + stageInUse;
Ram Mohane4064ce2022-12-20 18:05:14 +0530867 std::replace_if(
868 name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
869 return name;
870 });
871GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(DynamicsProcessingTestEqBandConfig);
872
873/**
874 * Test DynamicsProcessing MbcBandConfig
875 */
876
877enum MbcBandConfigParamName {
878 MBC_BAND_INSTANCE_NAME,
879 MBC_BAND_CHANNEL,
Ram Mohane4064ce2022-12-20 18:05:14 +0530880 MBC_BAND_ENABLE,
881 MBC_BAND_CUTOFF_FREQ,
882 MBC_BAND_STAGE_IN_USE,
883 MBC_BAND_ADDITIONAL
884};
885enum MbcBandConfigAdditional {
886 MBC_ADD_ATTACK_TIME,
887 MBC_ADD_RELEASE_TIME,
888 MBC_ADD_RATIO,
889 MBC_ADD_THRESHOLD,
890 MBC_ADD_KNEE_WIDTH,
891 MBC_ADD_NOISE_GATE_THRESHOLD,
892 MBC_ADD_EXPENDER_RATIO,
893 MBC_ADD_PRE_GAIN,
894 MBC_ADD_POST_GAIN,
895 MBC_ADD_MAX_NUM
896};
897using TestParamsMbcBandConfigAdditional = std::array<float, MBC_ADD_MAX_NUM>;
898
Ram Mohanafdf90b2023-03-23 08:48:25 +0530899// attackTime, releaseTime, ratio, thresh, kneeWidth, noise, expander, preGain, postGain
Ram Mohane4064ce2022-12-20 18:05:14 +0530900static constexpr std::array<TestParamsMbcBandConfigAdditional, 4> kMbcBandConfigAdditionalParam = {
901 {{-3, -10, -2, -2, -5, -90, -2.5, -2, -2},
902 {0, 0, 0, 0, 0, 0, 0, 0, 0},
903 {-3, 10, -2, 2, -5, 90, -2.5, 2, -2},
Ram Mohanafdf90b2023-03-23 08:48:25 +0530904 {3, 10, 2, -2, -5, 90, 2.5, 2, 2}}};
Ram Mohane4064ce2022-12-20 18:05:14 +0530905
906using TestParamsMbcBandConfig =
Ram Mohanafdf90b2023-03-23 08:48:25 +0530907 std::tuple<std::pair<std::shared_ptr<IFactory>, Descriptor>, int32_t, bool,
Ram Mohane4064ce2022-12-20 18:05:14 +0530908 std::vector<std::pair<int, float>>, bool, TestParamsMbcBandConfigAdditional>;
909
910void fillMbcBandConfig(std::vector<DynamicsProcessing::MbcBandConfig>& cfgs,
911 const TestParamsMbcBandConfig& params) {
912 const std::vector<std::pair<int, float>> cutOffFreqs = std::get<MBC_BAND_CUTOFF_FREQ>(params);
913 const std::array<float, MBC_ADD_MAX_NUM> additional = std::get<MBC_BAND_ADDITIONAL>(params);
914 int bandCount = cutOffFreqs.size();
915 cfgs.resize(bandCount);
916 for (int i = 0; i < bandCount; i++) {
917 cfgs[i] = DynamicsProcessing::MbcBandConfig{
918 .channel = std::get<MBC_BAND_CHANNEL>(params),
919 .band = cutOffFreqs[i].first,
920 .enable = std::get<MBC_BAND_ENABLE>(params),
921 .cutoffFrequencyHz = cutOffFreqs[i].second,
922 .attackTimeMs = additional[MBC_ADD_ATTACK_TIME],
923 .releaseTimeMs = additional[MBC_ADD_RELEASE_TIME],
924 .ratio = additional[MBC_ADD_RATIO],
925 .thresholdDb = additional[MBC_ADD_THRESHOLD],
926 .kneeWidthDb = additional[MBC_ADD_KNEE_WIDTH],
927 .noiseGateThresholdDb = additional[MBC_ADD_NOISE_GATE_THRESHOLD],
928 .expanderRatio = additional[MBC_ADD_EXPENDER_RATIO],
929 .preGainDb = additional[MBC_ADD_PRE_GAIN],
930 .postGainDb = additional[MBC_ADD_POST_GAIN]};
931 }
932}
933
934class DynamicsProcessingTestMbcBandConfig
935 : public ::testing::TestWithParam<TestParamsMbcBandConfig>,
936 public DynamicsProcessingTestHelper {
937 public:
938 DynamicsProcessingTestMbcBandConfig()
939 : DynamicsProcessingTestHelper(std::get<MBC_BAND_INSTANCE_NAME>(GetParam())),
Ram Mohanafdf90b2023-03-23 08:48:25 +0530940 mStageInUse(std::get<MBC_BAND_STAGE_IN_USE>(GetParam())) {
Ram Mohane4064ce2022-12-20 18:05:14 +0530941 fillMbcBandConfig(mCfgs, GetParam());
942 }
943
944 void SetUp() override { SetUpDynamicsProcessingEffect(); }
945
946 void TearDown() override { TearDownDynamicsProcessingEffect(); }
947
948 std::vector<DynamicsProcessing::MbcBandConfig> mCfgs;
949 const bool mStageInUse;
Ram Mohane4064ce2022-12-20 18:05:14 +0530950};
951
952TEST_P(DynamicsProcessingTestMbcBandConfig, SetAndGetMbcBandConfig) {
953 mEngineConfigPreset.mbcStage.inUse = mStageInUse;
954 mEngineConfigPreset.mbcStage.bandCount = mCfgs.size();
955 EXPECT_NO_FATAL_FAILURE(addEngineConfig(mEngineConfigPreset));
Ram Mohanafdf90b2023-03-23 08:48:25 +0530956 std::vector<DynamicsProcessing::ChannelConfig> cfgs(mChannelCount);
957 for (int i = 0; i < mChannelCount; i++) {
958 cfgs[i].channel = i;
959 cfgs[i].enable = true;
960 }
961 EXPECT_NO_FATAL_FAILURE(addMbcChannelConfig(cfgs));
Ram Mohane4064ce2022-12-20 18:05:14 +0530962 EXPECT_NO_FATAL_FAILURE(addMbcBandConfigs(mCfgs));
963 SetAndGetDynamicsProcessingParameters();
964}
965
966INSTANTIATE_TEST_SUITE_P(
967 DynamicsProcessingTest, DynamicsProcessingTestMbcBandConfig,
Ram Mohanafdf90b2023-03-23 08:48:25 +0530968 ::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
969 IFactory::descriptor, getEffectTypeUuidDynamicsProcessing())),
970 testing::Values(-1, 0, 10), // channel count
971 testing::Bool(), // enable
972 testing::ValuesIn(kBands), // cut off frequencies
973 testing::Bool(), // stage in use
974 testing::ValuesIn(kMbcBandConfigAdditionalParam)), // Additional
Ram Mohane4064ce2022-12-20 18:05:14 +0530975 [](const auto& info) {
976 auto descriptor = std::get<MBC_BAND_INSTANCE_NAME>(info.param).second;
977 std::vector<DynamicsProcessing::MbcBandConfig> cfgs;
978 fillMbcBandConfig(cfgs, info.param);
Ram Mohane4064ce2022-12-20 18:05:14 +0530979 std::string mbcBands = ::android::internal::ToString(cfgs);
980 std::string stageInUse = std::to_string(std::get<MBC_BAND_STAGE_IN_USE>(info.param));
981 std::string name = "Implementor_" + descriptor.common.implementor + "_name_" +
982 descriptor.common.name + "_UUID_" +
Shunkai Yaofb8f3942024-03-29 18:45:30 +0000983 toString(descriptor.common.id.uuid) + "_bands_" + mbcBands +
Ram Mohanafdf90b2023-03-23 08:48:25 +0530984 "_stageInUse_" + stageInUse;
Ram Mohane4064ce2022-12-20 18:05:14 +0530985 std::replace_if(
986 name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_');
987 return name;
988 });
989GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(DynamicsProcessingTestMbcBandConfig);
990
991int main(int argc, char** argv) {
992 ::testing::InitGoogleTest(&argc, argv);
Jaideep Sharma74498412023-09-13 15:25:25 +0530993 ::testing::UnitTest::GetInstance()->listeners().Append(new TestExecutionTracer());
Ram Mohane4064ce2022-12-20 18:05:14 +0530994 ABinderProcess_setThreadPoolMaxThreadCount(1);
995 ABinderProcess_startThreadPool();
996 return RUN_ALL_TESTS();
997}