57 int aziIndex, elevIndex, N_azi, idx3d;
59 float_complex weights_cmplx[3], hrtf_fb3[
NUM_EARS][3];
60 float aziRes, elevRes, weights[3], itds3[3], itdInterp;
62 const float_complex calpha = cmplxf(1.0f, 0.0f), cbeta = cmplxf(0.0f, 0.0f);
67 N_azi = (int)(360.0f / aziRes + 0.5f) + 1;
68 aziIndex = (int)(
matlab_fmodf(azimuth_deg + 180.0f, 360.0f) / aziRes + 0.5f);
69 elevIndex = (int)((elevation_deg + 90.0f) / elevRes + 0.5f);
70 idx3d = elevIndex * N_azi + aziIndex;
71 for (i = 0; i < 3; i++)
76 for (i = 0; i < 3; i++)
77 weights_cmplx[i] = cmplxf(weights[i], 0.0f);
79 for (i = 0; i < 3; i++){
83 cblas_cgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans,
NUM_EARS, 1, 3, &calpha,
84 (float_complex*)hrtf_fb3, 3,
85 (float_complex*)weights_cmplx, 1, &cbeta,
86 (float_complex*)h_intrp[band], 1);
92 for (i = 0; i < 3; i++) {
101 cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, 1, 1, 3, 1.0f,
103 (
float*)itds3, 1, 0.0f,
106 cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, 1, 2, 3, 1.0f,
108 (
float*)magnitudes3[band], 2, 0.0f,
109 (
float*)magInterp[band], 2);
117 ipd = cmplxf(0.0f, 0.0f);
118 h_intrp[band][0] = crmulf(cexpf(ipd), magInterp[band][0]);
119 h_intrp[band][1] = crmulf(conjf(cexpf(ipd)), magInterp[band][1]);
129 float* hrtf_vbap_gtable, *hrirs_resampled;
130#ifdef SAF_ENABLE_SOFA_READER_MODULE
139#ifdef SAF_ENABLE_SOFA_READER_MODULE
147 saf_print_warning(
"Unable to load the specified SOFA file, or it contained something other than 2 channels. Using default HRIR data instead.");
191 hrirs_resampled = NULL;
195 free(hrirs_resampled);
207 hrtf_vbap_gtable = NULL;
212 if(hrtf_vbap_gtable==NULL){
247 saf_print_warning(
"Too many grid points to calculate grid weights. Assuming that the HRTF measurement grid was uniform.");
264 free(hrtf_vbap_gtable);
274 if(pData->
hSTFT==NULL)
287 _Atomic_INT32* newNCH,
296 case SOURCE_CONFIG_PRESET_DEFAULT:
298 for(ch=0; ch<nCH; ch++)
300 dirs_deg[ch][i] = 0.0f;
302 case SOURCE_CONFIG_PRESET_MONO:
304 for(ch=0; ch<nCH; ch++)
308 case SOURCE_CONFIG_PRESET_STEREO:
310 for(ch=0; ch<nCH; ch++)
314 case SOURCE_CONFIG_PRESET_5PX:
316 for(ch=0; ch<nCH; ch++)
320 case SOURCE_CONFIG_PRESET_7PX:
322 for(ch=0; ch<nCH; ch++)
326 case SOURCE_CONFIG_PRESET_8PX:
328 for(ch=0; ch<nCH; ch++)
332 case SOURCE_CONFIG_PRESET_9PX:
334 for(ch=0; ch<nCH; ch++)
338 case SOURCE_CONFIG_PRESET_10PX:
340 for(ch=0; ch<nCH; ch++)
344 case SOURCE_CONFIG_PRESET_11PX:
346 for(ch=0; ch<nCH; ch++)
350 case SOURCE_CONFIG_PRESET_11PX_7_4:
352 for(ch=0; ch<nCH; ch++)
356 case SOURCE_CONFIG_PRESET_13PX:
358 for(ch=0; ch<nCH; ch++)
362 case SOURCE_CONFIG_PRESET_22PX:
364 for(ch=0; ch<nCH; ch++)
368 case SOURCE_CONFIG_PRESET_22P2_9_10_3:
370 for(ch=0; ch<nCH; ch++)
374 case SOURCE_CONFIG_PRESET_AALTO_MCC:
376 for(ch=0; ch<nCH; ch++)
380 case SOURCE_CONFIG_PRESET_AALTO_MCC_SUBSET:
382 for(ch=0; ch<nCH; ch++)
386 case SOURCE_CONFIG_PRESET_AALTO_APAJA:
388 for(ch=0; ch<nCH; ch++)
392 case SOURCE_CONFIG_PRESET_AALTO_LR:
394 for(ch=0; ch<nCH; ch++)
398 case SOURCE_CONFIG_PRESET_DTU_AVIL:
400 for(ch=0; ch<nCH; ch++)
404 case SOURCE_CONFIG_PRESET_ZYLIA_LAB:
406 for(ch=0; ch<nCH; ch++)
410 case SOURCE_CONFIG_PRESET_T_DESIGN_4:
412 for(ch=0; ch<nCH; ch++)
416 case SOURCE_CONFIG_PRESET_T_DESIGN_12:
418 for(ch=0; ch<nCH; ch++)
422 case SOURCE_CONFIG_PRESET_T_DESIGN_24:
424 for(ch=0; ch<nCH; ch++)
428 case SOURCE_CONFIG_PRESET_T_DESIGN_36:
430 for(ch=0; ch<nCH; ch++)
434 case SOURCE_CONFIG_PRESET_T_DESIGN_48:
436 for(ch=0; ch<nCH; ch++)
440 case SOURCE_CONFIG_PRESET_T_DESIGN_60:
442 for(ch=0; ch<nCH; ch++)
446 case SOURCE_CONFIG_PRESET_SPH_COV_9:
448 for(ch=0; ch<nCH; ch++)
452 case SOURCE_CONFIG_PRESET_SPH_COV_16:
454 for(ch=0; ch<nCH; ch++)
458 case SOURCE_CONFIG_PRESET_SPH_COV_25:
460 for(ch=0; ch<nCH; ch++)
464 case SOURCE_CONFIG_PRESET_SPH_COV_49:
466 for(ch=0; ch<nCH; ch++)
470 case SOURCE_CONFIG_PRESET_SPH_COV_64:
472 for(ch=0; ch<nCH; ch++)
491 for(i=0; i<nCH; i++){
492 sum_elev += dirs_deg[i][1];
#define MAX_NUM_INPUTS
Maximum number of input channels supported.
SOURCE_CONFIG_PRESETS
Available source configurations presets to use for encoding/panning.
CODEC_STATUS
Current status of the codec.
@ CODEC_STATUS_NOT_INITIALISED
Codec has not yet been initialised, or the codec configuration has changed.
@ CODEC_STATUS_INITIALISING
Codec is currently being initialised, input audio should not be processed.
void afSTFT_clearBuffers(void *const hSTFT)
Flushes time-domain buffers with zeros.
void afSTFT_create(void **const phSTFT, int nCHin, int nCHout, int hopsize, int lowDelayMode, int hybridmode, AFSTFT_FDDATA_FORMAT format)
Creates an instance of afSTFT.
void afSTFT_channelChange(void *const hSTFT, int new_nCHin, int new_nCHout)
Re-allocates memory to support a change in the number of input/output channels.
@ AFSTFT_BANDS_CH_TIME
nBands x nChannels x nTimeHops
#define HOP_SIZE
STFT hop size.
#define HYBRID_BANDS
Number of frequency bands.
INTERP_MODES
Available interpolation modes.
@ INTERP_TRI
Triangular interpolation.
@ INTERP_TRI_PS
Triangular interpolation (with phase-simplification)
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.
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.
Convolves input audio (up to 64 channels) with interpolated HRTFs in the time-frequency domain.
const int __default_N_hrir_dirs
The number of directions/measurements in the default HRIR dataset.
const float __default_hrirs[836][2][256]
The default HRIR data for SAF.
const float __default_hrir_dirs_deg[836][2]
The measurement directions used for the default HRIR dataset.
const int __default_hrir_len
The length of the filters, in samples, for the default HRIR dataset.
const int __default_hrir_fs
The samplerate used to measure the default HRIR filters.
void diffuseFieldEqualiseHRTFs(int N_dirs, float *itds_s, float *centreFreq, int N_bands, float *weights, int applyEQ, int applyPhase, float_complex *hrtfs)
Applies pre-processing to a set of HRTFs, which can either be diffuse-field EQ of an (optionally weig...
void resampleHRIRs(float *hrirs_in, int hrirs_N_dirs, int hrirs_in_len, int hrirs_in_fs, int hrirs_out_fs, int padToNextPow2, float **hrirs_out, int *hrirs_out_len)
Resamples a set of HRIRs from its original samplerate to a new samplerate.
void estimateITDs(float *hrirs, int N_dirs, int hrir_len, int fs, float *itds_s)
Estimates the interaural time-differences (ITDs) for each HRIR based on the cross-correlation between...
void HRIRs2HRTFs_afSTFT(float *hrirs, int N_dirs, int hrir_len, int hopsize, int LDmode, int hybridmode, float_complex *hrtf_fb)
Passes zero padded HRIRs through the afSTFT filterbank.
int calculateGridWeights(float *dirs_rad, int nDirs, int order, float *w)
Computes approximation of quadrature/integration weights for a given grid.
void saf_sofa_close(saf_sofa_container *c)
Frees all SOFA data in a sofa_container.
SAF_SOFA_ERROR_CODES saf_sofa_open(saf_sofa_container *h, char *sofa_filepath, SAF_SOFA_READER_OPTIONS option)
Fills a 'sofa_container' with data found in a SOFA file (GeneralFIR or SimpleFreeFieldHRIR),...
SAF_SOFA_ERROR_CODES
SOFA loader error codes.
@ SAF_SOFA_READER_OPTION_DEFAULT
The default option is SAF_SOFA_READER_OPTION_LIBMYSOFA.
@ SAF_SOFA_OK
None of the error checks failed.
const float __Zylia_Lab_dirs_deg[22][2]
Loudspeaker directions [azimuth, Elevation] in degrees, for the 22.x setup, at Zylia Labs.
#define SAF_PI
pi constant (single precision)
const float __9pX_dirs_deg[9][2]
Loudspeaker directions [azimuth, Elevation] in degrees, for a 9.x setup.
const float __SphCovering_16_dirs_deg[16][2]
Directions [azimuth, Elevation] in degrees, for sphere covering: 16 dirs.
const float __Aalto_MCC_dirs_deg[45][2]
Loudspeaker directions [azimuth, Elevation] in degrees, for the multi-channel anechoic chamber (MCC),...
const float __SphCovering_49_dirs_deg[49][2]
Directions [azimuth, Elevation] in degrees, for sphere covering: 49 dirs.
void convert_0_360To_m180_180(float *dirs_deg, int nDirs)
Wraps around any angles exeeding 180 degrees (e.g., 200-> -160)
#define NUM_EARS
2 (true for most humans)
float matlab_fmodf(float x, float y)
C fmodf function, except it behaves like 'mod' in Matlab (i.e.
const float __mono_dirs_deg[1][2]
Loudspeaker directions [azimuth, Elevation] in degrees, for a mono setup.
const float __5pX_dirs_deg[5][2]
Loudspeaker directions [azimuth, Elevation] in degrees, for a 5.x setup.
const float __11pX_dirs_deg[11][2]
Loudspeaker directions [azimuth, Elevation] in degrees, for a 11.x setup.
const float __Tdesign_degree_9_dirs_deg[48][2]
Directions [azimuth, Elevation] in degrees, for minimum Tdesign degree: 9.
const float __Tdesign_degree_2_dirs_deg[4][2]
Directions [azimuth, Elevation] in degrees, for minimum Tdesign degree: 2.
const float __11pX_7_4_dirs_deg[11][2]
Loudspeaker directions [azimuth, Elevation] in degrees, for a 7.4.x setup.
const float __Tdesign_degree_8_dirs_deg[36][2]
Directions [azimuth, Elevation] in degrees, for minimum Tdesign degree: 8.
const float __9_10_3p2_dirs_deg[24][2]
Loudspeaker directions [azimuth, Elevation] in degrees, for a 9+10+3.2 setup BS 2051 recommedation: h...
const float __default_LScoords128_deg[128][2]
Default Loudspeaker directions [azimuth, Elevation] - to replace above!
const float __Aalto_MCCsubset_dirs_deg[37][2]
Loudspeaker directions [azimuth, Elevation] in degrees, for the multi-channel anechoic chamber (MCC) ...
const float __Aalto_Apaja_dirs_deg[29][2]
Loudspeaker directions [azimuth, Elevation] in degrees, for the audio-visual listening room (Apaja),...
const float __SphCovering_9_dirs_deg[9][2]
Directions [azimuth, Elevation] in degrees, for sphere covering: 9 dirs.
const float __stereo_dirs_deg[2][2]
Loudspeaker directions [azimuth, Elevation] in degrees, for a stereo setup.
const float __SphCovering_64_dirs_deg[64][2]
Directions [azimuth, Elevation] in degrees, for sphere covering: 64 dirs.
const float __Tdesign_degree_4_dirs_deg[12][2]
Directions [azimuth, Elevation] in degrees, for minimum Tdesign degree: 4.
void sphElev2incl(float *dirsElev, int nDirs, int degreesFlag, float *dirsIncl)
Converts spherical coordinates of unit length from elevation to inclination.
const float __Aalto_LR_dirs_deg[13][2]
Loudspeaker directions [azimuth, Elevation] in degrees, for the ITU standard listening room (LR),...
const float __DTU_AVIL_dirs_deg[64][2]
Loudspeaker directions [azimuth, Elevation] in degrees, for the Audio Visual Immersion Lab (AVIL),...
const float __8pX_dirs_deg[8][2]
Loudspeaker directions [azimuth, Elevation] in degrees, for a 8.x setup.
const float __Tdesign_degree_6_dirs_deg[24][2]
Directions [azimuth, Elevation] in degrees, for minimum Tdesign degree: 6.
const float __13pX_dirs_deg[13][2]
Loudspeaker directions [azimuth, Elevation] in degrees, for a 13.x setup.
const float __7pX_dirs_deg[7][2]
Loudspeaker directions [azimuth, Elevation] in degrees, for a 7.x setup.
#define saf_print_warning(message)
Macro to print a warning message along with the filename and line number.
const float __22pX_dirs_deg[22][2]
Loudspeaker directions [azimuth, Elevation] in degrees, for a 22.x setup.
const float __SphCovering_25_dirs_deg[25][2]
Directions [azimuth, Elevation] in degrees, for sphere covering: 25 dirs.
const float __Tdesign_degree_10_dirs_deg[60][2]
Directions [azimuth, Elevation] in degrees, for minimum Tdesign degree: 10.
const float __10pX_dirs_deg[10][2]
Loudspeaker directions [azimuth, Elevation] in degrees, for a 10.x setup.
void generateVBAPgainTable3D(float *ls_dirs_deg, int L, int az_res_deg, int el_res_deg, int omitLargeTriangles, int enableDummies, float spread, float **gtable, int *N_gtable, int *nTriangles)
Generates a 3-D VBAP gain table based on specified loudspeaker directions, with optional spreading [2...
void compressVBAPgainTable3D(float *vbap_gtable, int nTable, int nDirs, float *vbap_gtableComp, int *vbap_gtableIdx)
Compresses a VBAP gain table to use less memory and CPU (by removing the elements which are just zero...
void * malloc1d(size_t dim1_data_size)
1-D malloc (same as malloc, but with error checking)
void * realloc1d(void *ptr, size_t dim1_data_size)
1-D realloc (same as realloc, but with error checking)
Main structure for binauraliser.
_Atomic_INT32 hrir_loaded_fs
sampling rate of the loaded HRIRs
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 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_complex * hrtf_fb
hrtf filterbank coefficients; nBands x nCH x N_hrirs
int N_hrtf_vbap_gtable
Number of interpolation weights/directions.
float * hrir_dirs_deg
directions of the HRIRs in degrees [azi elev]; FLAT: N_hrir_dirs x 2
_Atomic_FLOAT32 fs
Host sampling rate, in Hz.
float * weights
Integration weights for the HRIR measurement grid; N_hrir_dirs x 1.
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.
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_FLOAT32 progressBar0_1
Current (re)initialisation progress, between [0..1].
_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 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.
SOFA container struct comprising all possible data that can be extracted from SOFA 1....
int DataLengthIR
Length of the IRs, in samples.
int nSources
Number of source/measurement positions.
float * SourcePosition
Source positions (refer to SourcePositionType & SourcePositionUnits for the convention and units); FL...
float DataSamplingRate
Sampling rate used to measure the IRs.
int nReceivers
Number of ears/number of mics etc.
float * DataIR
The impulse response (IR) Data; FLAT:nSources x nReceivers x DataLengthIR.