/*
 * Copyright (C) 2023 Mohamad Al-Jaf
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

import "xapo.idl";

cpp_quote("#include <float.h>")

cpp_quote("#define HRTF_MAX_GAIN_LIMIT 12.0f")
cpp_quote("#define HRTF_MIN_GAIN_LIMIT -96.0f")
cpp_quote("#define HRTF_MIN_UNITY_GAIN_DISTANCE 0.05f")
cpp_quote("#define HRTF_DEFAULT_UNITY_GAIN_DISTANCE 1.0f")
cpp_quote("#define HRTF_DEFAULT_CUTOFF_DISTANCE FLT_MAX")

typedef struct HrtfPosition
{
    float x;
    float y;
    float z;
} HrtfPosition;

typedef struct HrtfOrientation
{
    float element[9];
} HrtfOrientation;

typedef enum HrtfDirectivityType
{
    OmniDirectional,
    Cardioid,
    Cone,
} HrtfDirectivityType;

typedef enum HrtfEnvironment
{
    Small,
    Medium,
    Large,
    Outdoors,
} HrtfEnvironment;

typedef struct HrtfDirectivity
{
    HrtfDirectivityType type;
    float scaling;
} HrtfDirectivity;

typedef struct HrtfDirectivityCardioid
{
    HrtfDirectivity directivity;
    float order;
} HrtfDirectivityCardioid;

typedef struct HrtfDirectivityCone
{
    HrtfDirectivity directivity;
    float innerAngle;
    float outerAngle;
} HrtfDirectivityCone;

typedef enum HrtfDistanceDecayType
{
    NaturalDecay,
    CustomDecay,
} HrtfDistanceDecayType;

typedef struct HrtfDistanceDecay
{
    HrtfDistanceDecayType type;
    float maxGain;
    float minGain;
    float unityGainDistance;
    float cutoffDistance;
} HrtfDistanceDecay;

typedef struct HrtfApoInit
{
    HrtfDistanceDecay *distanceDecay;
    HrtfDirectivity *directivity;
} HrtfApoInit;

HRESULT __stdcall CreateHrtfApo(const HrtfApoInit *init, IXAPO **xapo);

[
    object,
    uuid(15b3cd66-e9de-4464-b6e6-2bc3cf63d455)
]
interface IXAPOHrtfParameters : IUnknown
{
    HRESULT SetSourcePosition(const HrtfPosition *position);
    HRESULT SetSourceOrientation(const HrtfOrientation *orientation);
    HRESULT SetSourceGain(float gain);
    HRESULT SetEnvironment(HrtfEnvironment environment);
}
