SAF
Loading...
Searching...
No Matches
binauraliser_internal.h
Go to the documentation of this file.
1/*
2 * Copyright 2017-2018 Leo McCormack
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 * PERFORMANCE OF THIS SOFTWARE.
15 */
16
32
33#ifndef __BINAURALISER_INTERNAL_H_INCLUDED__
34#define __BINAURALISER_INTERNAL_H_INCLUDED__
35
36#include "binauraliser.h" /* Include header for this example */
37#include "saf.h" /* Main include header for SAF */
38#include "saf_externals.h" /* To also include SAF dependencies (cblas etc.) */
39
40#ifdef __cplusplus
41extern "C" {
42#endif /* __cplusplus */
43
44/* ========================================================================== */
45/* Internal Parameters */
46/* ========================================================================== */
47
48#if !defined(BINAURALISER_FRAME_SIZE)
49# if defined(FRAME_SIZE) /* Use the global framesize if it is specified: */
50# define BINAURALISER_FRAME_SIZE ( FRAME_SIZE )
51# else /* Otherwise, the default framesize for this example is: */
52# define BINAURALISER_FRAME_SIZE ( 128 )
53# endif
54#endif
55#define HOP_SIZE ( 128 )
56#define HYBRID_BANDS ( HOP_SIZE + 5 )
57#define TIME_SLOTS ( BINAURALISER_FRAME_SIZE / HOP_SIZE )
58
59/* Checks: */
60#if (BINAURALISER_FRAME_SIZE % HOP_SIZE != 0)
61# error "BINAURALISER_FRAME_SIZE must be an integer multiple of HOP_SIZE"
62#endif
63
64#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && !defined(__STDC_NO_ATOMICS__)
65 typedef _Atomic INTERP_MODES _Atomic_INTERP_MODES;
66#else
67 typedef INTERP_MODES _Atomic_INTERP_MODES;
68#endif
69
70/* ========================================================================== */
71/* Structures */
72/* ========================================================================== */
73
79typedef struct _binauraliser
80{
81 /* audio buffers */
82 float** inputFrameTD;
83 float** outframeTD;
84 float_complex*** inputframeTF;
85 float_complex*** outputframeTF;
86 _Atomic_FLOAT32 fs;
88 void* hSTFT;
89
90 /* sofa file info */
92 float* hrirs;
94 _Atomic_INT32 N_hrir_dirs;
95 _Atomic_INT32 hrir_loaded_len;
96 _Atomic_INT32 hrir_runtime_len;
97 _Atomic_INT32 hrir_loaded_fs;
98 _Atomic_INT32 hrir_runtime_fs;
99 float* weights;
100
101 /* vbap gain table */
106
107 /* hrir filterbank coefficients */
108 float* itds_s;
109 float_complex* hrtf_fb;
110 float* hrtf_fb_mag;
112
113 /* flags/status */
114 _Atomic_CODEC_STATUS codecStatus;
115 _Atomic_FLOAT32 progressBar0_1;
117 _Atomic_PROC_STATUS procStatus;
120 _Atomic_INT32 recalc_M_rotFLAG;
121
122 /* misc. */
127 _Atomic_INT32 new_nSources;
128
129 /* user parameters */
130 _Atomic_INT32 nSources;
131 _Atomic_FLOAT32 src_dirs_deg[MAX_NUM_INPUTS][2];
132 _Atomic_INTERP_MODES interpMode;
133 _Atomic_INT32 useDefaultHRIRsFLAG;
134 _Atomic_INT32 enableHRIRsDiffuseEQ;
135 _Atomic_INT32 enableRotation;
136 _Atomic_FLOAT32 yaw;
137 _Atomic_FLOAT32 roll;
138 _Atomic_FLOAT32 pitch;
139 _Atomic_INT32 bFlipYaw;
140 _Atomic_INT32 bFlipPitch;
141 _Atomic_INT32 bFlipRoll;
142 _Atomic_INT32 useRollPitchYawFlag;
143 _Atomic_FLOAT32 src_gains[MAX_NUM_INPUTS];
144
146
147
148/* ========================================================================== */
149/* Internal Functions */
150/* ========================================================================== */
151
153void binauraliser_setCodecStatus(void* const hBin,
154 CODEC_STATUS newStatus);
155
168void binauraliser_interpHRTFs(void* const hBin,
169 INTERP_MODES mode,
170 float azimuth_deg,
171 float elevation_deg,
172 float_complex h_intrp[HYBRID_BANDS][NUM_EARS]);
173
180void binauraliser_initHRTFsAndGainTables(void* const hBin);
181
187void binauraliser_initTFT(void* const hBin);
188
205 _Atomic_FLOAT32 dirs_deg[MAX_NUM_INPUTS][2],
206 _Atomic_INT32* newNCH,
207 int* nDims);
208
209
210#ifdef __cplusplus
211} /* extern "C" { */
212#endif /* __cplusplus */
213
214#endif /* __BINAURALISER_INTERNAL_H_INCLUDED__ */
#define MAX_NUM_INPUTS
Maximum number of input channels supported.
Definition _common.h:237
SOURCE_CONFIG_PRESETS
Available source configurations presets to use for encoding/panning.
Definition _common.h:137
CODEC_STATUS
Current status of the codec.
Definition _common.h:205
#define HYBRID_BANDS
Number of frequency bands.
Convolves input audio (up to 64 channels) with interpolated HRTFs in the time-frequency domain.
INTERP_MODES
Available interpolation modes.
void binauraliser_initHRTFsAndGainTables(void *const hBin)
Initialise the HRTFs: either loading the default set or loading from a SOFA file; and then generate a...
void binauraliser_loadPreset(SOURCE_CONFIG_PRESETS preset, _Atomic_FLOAT32 dirs_deg[MAX_NUM_INPUTS][2], _Atomic_INT32 *newNCH, int *nDims)
Returns the source directions for a specified source config preset.
void binauraliser_setCodecStatus(void *const hBin, CODEC_STATUS newStatus)
Sets codec status (see CODEC_STATUS enum)
void binauraliser_initTFT(void *const hBin)
Initialise the filterbank used by binauraliser.
#define HYBRID_BANDS
Number of frequency bands.
void binauraliser_interpHRTFs(void *const hBin, INTERP_MODES mode, float azimuth_deg, float elevation_deg, float_complex h_intrp[HYBRID_BANDS][NUM_EARS])
Interpolates between (up to) 3 HRTFs via amplitude-normalised VBAP gains.
#define NUM_EARS
2 (true for most humans)
Main include header for the Spatial_Audio_Framework (SAF)
Include header for SAF externals.
Main structure for binauraliser.
float ** inputFrameTD
time-domain input frame; MAX_NUM_INPUTS x BINAURALISER_FRAME_SIZE
_Atomic_INT32 hrir_loaded_fs
sampling rate of the loaded HRIRs
_Atomic_INT32 reInitHRTFsAndGainTables
1: reinitialise the HRTFs and interpolation tables, 0: do not
_Atomic_FLOAT32 yaw
yaw (Euler) rotation angle, in degrees
_Atomic_FLOAT32 src_gains[MAX_NUM_INPUTS]
Gains applied per source.
_Atomic_INT32 recalc_M_rotFLAG
1: re-calculate the rotation matrix, 0: do not
float_complex *** outputframeTF
time-frequency domain input frame; HYBRID_BANDS x NUM_EARS x TIME_SLOTS
float * hrtf_vbap_gtableComp
N_hrtf_vbap_gtable x 3.
_Atomic_INT32 enableHRIRsDiffuseEQ
flag to diffuse-field equalisation to the currently loaded HRTFs
_Atomic_INT32 bFlipPitch
flag to flip the sign of the pitch rotation angle
_Atomic_INT32 useRollPitchYawFlag
rotation order flag, 1: r-p-y, 0: y-p-r
float src_dirs_rot_xyz[MAX_NUM_INPUTS][3]
Intermediate rotated source directions, as unit-length Cartesian coordinates.
_Atomic_INT32 hrir_runtime_fs
sampling rate of the HRIRs being used for processing (after any resampling)
float * hrirs
time domain HRIRs; FLAT: N_hrir_dirs x NUM_EARS x hrir_len
float src_dirs_rot_deg[MAX_NUM_INPUTS][2]
Intermediate rotated source directions, in degrees.
float_complex * hrtf_fb
hrtf filterbank coefficients; nBands x nCH x N_hrirs
int N_hrtf_vbap_gtable
Number of interpolation weights/directions.
float_complex hrtf_interp[MAX_NUM_INPUTS][HYBRID_BANDS][NUM_EARS]
Interpolated HRTFs.
_Atomic_INTERP_MODES interpMode
see INTERP_MODES
float * hrir_dirs_deg
directions of the HRIRs in degrees [azi elev]; FLAT: N_hrir_dirs x 2
_Atomic_FLOAT32 src_dirs_deg[MAX_NUM_INPUTS][2]
Current source/panning directions, in degrees.
_Atomic_FLOAT32 fs
Host sampling rate, in Hz.
float * weights
Integration weights for the HRIR measurement grid; N_hrir_dirs x 1.
_Atomic_INT32 bFlipYaw
flag to flip the sign of the yaw rotation angle
float src_dirs_xyz[MAX_NUM_INPUTS][3]
Intermediate source directions, as unit-length Cartesian coordinates.
float_complex *** inputframeTF
time-frequency domain input frame; HYBRID_BANDS x MAX_NUM_INPUTS x TIME_SLOTS
float * itds_s
interaural-time differences for each HRIR (in seconds); nBands x 1
_Atomic_INT32 hrir_loaded_len
length of the loaded HRIRs, in samples
int * hrtf_vbap_gtableIdx
N_hrtf_vbap_gtable x 3.
_Atomic_FLOAT32 pitch
pitch (Euler) rotation angle, in degrees
_Atomic_FLOAT32 roll
roll (Euler) rotation angle, in degrees
_Atomic_INT32 enableRotation
1: enable rotation, 0: disable
int hrtf_vbapTableRes[2]
[0] azimuth, and [1] elevation grid resolution, in degrees
char * progressBarText
Current (re)initialisation step, string.
void * hSTFT
afSTFT handle
_Atomic_INT32 recalc_hrtf_interpFLAG[MAX_NUM_INPUTS]
1: re-calculate/interpolate the HRTF, 0: do not
float * hrtf_fb_mag
magnitudes of the hrtf filterbank coefficients; nBands x nCH x N_hrirs
_Atomic_PROC_STATUS procStatus
see PROC_STATUS
_Atomic_FLOAT32 progressBar0_1
Current (re)initialisation progress, between [0..1].
_Atomic_INT32 bFlipRoll
flag to flip the sign of the roll rotation angle
_Atomic_INT32 N_hrir_dirs
number of HRIR directions in the current sofa file
_Atomic_INT32 hrir_runtime_len
length of the HRIRs being used for processing (after any resampling), in samples
_Atomic_INT32 useDefaultHRIRsFLAG
1: use default HRIRs in database, 0: use those from SOFA file
char * sofa_filepath
absolute/relevative file path for a sofa file
_Atomic_CODEC_STATUS codecStatus
see CODEC_STATUS
int nTriangles
Number of triangles in the convex hull of the spherical arrangement of HRIR directions/points.
float ** outframeTD
time-domain output frame; NUM_EARS x BINAURALISER_FRAME_SIZE
float freqVector[HYBRID_BANDS]
Frequency vector (filterbank centre frequencies)
_Atomic_INT32 new_nSources
New number of input/source signals (current value will be replaced by this after next re-init)
_Atomic_INT32 nSources
Current number of input/source signals.