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 "effect-impl/EffectContext.h" 20 21 #include <audio_utils/ChannelMix.h> 22 23 namespace aidl::android::hardware::audio::effect { 24 25 enum DownmixState { 26 DOWNMIX_STATE_UNINITIALIZED, 27 DOWNMIX_STATE_INITIALIZED, 28 DOWNMIX_STATE_ACTIVE, 29 }; 30 31 class DownmixContext final : public EffectContext { 32 public: 33 DownmixContext(int statusDepth, const Parameter::Common& common); 34 ~DownmixContext(); 35 RetCode enable() override; 36 RetCode disable() override; 37 setDmType(Downmix::Type type)38 RetCode setDmType(Downmix::Type type) { 39 mType = type; 40 return RetCode::SUCCESS; 41 } getDmType()42 Downmix::Type getDmType() const { return mType; } 43 setOutputDevice(const std::vector<::aidl::android::media::audio::common::AudioDeviceDescription> & device)44 RetCode setOutputDevice( 45 const std::vector<::aidl::android::media::audio::common::AudioDeviceDescription>& 46 device) override { 47 // FIXME change type if playing on headset vs speaker 48 mOutputDevice = device; 49 return RetCode::SUCCESS; 50 } 51 52 IEffect::Status downmixProcess(float* in, float* out, int samples); 53 54 static bool validateCommonConfig(const Parameter::Common& common); 55 56 private: 57 DownmixState mState; 58 Downmix::Type mType; 59 ::aidl::android::media::audio::common::AudioChannelLayout mChMask; 60 ::android::audio_utils::channels::ChannelMix<AUDIO_CHANNEL_OUT_STEREO> mChannelMix; 61 62 // Common Params 63 void init_params(const Parameter::Common& common); 64 }; 65 66 } // namespace aidl::android::hardware::audio::effect 67