HephAudio v3.1.0
A cross-platform C++ library for recording, playing, and processing audio on Windows, Android, Linux, iOS, and macOS.
Loading...
Searching...
No Matches
HephAudio::Spatializer Class Reference

applies 3D audio spatialization using SOFA files. More...

#include <Spatializer.h>

Inheritance diagram for HephAudio::Spatializer:
HephAudio::FrequencyDomainEffect HephAudio::OlaEffect HephAudio::DoubleBufferedAudioEffect HephAudio::AudioEffect

Public Member Functions

 Spatializer ()
 
 Spatializer (size_t hopSize, const Window &wnd)
 
 Spatializer (float azimuth, float elevation, size_t hopSize, const Window &wnd)
 
 Spatializer (const std::filesystem::path &filePath, uint32_t sampleRate, float azimuth, float elevation, size_t hopSize, const Window &wnd)
 
virtual ~Spatializer ()
 
virtual std::string Name () const override
 
virtual void Process (AudioBuffer &buffer, size_t startIndex, size_t frameCount) override
 
virtual void SetWindow (const Window &wnd) override
 
virtual void OpenSofaFile (const std::filesystem::path &filePath)
 
virtual void CloseSofaFile ()
 
virtual float GetAzimuth () const
 
virtual void SetAzimuth (float azimuth)
 
virtual float GetElevation () const
 
virtual void SetElevation (float elevation)
 
virtual uint32_t GetSampleRate () const
 
virtual void SetSampleRate (uint32_t sampleRate)
 
virtual size_t GetHrtfSize () const
 
- Public Member Functions inherited from HephAudio::FrequencyDomainEffect
virtual ~FrequencyDomainEffect ()=default
 
- Public Member Functions inherited from HephAudio::OlaEffect
virtual ~OlaEffect ()=default
 
virtual size_t CalculateRequiredFrameCount (size_t outputFrameCount, const AudioFormatInfo &formatInfo) const
 
virtual void ResetInternalState () override
 
virtual size_t GetHopSize () const
 
virtual void SetHopSize (size_t hopSize)
 
virtual size_t GetWindowSize () const
 
virtual void Process (AudioBuffer &buffer)
 
virtual void Process (AudioBuffer &buffer, size_t startIndex)
 
- Public Member Functions inherited from HephAudio::DoubleBufferedAudioEffect
virtual ~DoubleBufferedAudioEffect ()=default
 
- Public Member Functions inherited from HephAudio::AudioEffect
virtual ~AudioEffect ()=default
 
virtual bool HasMTSupport () const
 
virtual bool HasRTSupport () const
 
virtual size_t GetThreadCount () const
 
virtual void SetThreadCount (size_t threadCount)
 
virtual size_t CalculateOutputFrameCount (size_t inputFrameCount, const AudioFormatInfo &formatInfo) const
 
virtual size_t CalculateAdvanceSize (size_t renderFrameCount, const AudioFormatInfo &formatInfo) const
 

Protected Member Functions

virtual void ProcessST (const AudioBuffer &inputBuffer, AudioBuffer &outputBuffer, size_t startIndex, size_t frameCount) override
 
virtual void OpenDefaultFile ()
 
virtual std::string GetErrorString (int errorCode) const
 gets the error message that corresponds to the provided code.
 
- Protected Member Functions inherited from HephAudio::FrequencyDomainEffect
 FrequencyDomainEffect ()
 
 FrequencyDomainEffect (size_t hopSize)
 
 FrequencyDomainEffect (size_t hopSize, const Window &wnd)
 
- Protected Member Functions inherited from HephAudio::OlaEffect
 OlaEffect ()
 
 OlaEffect (size_t hopSize)
 
 OlaEffect (size_t hopSize, const Window &wnd)
 
virtual size_t CalculateMaxNumberOfOverlaps () const
 
virtual size_t CalculatePastSamplesSize () const
 
- Protected Member Functions inherited from HephAudio::DoubleBufferedAudioEffect
 DoubleBufferedAudioEffect ()
 
virtual AudioBuffer CreateOutputBuffer (const AudioBuffer &inputBuffer, size_t startIndex, size_t frameCount) const
 
virtual void InitializeOutputBuffer (const AudioBuffer &inputBuffer, AudioBuffer &outputBuffer, size_t startIndex, size_t frameCount) const
 
- Protected Member Functions inherited from HephAudio::AudioEffect
 AudioEffect ()
 
virtual void ProcessMT (const AudioBuffer &inputBuffer, AudioBuffer &outputBuffer, size_t startIndex, size_t frameCount)
 

Protected Attributes

float azimuth
 
float elevation
 
std::filesystem::path filePath
 
MYSOFA_EASY * pEasy
 
size_t hrtfSize
 
uint32_t hrtfSampleRate
 
bool updateTransferFunctions
 
std::array< Heph::ComplexBuffer, 2 > transferFunctions
 
- Protected Attributes inherited from HephAudio::OlaEffect
size_t hopSize
 
Heph::DoubleBuffer wnd
 
size_t currentIndex
 
AudioBuffer pastSamples
 
- Protected Attributes inherited from HephAudio::AudioEffect
size_t threadCount
 

Detailed Description

applies 3D audio spatialization using SOFA files.

Constructor & Destructor Documentation

◆ Spatializer() [1/4]

HephAudio::Spatializer::Spatializer ( )

creates a new instance and initializes it with default values.

◆ Spatializer() [2/4]

HephAudio::Spatializer::Spatializer ( size_t hopSize,
const Window & wnd )

