blob: 819351a8484b6242d4af1a960c318b34435a9133 [file] [log] [blame]
Shunkai Yao6afc8552022-10-26 22:47:20 +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
Sham Rathod94aae5e2022-11-23 12:22:32 +053019#include <vector>
Shunkai Yao6afc8552022-10-26 22:47:20 +000020
Shunkai Yaof8be1ac2023-03-06 18:41:27 +000021#include <aidl/android/hardware/audio/effect/BnEffect.h>
Shunkai Yao13326772024-02-15 17:41:42 +000022#include <system/audio_effects/effect_visualizer.h>
Shunkai Yao6afc8552022-10-26 22:47:20 +000023#include "effect-impl/EffectImpl.h"
Shunkai Yao6afc8552022-10-26 22:47:20 +000024
25namespace aidl::android::hardware::audio::effect {
26
Shunkai Yao6755d762022-11-02 00:21:02 +000027class VisualizerSwContext final : public EffectContext {
Shunkai Yao6afc8552022-10-26 22:47:20 +000028 public:
Shunkai Yao13326772024-02-15 17:41:42 +000029 // need align the min/max capture size to VISUALIZER_CAPTURE_SIZE_MIN and
30 // VISUALIZER_CAPTURE_SIZE_MAX because of limitation in audio_utils fixedfft.
31 static constexpr int32_t kMinCaptureSize = VISUALIZER_CAPTURE_SIZE_MIN;
32 static constexpr int32_t kMaxCaptureSize = VISUALIZER_CAPTURE_SIZE_MAX;
33 static constexpr int32_t kMaxLatencyMs = 3000;
Shunkai Yao6afc8552022-10-26 22:47:20 +000034 VisualizerSwContext(int statusDepth, const Parameter::Common& common)
35 : EffectContext(statusDepth, common) {
36 LOG(DEBUG) << __func__;
Shunkai Yao13326772024-02-15 17:41:42 +000037 mCaptureSampleBuffer.resize(kMaxCaptureSize);
Shunkai Yaoe39cd362022-12-22 00:23:34 +000038 fill(mCaptureSampleBuffer.begin(), mCaptureSampleBuffer.end(), 0x80);
Shunkai Yao6afc8552022-10-26 22:47:20 +000039 }
Sham Rathod94aae5e2022-11-23 12:22:32 +053040
Sham Rathoddc7bcc82022-12-27 18:16:10 +053041 RetCode setVsCaptureSize(int captureSize);
Sham Rathod94aae5e2022-11-23 12:22:32 +053042 int getVsCaptureSize() const { return mCaptureSize; }
43
Sham Rathoddc7bcc82022-12-27 18:16:10 +053044 RetCode setVsScalingMode(Visualizer::ScalingMode scalingMode);
Sham Rathod94aae5e2022-11-23 12:22:32 +053045 Visualizer::ScalingMode getVsScalingMode() const { return mScalingMode; }
46
Sham Rathoddc7bcc82022-12-27 18:16:10 +053047 RetCode setVsMeasurementMode(Visualizer::MeasurementMode measurementMode);
Sham Rathod94aae5e2022-11-23 12:22:32 +053048 Visualizer::MeasurementMode getVsMeasurementMode() const { return mMeasurementMode; }
49
Sham Rathoddc7bcc82022-12-27 18:16:10 +053050 RetCode setVsLatency(int latency);
Shunkai Yao87811022023-02-13 17:40:37 +000051 int getVsLatency() const { return mLatency; }
Sham Rathod94aae5e2022-11-23 12:22:32 +053052
Shunkai Yao87811022023-02-13 17:40:37 +000053 Visualizer::Measurement getVsMeasurement() const { return mMeasurement; }
Shunkai Yaoe39cd362022-12-22 00:23:34 +000054 std::vector<uint8_t> getVsCaptureSampleBuffer() const { return mCaptureSampleBuffer; }
Sham Rathod94aae5e2022-11-23 12:22:32 +053055
56 private:
Shunkai Yaoe39cd362022-12-22 00:23:34 +000057 int mCaptureSize = kMaxCaptureSize;
Sham Rathod94aae5e2022-11-23 12:22:32 +053058 Visualizer::ScalingMode mScalingMode = Visualizer::ScalingMode::NORMALIZED;
59 Visualizer::MeasurementMode mMeasurementMode = Visualizer::MeasurementMode::NONE;
Sham Rathodd7c6f322022-12-26 11:17:10 +053060 int mLatency = 0;
Shunkai Yao87811022023-02-13 17:40:37 +000061 const Visualizer::Measurement mMeasurement = {0, 0};
Shunkai Yaoe39cd362022-12-22 00:23:34 +000062 std::vector<uint8_t> mCaptureSampleBuffer;
Shunkai Yao6afc8552022-10-26 22:47:20 +000063};
64
Shunkai Yao6755d762022-11-02 00:21:02 +000065class VisualizerSw final : public EffectImpl {
Shunkai Yao6afc8552022-10-26 22:47:20 +000066 public:
Shunkai Yaoc12e0822022-12-12 07:13:58 +000067 static const std::string kEffectName;
Shunkai Yao87811022023-02-13 17:40:37 +000068 static const Capability kCapability;
Shunkai Yaoc12e0822022-12-12 07:13:58 +000069 static const Descriptor kDescriptor;
Shunkai Yao6afc8552022-10-26 22:47:20 +000070 VisualizerSw() { LOG(DEBUG) << __func__; }
71 ~VisualizerSw() {
Shunkai Yao812d5b42022-11-16 18:08:50 +000072 cleanUp();
Shunkai Yao6afc8552022-10-26 22:47:20 +000073 LOG(DEBUG) << __func__;
Shunkai Yao6afc8552022-10-26 22:47:20 +000074 }
75
76 ndk::ScopedAStatus getDescriptor(Descriptor* _aidl_return) override;
Shunkai Yao65c7c702024-01-09 20:50:53 +000077 ndk::ScopedAStatus setParameterSpecific(const Parameter::Specific& specific)
78 REQUIRES(mImplMutex) override;
79 ndk::ScopedAStatus getParameterSpecific(const Parameter::Id& id, Parameter::Specific* specific)
80 REQUIRES(mImplMutex) override;
Shraddha Basantwanif627d802022-11-08 14:45:07 +053081
Shunkai Yao65c7c702024-01-09 20:50:53 +000082 std::shared_ptr<EffectContext> createContext(const Parameter::Common& common)
83 REQUIRES(mImplMutex) override;
84 RetCode releaseContext() REQUIRES(mImplMutex) override;
Shunkai Yao6afc8552022-10-26 22:47:20 +000085
Shunkai Yao65c7c702024-01-09 20:50:53 +000086 IEffect::Status effectProcessImpl(float* in, float* out, int samples)
87 REQUIRES(mImplMutex) override;
Shraddha Basantwanif627d802022-11-08 14:45:07 +053088 std::string getEffectName() override { return kEffectName; }
89
Shunkai Yao6afc8552022-10-26 22:47:20 +000090 private:
Shunkai Yao87811022023-02-13 17:40:37 +000091 static const std::vector<Range::VisualizerRange> kRanges;
Shunkai Yao65c7c702024-01-09 20:50:53 +000092 std::shared_ptr<VisualizerSwContext> mContext GUARDED_BY(mImplMutex);
Sham Rathod94aae5e2022-11-23 12:22:32 +053093 ndk::ScopedAStatus getParameterVisualizer(const Visualizer::Tag& tag,
Shunkai Yao65c7c702024-01-09 20:50:53 +000094 Parameter::Specific* specific) REQUIRES(mImplMutex);
Shunkai Yao6afc8552022-10-26 22:47:20 +000095};
96} // namespace aidl::android::hardware::audio::effect