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