1 /*
2  * Copyright (C) 2018 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 #define LOG_TAG "EnvReverb_HAL"
18 #include <android/log.h>
19 
20 #include "EnvironmentalReverbEffect.h"
21 
22 #include <android/log.h>
23 
24 #include "VersionUtils.h"
25 
26 namespace android {
27 namespace hardware {
28 namespace audio {
29 namespace effect {
30 namespace CPP_VERSION {
31 namespace implementation {
32 
EnvironmentalReverbEffect(effect_handle_t handle)33 EnvironmentalReverbEffect::EnvironmentalReverbEffect(effect_handle_t handle)
34     : mEffect(new Effect(handle)) {}
35 
~EnvironmentalReverbEffect()36 EnvironmentalReverbEffect::~EnvironmentalReverbEffect() {}
37 
propertiesFromHal(const t_reverb_settings & halProperties,IEnvironmentalReverbEffect::AllProperties * properties)38 void EnvironmentalReverbEffect::propertiesFromHal(
39     const t_reverb_settings& halProperties, IEnvironmentalReverbEffect::AllProperties* properties) {
40     properties->roomLevel = halProperties.roomLevel;
41     properties->roomHfLevel = halProperties.roomHFLevel;
42     properties->decayTime = halProperties.decayTime;
43     properties->decayHfRatio = halProperties.decayHFRatio;
44     properties->reflectionsLevel = halProperties.reflectionsLevel;
45     properties->reflectionsDelay = halProperties.reflectionsDelay;
46     properties->reverbLevel = halProperties.reverbLevel;
47     properties->reverbDelay = halProperties.reverbDelay;
48     properties->diffusion = halProperties.diffusion;
49     properties->density = halProperties.density;
50 }
51 
propertiesToHal(const IEnvironmentalReverbEffect::AllProperties & properties,t_reverb_settings * halProperties)52 void EnvironmentalReverbEffect::propertiesToHal(
53     const IEnvironmentalReverbEffect::AllProperties& properties, t_reverb_settings* halProperties) {
54     halProperties->roomLevel = properties.roomLevel;
55     halProperties->roomHFLevel = properties.roomHfLevel;
56     halProperties->decayTime = properties.decayTime;
57     halProperties->decayHFRatio = properties.decayHfRatio;
58     halProperties->reflectionsLevel = properties.reflectionsLevel;
59     halProperties->reflectionsDelay = properties.reflectionsDelay;
60     halProperties->reverbLevel = properties.reverbLevel;
61     halProperties->reverbDelay = properties.reverbDelay;
62     halProperties->diffusion = properties.diffusion;
63     halProperties->density = properties.density;
64 }
65 
66 // Methods from ::android::hardware::audio::effect::CPP_VERSION::IEffect follow.
init()67 Return<Result> EnvironmentalReverbEffect::init() {
68     return mEffect->init();
69 }
70 
setConfig(const EffectConfig & config,const sp<IEffectBufferProviderCallback> & inputBufferProvider,const sp<IEffectBufferProviderCallback> & outputBufferProvider)71 Return<Result> EnvironmentalReverbEffect::setConfig(
72     const EffectConfig& config, const sp<IEffectBufferProviderCallback>& inputBufferProvider,
73     const sp<IEffectBufferProviderCallback>& outputBufferProvider) {
74     return mEffect->setConfig(config, inputBufferProvider, outputBufferProvider);
75 }
76 
reset()77 Return<Result> EnvironmentalReverbEffect::reset() {
78     return mEffect->reset();
79 }
80 
enable()81 Return<Result> EnvironmentalReverbEffect::enable() {
82     return mEffect->enable();
83 }
84 
disable()85 Return<Result> EnvironmentalReverbEffect::disable() {
86     return mEffect->disable();
87 }
88 
setDevice(AudioDeviceBitfield device)89 Return<Result> EnvironmentalReverbEffect::setDevice(AudioDeviceBitfield device) {
90     return mEffect->setDevice(device);
91 }
92 
setAndGetVolume(const hidl_vec<uint32_t> & volumes,setAndGetVolume_cb _hidl_cb)93 Return<void> EnvironmentalReverbEffect::setAndGetVolume(const hidl_vec<uint32_t>& volumes,
94                                                         setAndGetVolume_cb _hidl_cb) {
95     return mEffect->setAndGetVolume(volumes, _hidl_cb);
96 }
97 
volumeChangeNotification(const hidl_vec<uint32_t> & volumes)98 Return<Result> EnvironmentalReverbEffect::volumeChangeNotification(
99     const hidl_vec<uint32_t>& volumes) {
100     return mEffect->volumeChangeNotification(volumes);
101 }
102 
setAudioMode(AudioMode mode)103 Return<Result> EnvironmentalReverbEffect::setAudioMode(AudioMode mode) {
104     return mEffect->setAudioMode(mode);
105 }
106 
setConfigReverse(const EffectConfig & config,const sp<IEffectBufferProviderCallback> & inputBufferProvider,const sp<IEffectBufferProviderCallback> & outputBufferProvider)107 Return<Result> EnvironmentalReverbEffect::setConfigReverse(
108     const EffectConfig& config, const sp<IEffectBufferProviderCallback>& inputBufferProvider,
109     const sp<IEffectBufferProviderCallback>& outputBufferProvider) {
110     return mEffect->setConfigReverse(config, inputBufferProvider, outputBufferProvider);
111 }
112 
setInputDevice(AudioDeviceBitfield device)113 Return<Result> EnvironmentalReverbEffect::setInputDevice(AudioDeviceBitfield device) {
114     return mEffect->setInputDevice(device);
115 }
116 
getConfig(getConfig_cb _hidl_cb)117 Return<void> EnvironmentalReverbEffect::getConfig(getConfig_cb _hidl_cb) {
118     return mEffect->getConfig(_hidl_cb);
119 }
120 
getConfigReverse(getConfigReverse_cb _hidl_cb)121 Return<void> EnvironmentalReverbEffect::getConfigReverse(getConfigReverse_cb _hidl_cb) {
122     return mEffect->getConfigReverse(_hidl_cb);
123 }
124 
getSupportedAuxChannelsConfigs(uint32_t maxConfigs,getSupportedAuxChannelsConfigs_cb _hidl_cb)125 Return<void> EnvironmentalReverbEffect::getSupportedAuxChannelsConfigs(
126     uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) {
127     return mEffect->getSupportedAuxChannelsConfigs(maxConfigs, _hidl_cb);
128 }
129 
getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb)130 Return<void> EnvironmentalReverbEffect::getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) {
131     return mEffect->getAuxChannelsConfig(_hidl_cb);
132 }
133 
setAuxChannelsConfig(const EffectAuxChannelsConfig & config)134 Return<Result> EnvironmentalReverbEffect::setAuxChannelsConfig(
135     const EffectAuxChannelsConfig& config) {
136     return mEffect->setAuxChannelsConfig(config);
137 }
138 
setAudioSource(AudioSource source)139 Return<Result> EnvironmentalReverbEffect::setAudioSource(AudioSource source) {
140     return mEffect->setAudioSource(source);
141 }
142 
offload(const EffectOffloadParameter & param)143 Return<Result> EnvironmentalReverbEffect::offload(const EffectOffloadParameter& param) {
144     return mEffect->offload(param);
145 }
146 
getDescriptor(getDescriptor_cb _hidl_cb)147 Return<void> EnvironmentalReverbEffect::getDescriptor(getDescriptor_cb _hidl_cb) {
148     return mEffect->getDescriptor(_hidl_cb);
149 }
150 
prepareForProcessing(prepareForProcessing_cb _hidl_cb)151 Return<void> EnvironmentalReverbEffect::prepareForProcessing(prepareForProcessing_cb _hidl_cb) {
152     return mEffect->prepareForProcessing(_hidl_cb);
153 }
154 
setProcessBuffers(const AudioBuffer & inBuffer,const AudioBuffer & outBuffer)155 Return<Result> EnvironmentalReverbEffect::setProcessBuffers(const AudioBuffer& inBuffer,
156                                                             const AudioBuffer& outBuffer) {
157     return mEffect->setProcessBuffers(inBuffer, outBuffer);
158 }
159 
command(uint32_t commandId,const hidl_vec<uint8_t> & data,uint32_t resultMaxSize,command_cb _hidl_cb)160 Return<void> EnvironmentalReverbEffect::command(uint32_t commandId, const hidl_vec<uint8_t>& data,
161                                                 uint32_t resultMaxSize, command_cb _hidl_cb) {
162     return mEffect->command(commandId, data, resultMaxSize, _hidl_cb);
163 }
164 
setParameter(const hidl_vec<uint8_t> & parameter,const hidl_vec<uint8_t> & value)165 Return<Result> EnvironmentalReverbEffect::setParameter(const hidl_vec<uint8_t>& parameter,
166                                                        const hidl_vec<uint8_t>& value) {
167     return mEffect->setParameter(parameter, value);
168 }
169 
getParameter(const hidl_vec<uint8_t> & parameter,uint32_t valueMaxSize,getParameter_cb _hidl_cb)170 Return<void> EnvironmentalReverbEffect::getParameter(const hidl_vec<uint8_t>& parameter,
171                                                      uint32_t valueMaxSize,
172                                                      getParameter_cb _hidl_cb) {
173     return mEffect->getParameter(parameter, valueMaxSize, _hidl_cb);
174 }
175 
getSupportedConfigsForFeature(uint32_t featureId,uint32_t maxConfigs,uint32_t configSize,getSupportedConfigsForFeature_cb _hidl_cb)176 Return<void> EnvironmentalReverbEffect::getSupportedConfigsForFeature(
177     uint32_t featureId, uint32_t maxConfigs, uint32_t configSize,
178     getSupportedConfigsForFeature_cb _hidl_cb) {
179     return mEffect->getSupportedConfigsForFeature(featureId, maxConfigs, configSize, _hidl_cb);
180 }
181 
getCurrentConfigForFeature(uint32_t featureId,uint32_t configSize,getCurrentConfigForFeature_cb _hidl_cb)182 Return<void> EnvironmentalReverbEffect::getCurrentConfigForFeature(
183     uint32_t featureId, uint32_t configSize, getCurrentConfigForFeature_cb _hidl_cb) {
184     return mEffect->getCurrentConfigForFeature(featureId, configSize, _hidl_cb);
185 }
186 
setCurrentConfigForFeature(uint32_t featureId,const hidl_vec<uint8_t> & configData)187 Return<Result> EnvironmentalReverbEffect::setCurrentConfigForFeature(
188     uint32_t featureId, const hidl_vec<uint8_t>& configData) {
189     return mEffect->setCurrentConfigForFeature(featureId, configData);
190 }
191 
close()192 Return<Result> EnvironmentalReverbEffect::close() {
193     return mEffect->close();
194 }
195 
debug(const hidl_handle & fd,const hidl_vec<hidl_string> & options)196 Return<void> EnvironmentalReverbEffect::debug(const hidl_handle& fd,
197                                               const hidl_vec<hidl_string>& options) {
198     return mEffect->debug(fd, options);
199 }
200 
201 // Methods from ::android::hardware::audio::effect::CPP_VERSION::IEnvironmentalReverbEffect
202 // follow.
setBypass(bool bypass)203 Return<Result> EnvironmentalReverbEffect::setBypass(bool bypass) {
204     return mEffect->setParam(REVERB_PARAM_BYPASS, bypass);
205 }
206 
getBypass(getBypass_cb _hidl_cb)207 Return<void> EnvironmentalReverbEffect::getBypass(getBypass_cb _hidl_cb) {
208     return mEffect->getIntegerParam(REVERB_PARAM_BYPASS, _hidl_cb);
209 }
210 
setRoomLevel(int16_t roomLevel)211 Return<Result> EnvironmentalReverbEffect::setRoomLevel(int16_t roomLevel) {
212     return mEffect->setParam(REVERB_PARAM_ROOM_LEVEL, roomLevel);
213 }
214 
getRoomLevel(getRoomLevel_cb _hidl_cb)215 Return<void> EnvironmentalReverbEffect::getRoomLevel(getRoomLevel_cb _hidl_cb) {
216     return mEffect->getIntegerParam(REVERB_PARAM_ROOM_LEVEL, _hidl_cb);
217 }
218 
setRoomHfLevel(int16_t roomHfLevel)219 Return<Result> EnvironmentalReverbEffect::setRoomHfLevel(int16_t roomHfLevel) {
220     return mEffect->setParam(REVERB_PARAM_ROOM_HF_LEVEL, roomHfLevel);
221 }
222 
getRoomHfLevel(getRoomHfLevel_cb _hidl_cb)223 Return<void> EnvironmentalReverbEffect::getRoomHfLevel(getRoomHfLevel_cb _hidl_cb) {
224     return mEffect->getIntegerParam(REVERB_PARAM_ROOM_HF_LEVEL, _hidl_cb);
225 }
226 
setDecayTime(uint32_t decayTime)227 Return<Result> EnvironmentalReverbEffect::setDecayTime(uint32_t decayTime) {
228     return mEffect->setParam(REVERB_PARAM_DECAY_TIME, decayTime);
229 }
230 
getDecayTime(getDecayTime_cb _hidl_cb)231 Return<void> EnvironmentalReverbEffect::getDecayTime(getDecayTime_cb _hidl_cb) {
232     return mEffect->getIntegerParam(REVERB_PARAM_DECAY_TIME, _hidl_cb);
233 }
234 
setDecayHfRatio(int16_t decayHfRatio)235 Return<Result> EnvironmentalReverbEffect::setDecayHfRatio(int16_t decayHfRatio) {
236     return mEffect->setParam(REVERB_PARAM_DECAY_HF_RATIO, decayHfRatio);
237 }
238 
getDecayHfRatio(getDecayHfRatio_cb _hidl_cb)239 Return<void> EnvironmentalReverbEffect::getDecayHfRatio(getDecayHfRatio_cb _hidl_cb) {
240     return mEffect->getIntegerParam(REVERB_PARAM_DECAY_HF_RATIO, _hidl_cb);
241 }
242 
setReflectionsLevel(int16_t reflectionsLevel)243 Return<Result> EnvironmentalReverbEffect::setReflectionsLevel(int16_t reflectionsLevel) {
244     return mEffect->setParam(REVERB_PARAM_REFLECTIONS_LEVEL, reflectionsLevel);
245 }
246 
getReflectionsLevel(getReflectionsLevel_cb _hidl_cb)247 Return<void> EnvironmentalReverbEffect::getReflectionsLevel(getReflectionsLevel_cb _hidl_cb) {
248     return mEffect->getIntegerParam(REVERB_PARAM_REFLECTIONS_LEVEL, _hidl_cb);
249 }
250 
setReflectionsDelay(uint32_t reflectionsDelay)251 Return<Result> EnvironmentalReverbEffect::setReflectionsDelay(uint32_t reflectionsDelay) {
252     return mEffect->setParam(REVERB_PARAM_REFLECTIONS_DELAY, reflectionsDelay);
253 }
254 
getReflectionsDelay(getReflectionsDelay_cb _hidl_cb)255 Return<void> EnvironmentalReverbEffect::getReflectionsDelay(getReflectionsDelay_cb _hidl_cb) {
256     return mEffect->getIntegerParam(REVERB_PARAM_REFLECTIONS_DELAY, _hidl_cb);
257 }
258 
setReverbLevel(int16_t reverbLevel)259 Return<Result> EnvironmentalReverbEffect::setReverbLevel(int16_t reverbLevel) {
260     return mEffect->setParam(REVERB_PARAM_REVERB_LEVEL, reverbLevel);
261 }
262 
getReverbLevel(getReverbLevel_cb _hidl_cb)263 Return<void> EnvironmentalReverbEffect::getReverbLevel(getReverbLevel_cb _hidl_cb) {
264     return mEffect->getIntegerParam(REVERB_PARAM_REVERB_LEVEL, _hidl_cb);
265 }
266 
setReverbDelay(uint32_t reverbDelay)267 Return<Result> EnvironmentalReverbEffect::setReverbDelay(uint32_t reverbDelay) {
268     return mEffect->setParam(REVERB_PARAM_REVERB_DELAY, reverbDelay);
269 }
270 
getReverbDelay(getReverbDelay_cb _hidl_cb)271 Return<void> EnvironmentalReverbEffect::getReverbDelay(getReverbDelay_cb _hidl_cb) {
272     return mEffect->getIntegerParam(REVERB_PARAM_REVERB_DELAY, _hidl_cb);
273 }
274 
setDiffusion(int16_t diffusion)275 Return<Result> EnvironmentalReverbEffect::setDiffusion(int16_t diffusion) {
276     return mEffect->setParam(REVERB_PARAM_DIFFUSION, diffusion);
277 }
278 
getDiffusion(getDiffusion_cb _hidl_cb)279 Return<void> EnvironmentalReverbEffect::getDiffusion(getDiffusion_cb _hidl_cb) {
280     return mEffect->getIntegerParam(REVERB_PARAM_DIFFUSION, _hidl_cb);
281 }
282 
setDensity(int16_t density)283 Return<Result> EnvironmentalReverbEffect::setDensity(int16_t density) {
284     return mEffect->setParam(REVERB_PARAM_DENSITY, density);
285 }
286 
getDensity(getDensity_cb _hidl_cb)287 Return<void> EnvironmentalReverbEffect::getDensity(getDensity_cb _hidl_cb) {
288     return mEffect->getIntegerParam(REVERB_PARAM_DENSITY, _hidl_cb);
289 }
290 
setAllProperties(const IEnvironmentalReverbEffect::AllProperties & properties)291 Return<Result> EnvironmentalReverbEffect::setAllProperties(
292     const IEnvironmentalReverbEffect::AllProperties& properties) {
293     t_reverb_settings halProperties;
294     propertiesToHal(properties, &halProperties);
295     return mEffect->setParam(REVERB_PARAM_PROPERTIES, halProperties);
296 }
297 
getAllProperties(getAllProperties_cb _hidl_cb)298 Return<void> EnvironmentalReverbEffect::getAllProperties(getAllProperties_cb _hidl_cb) {
299     t_reverb_settings halProperties;
300     Result retval = mEffect->getParam(REVERB_PARAM_PROPERTIES, halProperties);
301     AllProperties properties;
302     propertiesFromHal(halProperties, &properties);
303     _hidl_cb(retval, properties);
304     return Void();
305 }
306 
307 }  // namespace implementation
308 }  // namespace CPP_VERSION
309 }  // namespace effect
310 }  // namespace audio
311 }  // namespace hardware
312 }  // namespace android
313