/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.hardware.audio.effect@6.0;

import android.hardware.audio.common@6.0;
import IEffect;

interface IEnvironmentalReverbEffect extends IEffect {
    /**
     * Sets whether the effect should be bypassed.
     */
    setBypass(bool bypass) generates (Result retval);

    /**
     * Gets whether the effect should be bypassed.
     */
    getBypass() generates (Result retval, bool bypass);

    enum ParamRange : int16_t {
        ROOM_LEVEL_MIN = -6000,
        ROOM_LEVEL_MAX = 0,
        ROOM_HF_LEVEL_MIN = -4000,
        ROOM_HF_LEVEL_MAX = 0,
        DECAY_TIME_MIN = 100,
        DECAY_TIME_MAX = 20000,
        DECAY_HF_RATIO_MIN = 100,
        DECAY_HF_RATIO_MAX = 1000,
        REFLECTIONS_LEVEL_MIN = -6000,
        REFLECTIONS_LEVEL_MAX = 0,
        REFLECTIONS_DELAY_MIN = 0,
        REFLECTIONS_DELAY_MAX = 65,
        REVERB_LEVEL_MIN = -6000,
        REVERB_LEVEL_MAX = 0,
        REVERB_DELAY_MIN = 0,
        REVERB_DELAY_MAX = 65,
        DIFFUSION_MIN = 0,
        DIFFUSION_MAX = 1000,
        DENSITY_MIN = 0,
        DENSITY_MAX = 1000
    };

    /**
     * Sets the room level.
     */
    setRoomLevel(int16_t roomLevel) generates (Result retval);

    /**
     * Gets the room level.
     */
    getRoomLevel() generates (Result retval, int16_t roomLevel);

    /**
     * Sets the room high frequencies level.
     */
    setRoomHfLevel(int16_t roomHfLevel) generates (Result retval);

    /**
     * Gets the room high frequencies level.
     */
    getRoomHfLevel() generates (Result retval, int16_t roomHfLevel);

    /**
     * Sets the room decay time.
     */
    setDecayTime(uint32_t decayTime) generates (Result retval);

    /**
     * Gets the room decay time.
     */
    getDecayTime() generates (Result retval, uint32_t decayTime);

    /**
     * Sets the ratio of high frequencies decay.
     */
    setDecayHfRatio(int16_t decayHfRatio) generates (Result retval);

    /**
     * Gets the ratio of high frequencies decay.
     */
    getDecayHfRatio() generates (Result retval, int16_t decayHfRatio);

    /**
     * Sets the level of reflections in the room.
     */
    setReflectionsLevel(int16_t reflectionsLevel) generates (Result retval);

    /**
     * Gets the level of reflections in the room.
     */
    getReflectionsLevel() generates (Result retval, int16_t reflectionsLevel);

    /**
     * Sets the reflections delay in the room.
     */
    setReflectionsDelay(uint32_t reflectionsDelay) generates (Result retval);

    /**
     * Gets the reflections delay in the room.
     */
    getReflectionsDelay() generates (Result retval, uint32_t reflectionsDelay);

    /**
     * Sets the reverb level of the room.
     */
    setReverbLevel(int16_t reverbLevel) generates (Result retval);

    /**
     * Gets the reverb level of the room.
     */
    getReverbLevel() generates (Result retval, int16_t reverbLevel);

    /**
     * Sets the reverb delay of the room.
     */
    setReverbDelay(uint32_t reverDelay) generates (Result retval);

    /**
     * Gets the reverb delay of the room.
     */
    getReverbDelay() generates (Result retval, uint32_t reverbDelay);

    /**
     * Sets room diffusion.
     */
    setDiffusion(int16_t diffusion) generates (Result retval);

    /**
     * Gets room diffusion.
     */
    getDiffusion() generates (Result retval, int16_t diffusion);

    /**
     * Sets room wall density.
     */
    setDensity(int16_t density) generates (Result retval);

    /**
     * Gets room wall density.
     */
    getDensity() generates (Result retval, int16_t density);

    struct AllProperties {
        int16_t  roomLevel;         // in millibels,    range -6000 to 0
        int16_t  roomHfLevel;       // in millibels,    range -4000 to 0
        uint32_t decayTime;         // in milliseconds, range 100 to 20000
        int16_t  decayHfRatio;      // in permilles,    range 100 to 1000
        int16_t  reflectionsLevel;  // in millibels,    range -6000 to 0
        uint32_t reflectionsDelay;  // in milliseconds, range 0 to 65
        int16_t  reverbLevel;       // in millibels,    range -6000 to 0
        uint32_t reverbDelay;       // in milliseconds, range 0 to 65
        int16_t  diffusion;         // in permilles,    range 0 to 1000
        int16_t  density;           // in permilles,    range 0 to 1000
    };

    /**
     * Sets all properties at once.
     */
    setAllProperties(AllProperties properties) generates (Result retval);

    /**
     * Gets all properties at once.
     */
    getAllProperties() generates (Result retval, AllProperties properties);
};