creates a new instance and initializes it with the provided values.

Parameters
hopSizenumber of frames to advance each iteration.
wndwindow that will be applied for overlap-add.

◆ Spatializer() [3/4]

HephAudio::Spatializer::Spatializer ( float azimuth,
float elevation,
size_t hopSize,
const Window & wnd )

creates a new instance and initializes it with the provided values.

Parameters
azimuthin degrees.
elevationin degrees.
hopSizenumber of frames to advance each iteration.
wndwindow that will be applied for overlap-add.

◆ Spatializer() [4/4]

HephAudio::Spatializer::Spatializer ( const std::filesystem::path & filePath,
uint32_t sampleRate,
float azimuth,
float elevation,
size_t hopSize,
const Window & wnd )

creates a new instance and initializes it with the provided values.

Parameters
filePathpath of the SOFA file.
sampleRatesampling rate of the HRTF filters.
azimuthin degrees.
elevationin degrees.
hopSizenumber of frames to advance each iteration.
wndwindow that will be applied for overlap-add.

◆ ~Spatializer()

virtual HephAudio::Spatializer::~Spatializer ( )
virtual

releases the resources and destroys the instance.

Member Function Documentation

◆ Name()

virtual std::string HephAudio::Spatializer::Name ( ) const
overridevirtual

gets the name of the audio effect.

Implements HephAudio::AudioEffect.

◆ Process()

virtual void HephAudio::Spatializer::Process ( AudioBuffer & buffer,
size_t startIndex,
size_t frameCount )
overridevirtual

Applies the effect.

Parameters
buffercontains the audio data which will be processed.
startIndexindex of the first audio frame to process.
frameCountnumber of frames to process.

Reimplemented from HephAudio::OlaEffect.

◆ SetWindow()

virtual void HephAudio::Spatializer::SetWindow ( const Window & wnd)
overridevirtual

sets the window.

Parameters
wndwindow that will be applied for overlap-add.

Reimplemented from HephAudio::FrequencyDomainEffect.

◆ OpenSofaFile()

virtual void HephAudio::Spatializer::OpenSofaFile ( const std::filesystem::path & filePath)
virtual

reads the SOFA file.

Parameters
filePathpath of the SOFA file.

◆ CloseSofaFile()

virtual void HephAudio::Spatializer::CloseSofaFile ( )
virtual

closes the SOFA file and releases the resources.

◆ GetAzimuth()

virtual float HephAudio::Spatializer::GetAzimuth ( ) const
virtual

gets the azimuth angle in degrees.

◆ SetAzimuth()

virtual void HephAudio::Spatializer::SetAzimuth ( float azimuth)
virtual

sets the azimuth angle.

Parameters
azimuthin degrees.

◆ GetElevation()

virtual float HephAudio::Spatializer::GetElevation ( ) const
virtual

gets the elevation angle in degrees.

◆ SetElevation()

virtual void HephAudio::Spatializer::SetElevation ( float elevation)
virtual

sets the elevation angle.

Parameters
elevationin degrees.

◆ GetSampleRate()

virtual uint32_t HephAudio::Spatializer::GetSampleRate ( ) const
virtual

gets the sampling rate of the HRTF filters.

◆ SetSampleRate()

virtual void HephAudio::Spatializer::SetSampleRate ( uint32_t sampleRate)
virtual

sets the sampling rate of the HRTF filters.

Parameters
sampleRatesampling rate of the HRTF filters.

◆ GetHrtfSize()

virtual size_t HephAudio::Spatializer::GetHrtfSize ( ) const
virtual

gets the size of the HRTF filters.

◆ ProcessST()

virtual void HephAudio::Spatializer::ProcessST ( const AudioBuffer & inputBuffer,
AudioBuffer & outputBuffer,
size_t startIndex,
size_t frameCount )
overrideprotectedvirtual

applies the effect using single thread.

Parameters
inputBuffercontains the audio data which will be processed.
outputBuffercontains the processed audio data.
startIndexindex of the first sample to process.
frameCountnumber of frames to process.

Implements HephAudio::AudioEffect.

◆ OpenDefaultFile()

virtual void HephAudio::Spatializer::OpenDefaultFile ( )
protectedvirtual

opens the default SOFA file.

◆ GetErrorString()

virtual std::string HephAudio::Spatializer::GetErrorString ( int errorCode) const
protectedvirtual

gets the error message that corresponds to the provided code.

Parameters
errorCodethe error code returned by the libmysofa library.

Member Data Documentation

◆ azimuth

float HephAudio::Spatializer::azimuth
protected

in degrees.

◆ elevation

float HephAudio::Spatializer::elevation
protected

in degrees.

◆ filePath

std::filesystem::path HephAudio::Spatializer::filePath
protected

path of the SOFA file.

◆ pEasy

MYSOFA_EASY* HephAudio::Spatializer::pEasy
protected

stores the contents of the SOFA file.

◆ hrtfSize

size_t HephAudio::Spatializer::hrtfSize
protected

size of the HRTF filters.

◆ hrtfSampleRate

uint32_t HephAudio::Spatializer::hrtfSampleRate
protected

sampling rate of the HRTF filters.

◆ updateTransferFunctions

bool HephAudio::Spatializer::updateTransferFunctions
protected

indicates whether there has been any change and the transfer functions needs updating.

◆ transferFunctions

std::array<Heph::ComplexBuffer, 2> HephAudio::Spatializer::transferFunctions
protected

an array of transfer functions where the first element is the left channel, and the second element is the right channel.