VAE - Virtual Audio Engine 1
Small Data Driven Audio Engine
vae::core::HRTFUtil Struct Reference

#include <vae_hrtf_util.hpp>

Collaboration diagram for vae::core::HRTFUtil:

Static Public Member Functions

static Size closest (const HRTF &hrtf, const Vec3 &direction)
 Looks for the best matching IR in a HRTF. More...
 
static void apply (HRTF::Position &hrtf, VoiceHRTF &hrtfVoice, SampleIndex frames, ScratchBuffer &target, const Sample *in, Sample distanceAttenuated)
 Applies simple time domain convolution. More...
 

Detailed Description

Definition at line 11 of file vae_hrtf_util.hpp.

Member Function Documentation

◆ apply()

static void vae::core::HRTFUtil::apply ( HRTF::Position hrtf,
VoiceHRTF hrtfVoice,
SampleIndex  frames,
ScratchBuffer target,
const Sample in,
Sample  distanceAttenuated 
)
inlinestatic

Applies simple time domain convolution.

Parameters
hrtfHRTF to use
hrtfVoiceConvolution data for the voice
framesNumber of frames
targetTarget buffer to mix into
inSignal to convolve
distanceAttenuatedVolume applied

Definition at line 48 of file vae_hrtf_util.hpp.

51 {
52 VAE_PROFILER_SCOPE_NAMED("Apply HRTF")
53 const Sample* irLeft = hrtf.ir[0][0];
54 const Sample* irRight = hrtf.ir[1][0];
55 const Size irLen = hrtf.ir[0].size();
56 Sample* convolutionBuffer = hrtfVoice.convolutionBuffer[0];
57 Size convolutionIndex = hrtfVoice.convolutionIndex;
58 // TODO bad brute force convolution in time domain
59 for (SampleIndex i = 0; i < frames; i++) {
60 Sample leftSum = 0;
61 Sample rightSum = 0;
62 convolutionBuffer[convolutionIndex] = in[i];
63
64 for (SampleIndex n = 0; n < irLen; n++) {
65 const Sample conv = convolutionBuffer[(irLen + convolutionIndex - n) % irLen];
66 leftSum += irLeft[n] * conv;
67 rightSum += irRight[n] * conv;
68 }
69 target[0][i] += leftSum * distanceAttenuated;
70 target[1][i] += rightSum * distanceAttenuated;
71 convolutionIndex = (convolutionIndex + 1) % irLen;
72 }
73 hrtfVoice.convolutionIndex = convolutionIndex;
74 }
AudioBuffer::Size SampleIndex
Definition: vae_types.hpp:87
unsigned int Size
How the elements are addressed in the heapbuffer.
Definition: vae.hpp:33
float Sample
Default sample types used where ever possible, changing this means the engine needs to be recompiled,...
Definition: vae.hpp:32
#define VAE_PROFILER_SCOPE_NAMED(name)
Profiles a scope and names it.
Here is the call graph for this function:

◆ closest()

static Size vae::core::HRTFUtil::closest ( const HRTF hrtf,
const Vec3 direction 
)
inlinestatic

Looks for the best matching IR in a HRTF.

Does bad brute force search, should use kd tree or the mysodalib

Parameters
hrtf
direction
Returns
Size

Definition at line 19 of file vae_hrtf_util.hpp.

19 {
20 // TODO this is obviously bad
21 VAE_PROFILER_SCOPE_NAMED("Search HRTF")
22 Sample closest = std::numeric_limits<Sample>::max();
23 Size closestIndex = ~0;
24 for (Size i = 0; i < hrtf.positions.size(); i++) {
25 const auto& pos = hrtf.positions[i];
26 const Sample dist = glm::distance(pos.pos, direction);
27 if (dist < closest) {
28 closestIndex = i;
29 closest = dist;
30 if (closest < 0.05) {
31 break; // * close enough
32 }
33 }
34 }
35 return closestIndex;
36 };
T max(const T &v1, const T &v2)
Definition: TMath.hpp:21
static Size closest(const HRTF &hrtf, const Vec3 &direction)
Looks for the best matching IR in a HRTF.
Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this struct was generated from the following file: