/*
 * Copyright (C) 2020 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@7.0;

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

interface IVirtualizerEffect extends IEffect {
    /**
     * Returns whether setting virtualization strength is supported.
     */
    isStrengthSupported() generates (bool strengthSupported);

    enum StrengthRange : uint16_t {
        MIN = 0,
        MAX = 1000
    };

    /**
     * Sets virtualization strength.
     *
     * @param strength strength of the effect. The valid range for strength
     *                 strength is [0, 1000], where 0 per mille designates the
     *                 mildest effect and 1000 per mille designates the
     *                 strongest.
     * @return retval operation completion status.
     */
    setStrength(uint16_t strength) generates (Result retval);

    /**
     * Gets virtualization strength.
     */
    getStrength() generates (Result retval, uint16_t strength);

    struct SpeakerAngles {
        /** Speaker channel mask */
        AudioChannelMask mask;
        /**
         * Horizontal speaker position angles for each channel ordered from LSb
         * to MSb in the channel mask. The number of values is the number of
         * channels in the channel mask.
         *
         * All angles are expressed in degrees and are relative to the listener.
         *  - 0 is the direction the listener faces;
         *  - 180 is behind the listener;
         *  - -90 is to their left.
         */
        vec<int16_t> azimuth;
        /**
         * Vertical speaker position angles for each channel ordered from LSb
         * to MSb in the channel mask. The number of values is the number of
         * channels in the channel mask.
         *
         * All angles are expressed in degrees and are relative to the listener.
         *  - 0 is the horizontal plane of the listener;
         *  - +90 is above the listener;
         *  - -90 is below the listener.
         */
        vec<int16_t> elevation;
    };
    /**
     * Retrieves virtual speaker angles for the given channel mask on the
     * specified device.
     */
    getVirtualSpeakerAngles(AudioChannelMask mask, DeviceAddress device)
            generates (Result retval, SpeakerAngles speakerAngles);

    /**
     * Forces the virtualizer effect for the given output device.
     */
    forceVirtualizationMode(DeviceAddress device) generates (Result retval);

    /**
     * Returns audio device reflecting the current virtualization mode,
     * Device type can be empty when not virtualizing.
     */
    getVirtualizationMode() generates (Result retval, DeviceAddress device);
};
