SAF
Loading...
Searching...
No Matches
saf_hades_internal.h
Go to the documentation of this file.
1/*
2 * This file is part of the saf_hades module.
3 * Copyright (c) 2021 - Leo McCormack & Janani Fernandez
4 *
5 * The saf_hades module is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 *
10 * The saf_hades module is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * See <http://www.gnu.org/licenses/> for a copy of the GNU General Public
16 * License.
17 */
18
38#ifndef __SAF_HADES_INTERNAL_H_INCLUDED__
39#define __SAF_HADES_INTERNAL_H_INCLUDED__
40
41#include "saf_hades_analysis.h"
42#include "saf_hades_synthesis.h"
43#include "saf.h"
44#include "saf_externals.h"
45
46#ifdef __cplusplus
47extern "C" {
48#endif /* __cplusplus */
49
50#ifdef SAF_ENABLE_HADES_MODULE
51
53#define HADES_MAX_BLOCKSIZE ( 4096 )
54
56typedef struct _CxMic{
57 float_complex Cx[HADES_MAX_NMICS*HADES_MAX_NMICS];
58}CxMic;
59
60/* ========================================================================== */
61/* Main Internal Structs */
62/* ========================================================================== */
63
65typedef struct _hades_analysis_data
66{
67 /* User parameters (defined at intialisation stage) */
68 float fs;
70 int hopsize;
73 float* h_array;
75 int nGrid;
76 int nMics;
77 int h_len;
81 /* Optional user parameters (that can also be manipulated at run-time) */
84 /* Time-frequency transform and array data */
85 void* hFB_enc;
86 int nBands;
89 float* freqVector;
90 float_complex* DCM_array;
91 float_complex* H_array;
92 float_complex* H_array_w;
94 /* DoA and diffuseness estimator data */
95 void* hEig;
96 float_complex** T;
97 void* hDoA;
99 float_complex* W;
101 /* Run-time variables */
102 float** inputBlock;
104 float_complex* V;
105 float_complex* Vn;
106 float* lambda;
109
111typedef struct _hades_synthesis_data
112{
113 /* User parameters */
117 int refIndices[2];
120 /* Optional user parameters (that can also be manipulated at run-time) */
121 float* eq;
125 /* Things relevant to the synthesiser, which are copied from the hades_analysis_create() to keep everything aligned */
127 int nBands;
130 int nGrid;
131 int nMics;
132 float_complex* H_array;
136 float* freqVector;
137 float_complex* DCM_array;
138 float_complex* W;
140 /* Time-frequency transform */
141 void* hFB_dec;
143 /* HRTF and diffuse rendering variables */
144 float_complex* H_bin;
145 float_complex* DCM_bin_norm;
146 float* diffEQ;
148 /* Run-time variables */
149 void* hPinv;
150 void* hLinSolve;
151 void* hCDF;
152 float_complex* As;
153 float_complex* As_l;
154 float_complex* As_r;
155 float_complex* Q_diff;
156 float_complex* Q_dir;
157 float_complex* Q;
158 float_complex* Cy;
159 float_complex* new_M;
160 float_complex** M;
162 /* Run-time audio buffers */
163 float_complex*** outTF;
164 float** outTD;
167
169typedef struct _hades_param_container_data {
170 int nBands;
172 /* Estimated Parameters */
173 float* diffuseness;
174 int* doa_idx;
177 /* Optional parameters */
178 float* gains_dir;
179 float* gains_diff;
182
184typedef struct _hades_radial_editor_data {
185 int nBands;
186 int nGrid;
191
193typedef struct _hades_signal_container_data {
194 int nMics;
195 int nBands;
198 /* Covariance matrices and signal statistics computed during the analysis */
201 /* TF frame to carry over to a decoder */
202 float_complex*** inTF;
205
206
207/* ========================================================================== */
208/* Internal Functions */
209/* ========================================================================== */
210
223void hades_getInterpolatedHRTFs(/* Input Arguments */
224 hades_analysis_handle const hAna,
225 HADES_HRTF_INTERP_OPTIONS interpOption,
226 hades_binaural_config* binConfig,
227 float* target_dirs_deg,
228 int nTargetDirs,
229 /* Output Arguments */
230 float_complex* hrtf_interp);
231
240void hades_sdMUSIC_create(void ** const phMUSIC,
241 int nMics,
242 float* grid_dirs_deg,
243 int nDirs);
244
252void hades_sdMUSIC_destroy(void ** const phMUSIC);
253
269void hades_sdMUSIC_compute(/* Input arguments */
270 void* const hMUSIC,
271 float_complex* A_grid,
272 float_complex* Vn,
273 int nSrcs,
274 /* Output arguments */
275 float* P_music,
276 int* peak_inds);
277
289float hades_comedie(float* lambda,
290 int N);
291
292#endif /* SAF_ENABLE_HADES_MODULE */
293
294
295#ifdef __cplusplus
296} /* extern "C" */
297#endif /* __cplusplus */
298
299#endif /* __SAF_HADES_INTERNAL_H_INCLUDED__ */
Main include header for the Spatial_Audio_Framework (SAF)
Include header for SAF externals.
Header for the HADES analysis (SAF_HADES_MODULE)
#define HADES_MAX_NMICS
Maximum number of microphones.
struct _hades_analysis_data * hades_analysis_handle
Handle for the hades analysis data.
HADES_FILTERBANKS
Filterbank options.
HADES_DOA_ESTIMATORS
Options for DoA estimation for hades_analysis.
HADES_DIFFUSENESS_ESTIMATORS
Options for diffuseness estimation for hades_analysis.
void hades_sdMUSIC_destroy(void **const phMUSIC)
Destroys an instance of the spherical harmonic domain MUSIC implementation, which may be used for com...
void hades_sdMUSIC_create(void **const phMUSIC, int nMics, float *grid_dirs_deg, int nDirs)
Creates an instance of the space-domain MUSIC implementation.
void hades_getInterpolatedHRTFs(hades_analysis_handle const hAna, HADES_HRTF_INTERP_OPTIONS interpOption, hades_binaural_config *binConfig, float *target_dirs_deg, int nTargetDirs, float_complex *hrtf_interp)
Binaural filter interpolator.
void hades_sdMUSIC_compute(void *const hMUSIC, float_complex *A_grid, float_complex *Vn, int nSrcs, float *P_music, int *peak_inds)
Computes a pseudo-spectrum based on the MUSIC algorithm optionally returning the grid indices corresp...
float hades_comedie(float *lambda, int N)
Returns an estimate of the diffuseness, based on [1].
Header for the HADES synthesis (SAF_HADES_MODULE)
HADES_BEAMFORMER_TYPE
Beamforming options for hades_synthesis.
HADES_HRTF_INTERP_OPTIONS
HRTF interpolation options for hades_synthesis.
Helper struct for averaging covariance matrices (block-wise)
Main structure for hades analysis.
int nMics
Number of microphones.
float covAvgCoeff
Temporal averaging coefficient [0 1].
float_complex ** T
for covariance whitening; nBands x (nMics x nMics)
int blocksize
Number of samples to process at a time (note that 1 doa and diffuseness estimate is made per block)
int hybridmode
Optionally, the lowest TF bands may be subdivided to improve low-freq resolution.
void * hEig
handle for the eigen solver
float_complex * DCM_array
Diffuse covariance matrix (computed over all grid directions and weighted); FLAT: nBands x nMics x nM...
float * grid_dirs_xyz
Scanning grid coordinates (unit vectors and only used by grid-based estimators); FLAT: nGrid x 3.
float * h_array
Array impulse responses; FLAT: nGrid x nMics x h_len.
float * freqVector
Centre frequencies; nBands x 1.
HADES_DOA_ESTIMATORS doaOpt
see HADES_DOA_ESTIMATORS
float * grid_dirs_deg
Array grid dirs in degrees; FLAT: nGrid x 2.
float ** inputBlock
Input frame; nMics x blocksize.
int hopsize
Filterbank hop size (blocksize must be divisable by this.
float_complex * V
Eigen vectors; FLAT: nMics x nMics.
HADES_FILTERBANKS fbOpt
see HADES_FILTERBANKS
float_complex * H_array_w
Array IRs in the frequency domain spatially weightend; FLAT: nBands x nMics x nDirs.
void * hFB_enc
Time-frequency transform handle.
float_complex * W
Diffuse integration weighting matrix; FLAT: nGrid x nGrid.
int h_len
Length of impulse responses, in samples.
float * lambda
Eigenvalues; nMics x 1.
CxMic * Cx
Current (time-averaged) covariance matrix per band; nBands x 1.
float_complex * H_array
Array IRs in the frequency domain; FLAT: nBands x nMics x nDirs.
float fs
Host samplerate, Hz.
int filterbankDelay
Filterbank delay, in time-domain samples.
int nBands
Number of frequency bands.
void * hDoA
DoA estimator handle.
int timeSlots
Number of time slots.
float_complex * Vn
Noise subspace; FLAT: nMics x (nMics-1)
HADES_DIFFUSENESS_ESTIMATORS diffOpt
see HADES_DIFFUSENESS_ESTIMATORS
int nGrid
Number of grid/scanning directions.
Binaural configuration struct.
Parameter container to store the data from an analyser for one blocksize of audio.
int * gains_idx
Reproduction direction index per band; nBands x 1.
int * doa_idx
Beamforming direction index per band; nBands x 1.
float * diffuseness
Diffuseness value per band; nBands x 1.
float * gains_diff
Extra diffuse reproduction gain per band (default=1.0f); nBands x 1
float * gains_dir
Extra direct reproduction gain per band (default=1.0f); nBands x 1
Main structure for hades radial (360degree) gain and direct-to-diffuse ratio editor.
float * pGrid_dirs_deg
Pointer to grid dirs in degrees; FLAT: nGrid x 2.
float * pGrid_dirs_xyz
Pointer to grid dirs as Cartesian coordinates of unit length; FLAT: nGrid x 3.
int nGrid
Number of grid/scanning directions.
Signal container to store one block of TF-domain audio data.
int nBands
Number of bands in the time-frequency transform.
int nMics
Number of spherical harmonic components.
int timeSlots
Number of time frames in time-frequency transform.
CxMic * Cx
NON-time-averaged covariance matrix per band; nBands x .Cx(nMics x nMics)
float_complex *** inTF
Input frame in TF-domain; nBands x nMics x timeSlots.
Main structure for hades synthesis.
float ** outTD
output time-domain buffer; NUM_EARS x blocksize
void * hLinSolve
Handle for solving linear equations (Ax=b)
int blocksize
blocksize in samples
void * hCDF
Handle for solving the covariance matching problem.
float_complex ** M
Mixing matrix per band; nBands x FLAT: (NUM_EARS x nMics)
float synAvgCoeff
Mixing matrix averaging coefficent [0..1].
HADES_FILTERBANKS fbOpt
Filterbank option, see HADES_FILTERBANKS.
float_complex * new_M
New mixing matrix (not yet temporally averaged); FLAT: NUM_EARS x nMics.
int nBands
Number of bands in the time-frequency transform domain.
float_complex * H_array
Array IRs in the frequency domain; FLAT: nBands x nMics x nGrid.
float_complex * As
Array steering vector for DoA; FLAT: nMics x 1.
float * eq
Gain factor per band; nBands x 1.
int timeSlots
Number of time frames in the time-frequency transform domain.
float_complex * H_bin
To spatialise the source beamformers; FLAT: nBands x NUM_EARS x nGrid.
HADES_BEAMFORMER_TYPE beamOption
see HADES_BEAMFORMER_TYPE
int enableCM
Flag: whether the spatial covariance matching is enabled (1) or disabled (0)
hades_binaural_config * binConfig
Internal copy of user configuration.
float * freqVector
Frequency vector (band centre frequencies); nBands x 1.
float * grid_dirs_deg
Array grid dirs in degrees; FLAT: nGrid x 2.
int nGrid
Number of grid/scanning directions.
float_complex * Q
Mixing matrix for the direct and diffuse streams combined (based on the diffuseness value); FLAT: NUM...
float_complex * As_r
Array steering vector relative to right reference sensor; FLAT: nMics x 1.
float * diffEQ
EQ curve to bring the overall diffuse-field magnitude response of the array to that of the HRTFs inst...
void * hPinv
Handle for computing the Moore-Penrose pseudo inverse.
float_complex * DCM_array
Diffuse coherence matrix for the array; FLAT: nBands x nMics x nMics.
int hopsize
hopsize in samples
float_complex * Cy
Target binaural spatial covariance matrix; FLAT: NUM_EARS x NUM_EARS.
float_complex *** outTF
nBands x NUM_EARS x timeSlots
float ** grid_dirs_xyz
Grid dirs as Cartesian coordinates of unit length; nGrid x 3.
float_complex * Q_dir
Mixing matrix for the direct stream; FLAT: NUM_EARS x nMics.
float_complex * DCM_bin_norm
Diffuse coherence matrix for the HRTF set, normalised with 1/trace(DCM_bin); FLAT: nBands x nMics x n...
float_complex * W
Diffuse integration weighting matrix; FLAT: nGrid x nGrid.
float_complex * Q_diff
Mixing matrix for the diffuse stream; FLAT: NUM_EARS x nMics.
HADES_HRTF_INTERP_OPTIONS interpOption
HRIR interpolation option, see HADES_HRTF_INTERP_OPTIONS.
float_complex * As_l
Array steering vector relative to left reference sensor; FLAT: nMics x 1.
void * hFB_dec
Filterbank handle.
int nMics
Number of microphones.
float * streamBalance
Stream balance per band (0:fully diffuse, 1:balanced, 2:fully direct); nBands x 1.