Skip to content

File HRIRSphere.h

File List > Amplitude > HRTF > HRIRSphere.h

Go to the documentation of this file

// Copyright (c) 2024-present Sparky Studios. All rights reserved.
//
// 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.

#pragma once

#ifndef _AM_HRTF_HRIR_SPHERE_H
#define _AM_HRTF_HRIR_SPHERE_H

#include <SparkyStudios/Audio/Amplitude/Core/Common.h>
#include <SparkyStudios/Audio/Amplitude/IO/File.h>
#include <SparkyStudios/Audio/Amplitude/IO/Resource.h>
#include <SparkyStudios/Audio/Amplitude/Math/Geometry.h>

namespace SparkyStudios::Audio::Amplitude
{
    enum eHRIRSphereDatasetModel : AmUInt8
    {
        eHRIRSphereDatasetModel_IRCAM = 0,

        eHRIRSphereDatasetModel_MIT = 1,

        eHRIRSphereDatasetModel_SADIE = 2,

        eHRIRSphereDatasetModel_SOFA = 3,

        eHRIRSphereDatasetModel_Invalid
    };

    struct HRIRSphereFileHeaderDescription
    {
        AmUInt8 m_Header[4] = { 'A', 'M', 'I', 'R' };

        AmUInt16 m_Version = 0;

        AmUInt32 m_SampleRate = 0;

        AmUInt32 m_IRLength = 0;

        AmUInt32 m_VertexCount = 0;

        AmUInt32 m_IndexCount = 0;
    };

    struct HRIRSphereVertex
    {
        AmVector3 m_Position;

        std::vector<AmReal32> m_LeftIR;

        std::vector<AmReal32> m_RightIR;

        AmReal32 m_LeftDelay = 0.0f;

        AmReal32 m_RightDelay = 0.0f;
    };

    class AM_API_PUBLIC HRIRSphere : public Resource
    {
    public:
        virtual void SetResource(const AmOsString& filePath) = 0;

        [[nodiscard]] virtual const std::vector<HRIRSphereVertex>& GetVertices() const = 0;

        [[nodiscard]] virtual const std::vector<Face>& GetFaces() const = 0;

        [[nodiscard]] virtual const HRIRSphereVertex& GetVertex(AmUInt32 index) const = 0;

        [[nodiscard]] virtual AmUInt32 GetVertexCount() const = 0;

        [[nodiscard]] virtual AmUInt32 GetFaceCount() const = 0;

        [[nodiscard]] virtual AmUInt32 GetSampleRate() const = 0;

        [[nodiscard]] virtual AmUInt32 GetIRLength() const = 0;

        virtual void SetSamplingMode(eHRIRSphereSamplingMode mode) = 0;

        [[nodiscard]] virtual eHRIRSphereSamplingMode GetSamplingMode() const = 0;

        virtual void Sample(const AmVector3& direction, AmReal32* leftHRIR, AmReal32* rightHRIR) const = 0;

        virtual void Transform(const AmMatrix4& matrix) = 0;

        [[nodiscard]] virtual bool IsLoaded() const = 0;
    };
} // namespace SparkyStudios::Audio::Amplitude

#endif // _AM_HRTF_HRIR_SPHERE_H