SAF
Loading...
Searching...
No Matches
array2sh_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
50#ifndef __ARRAY2SH_INTERNAL_H_INCLUDED__
51#define __ARRAY2SH_INTERNAL_H_INCLUDED__
52
53#include "array2sh.h" /* Include header for this example */
54#include "saf.h" /* Main include header for SAF */
55#include "saf_externals.h" /* To also include SAF dependencies (cblas etc.) */
56
57#ifdef __cplusplus
58extern "C" {
59#endif /* __cplusplus */
60
61/* ========================================================================== */
62/* Internal Parameters */
63/* ========================================================================== */
64
65#if !defined(ARRAY2SH_FRAME_SIZE)
66# if defined(FRAME_SIZE) /* Use the global framesize if it is specified: */
67# define ARRAY2SH_FRAME_SIZE ( FRAME_SIZE )
68# else /* Otherwise, the default framesize for this example is: */
69# define ARRAY2SH_FRAME_SIZE ( 128 )
70# endif
71#endif
72#define HOP_SIZE ( 128 )
73#define HYBRID_BANDS ( HOP_SIZE + 5 )
74#define TIME_SLOTS ( ARRAY2SH_FRAME_SIZE / HOP_SIZE )
75#define MAX_NUM_SENSORS ( ARRAY2SH_MAX_NUM_SENSORS )
76#define MAX_EVAL_FREQ_HZ ( 20e3f )
77#define MAX_NUM_SENSORS_IN_PRESET ( MAX_NUM_SENSORS )
79/* Checks: */
80#if (ARRAY2SH_FRAME_SIZE % HOP_SIZE != 0)
81# error "ARRAY2SH_FRAME_SIZE must be an integer multiple of HOP_SIZE"
82#endif
83
84/* ========================================================================== */
85/* Structures */
86/* ========================================================================== */
87
89typedef struct _array2sh_arrayPars {
90 int Q;
91 int newQ;
92 float r;
93 float R;
96 float sensorCoords_rad[MAX_NUM_SENSORS][2];
97 float sensorCoords_deg[MAX_NUM_SENSORS][2];
100
105typedef struct _array2sh
106{
107 /* audio buffers */
108 float** inputFrameTD;
109 float** SHframeTD;
110 float_complex*** inputframeTF;
111 float_complex*** SHframeTF;
113 /* intermediates */
114 double_complex bN_modal[HYBRID_BANDS][MAX_SH_ORDER + 1];
115 double_complex* bN;
116 double_complex bN_inv[HYBRID_BANDS][MAX_SH_ORDER + 1];
117 double_complex bN_inv_R[HYBRID_BANDS][MAX_NUM_SH_SIGNALS];
121 /* for displaying the bNs */
122 float** bN_modal_dB;
123 float** bN_inv_dB;
124 float* cSH;
125 float* lSH;
127 /* time-frequency transform and array details */
128 float freqVector[HYBRID_BANDS];
129 void* hSTFT;
132 /* internal parameters */
136 int fs;
139 /* For diffuse-field equalisation */
140 double_complex* L_diff_fal;
141 double_complex* L_diff;
142 double_complex* E_diff;
143 double_complex* W_diffEQ_tmp;
144 double_complex* W_tmp;
145
146 /* flags */
151 /* additional user parameters that are not included in the array presets */
152 int order;
155 float regPar;
158 float c;
159 float gain_dB;
163
164
165/* ========================================================================== */
166/* Internal Functions */
167/* ========================================================================== */
168
174void array2sh_initTFT(void* const hA2sh);
175
180void array2sh_calculate_sht_matrix(void* const hA2sh);
181
186void array2sh_apply_diff_EQ(void* const hA2sh);
187
192void array2sh_calculate_mag_curves(void* const hA2sh);
193
202void array2sh_evaluateSHTfilters(void* hA2sh);
203
210void array2sh_createArray(void ** const hPars);
211
218void array2sh_destroyArray(void ** const hPars);
219
230void array2sh_initArray(void * const hPars,
232 int* arrayOrder,
233 int firstInitFLAG);
234
235
236#ifdef __cplusplus
237} /* extern "C" { */
238#endif /* __cplusplus */
239
240#endif /* __ARRAY2SH_INTERNAL_H_INCLUDED__ */
#define MAX_SH_ORDER
Maximum supported Ambisonic order.
Definition _common.h:52
PROC_STATUS
Current status of the processing loop.
Definition _common.h:219
NORM_TYPES
Available Ambisonic normalisation conventions.
Definition _common.h:74
CH_ORDER
Available Ambisonic channel ordering conventions.
Definition _common.h:59
#define MAX_NUM_SH_SIGNALS
Maximum number of spherical harmonic components/signals supported.
Definition _common.h:239
#define HYBRID_BANDS
Number of frequency bands.
Spatially encodes spherical microphone array signals into spherical harmonic signals (aka: Ambisonic ...
ARRAY2SH_MICROPHONE_ARRAY_PRESETS
Available microphone array presets.
Definition array2sh.h:105
ARRAY2SH_FILTER_TYPES
Available encoding filter approaches.
Definition array2sh.h:134
ARRAY2SH_WEIGHT_TYPES
List of supported sensor directivities and array construction types.
Definition array2sh.h:166
ARRAY2SH_ARRAY_TYPES
List of supported array types.
Definition array2sh.h:156
ARRAY2SH_EVAL_STATUS
Current status of the encoder evaluation output data.
Definition array2sh.h:186
void array2sh_evaluateSHTfilters(void *hA2sh)
Evaluates the spherical harmonic transform performance with the currently configured microphone/hydro...
void array2sh_calculate_sht_matrix(void *const hA2sh)
Computes the spherical harmonic transform (SHT) matrix, to spatially encode input microphone/hydropho...
void array2sh_initTFT(void *const hA2sh)
Initialise the filterbank used by array2sh.
void array2sh_initArray(void *const hPars, ARRAY2SH_MICROPHONE_ARRAY_PRESETS preset, int *arrayOrder, int firstInitFLAG)
Intialises an instance of a struct based on a preset, which contains the array configuration data.
void array2sh_calculate_mag_curves(void *const hA2sh)
Computes the magnitude responses of the equalisation filters; the absolute values of the regularised ...
#define MAX_NUM_SENSORS
Maximum permitted number of inputs/sensors.
void array2sh_apply_diff_EQ(void *const hA2sh)
Applies diffuse-field equalisation at frequencies above the spatial aliasing limit.
void array2sh_destroyArray(void **const hPars)
Destroys an instance of a struct, which contains the array configuration data.
void array2sh_createArray(void **const hPars)
Creates an instance of a struct, which contains the array configuration data.
Main include header for the Spatial_Audio_Framework (SAF)
Include header for SAF externals.
Contains variables for describing the microphone/hydrophone array.
int Q
Current number of sensors.
float R
radius of scatterer (only for rigid arrays)
ARRAY2SH_ARRAY_TYPES arrayType
see ARRAY2SH_ARRAY_TYPES
ARRAY2SH_WEIGHT_TYPES weightType
see ARRAY2SH_WEIGHT_TYPES
int newQ
New number of sensors (current value replaced by this after next re-init)
float r
radius of sensors
Main structure for array2sh.
float ** SHframeTD
Output SH signals in the time-domain; MAX_NUM_SH_SIGNALS x ARRAY2SH_FRAME_SIZE.
float_complex *** inputframeTF
Input sensor signals in the time-domain; HYBRID_BANDS x MAX_NUM_SENSORS x TIME_SLOTS.
int fs
sampling rate, hz
float progressBar0_1
Current (re)initialisation progress, between [0..1].
double_complex * bN
Temp vector for the modal coefficients.
PROC_STATUS procStatus
see PROC_STATUS
char * progressBarText
Current (re)initialisation step, string.
float c
speed of sound, m/s
void * hSTFT
filterbank handle
float ** bN_modal_dB
modal responses / no regulaisation; HYBRID_BANDS x (MAX_SH_ORDER +1)
void * arraySpecs
array configuration
float gain_dB
post gain, dB
float ** inputFrameTD
Input sensor signals in the time-domain; MAX_NUM_SENSORS x ARRAY2SH_FRAME_SIZE.
float_complex *** SHframeTF
Output SH signals in the time-domain; HYBRID_BANDS x MAX_NUM_SH_SIGNALS x TIME_SLOTS.
ARRAY2SH_EVAL_STATUS evalStatus
see ARRAY2SH_EVAL_STATUS
float * cSH
spatial correlation; HYBRID_BANDS x 1
int reinitSHTmatrixFLAG
0: do not reinit; 1: reinit;
int new_order
new encoding order (current value will be replaced by this after next re-init)
float ** bN_inv_dB
modal responses / with regularisation; HYBRID_BANDS x (MAX_SH_ORDER +1)
float regPar
regularisation upper gain limit, dB;
float * lSH
level difference; HYBRID_BANDS x 1
NORM_TYPES norm
Ambisonic normalisation convention (see NORM_TYPES)
ARRAY2SH_MICROPHONE_ARRAY_PRESETS preset
currently selected MIC preset
ARRAY2SH_FILTER_TYPES filterType
encoding filter approach
int enableDiffEQpastAliasing
0: disabled, 1: enabled
int order
current encoding order
int evalRequestedFLAG
0: do not reinit; 1: reinit;
CH_ORDER chOrdering
Ambisonic channel order convention (see CH_ORDER)