SAF
Loading...
Searching...
No Matches
saf_reverb_internal.h
Go to the documentation of this file.
1/*
2 * Copyright 2020 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
29#ifndef __REVERB_INTERNAL_H_INCLUDED__
30#define __REVERB_INTERNAL_H_INCLUDED__
31
32#include "saf_reverb.h"
33#include "saf_externals.h"
35#include "../saf_sh/saf_sh.h"
36
37#ifdef __cplusplus
38extern "C" {
39#endif /* __cplusplus */
40
41/* ========================================================================== */
42/* IMS Shoebox Room Simulator */
43/* ========================================================================== */
44
46#define IMS_NUM_WALLS_SHOEBOX ( 6 )
48#define IMS_FIR_FILTERBANK_ORDER ( 400 )
50#define IMS_IIR_FILTERBANK_ORDER ( 3 )
52#define IMS_CIRC_BUFFER_LENGTH ( 4*8192U )
54#define IMS_CIRC_BUFFER_LENGTH_MASK ( IMS_CIRC_BUFFER_LENGTH - 1U )
56#define IMS_MAX_NSAMPLES_PER_FRAME ( 20000 )
58#define IMS_LAGRANGE_ORDER ( 2 )
60#define IMS_LAGRANGE_LOOKUP_TABLE_SIZE ( 100 )
62#define IMS_EG_CURRENT ( 0 )
64#define IMS_EG_PREV ( 1 )
66#define IMS_EG_NUM_SLOTS ( 2 )
68#define IMS_UNASSIGNED ( -1 )
69
72typedef void* voidPtr;
73
75typedef struct _ims_pos_xyz {
76 union {
77 struct { float x;
78 float y;
79 float z;
80 };
81 float v[3];
82 };
84
86typedef enum {
88 // RECEIVER_ARRAY /**< Microphone array/HRIR measurements-based receiver */
89
91
93typedef struct _ims_src_obj
94{
95 float* sig;
97 int ID;
100
102typedef struct _ims_rec_obj
103{
104 float** sigs;
108 int ID;
111
113typedef struct _echogram_data
114{
115 /* The echogram data: */
118 float** value;
120 float* time;
122 int** order;
130 /* Optional helper variables for run-time speed-ups */
132 float* tmp1;
133 float* tmp2;
134 int* rIdx;
136 int* rIdx_frac[IMS_LAGRANGE_ORDER];
139 float** h_frac;
141 float** cb_vals;
143 float** contrib;
145 float* ones_dummy;
149
155typedef struct _ims_core_workspace
156{
157 /* Locals */
158 float room[3];
159 float d_max;
160 int N_max;
163 int nBands;
165 /* Internal */
166 int Nx, Ny, Nz;
167 int lengthVec, numImageSources;
168 int* validIDs;
169 int* s_ord;
170 float* II, *JJ, *KK;
171 int* iII, *iJJ, *iKK;
172 float* s_x, *s_y, *s_z, *s_d, *s_t, *s_att;
173
174 /* Echograms */
176 void* hEchogram;
186 /* Room impulse responses (only used/allocated when a render function is
187 * called) */
188 int refreshRIRFLAG;
189 int rir_len_samples;
190 float rir_len_seconds;
191 float*** rir_bands; /* nBands x nChannels x rir_len_samples */
192
194
200typedef struct _ims_scene_data
201{
202 /* Locals */
203 float room_dims[3];
204 float c_ms;
205 float fs;
206 int nBands;
207 float** abs_wall;
209 /* Source and receiver positions */
212 long nSources;
215 /* Internal */
220 float** H_filt;
223 /* Circular buffers (only used/allocated when applyEchogramTD() function is
224 * called for the first time) */
226 float*** circ_buffer[IMS_EG_NUM_SLOTS];
228 /* IIR filterbank (only used/allocated when applyEchogramTD() function is
229 * called for the first time) */
231 float*** src_sigs_bands;
233 /* Temporary receiver frame used for cross-fading (only used/allocated when
234 * applyEchogramTD() function is called for the first time) */
235 float*** rec_sig_tmp[IMS_EG_NUM_SLOTS];
238 float* tmp_frame;
239 int applyCrossFadeFLAG[IMS_MAX_NUM_RECEIVERS][IMS_MAX_NUM_SOURCES];
242 /* Lagrange interpolator look-up table */
243 float lookup_fractions[IMS_LAGRANGE_LOOKUP_TABLE_SIZE];
245
247
248
249/* =========================== Internal Functions =========================== */
250
260void ims_shoebox_coreWorkspaceCreate(void** phWork,
261 int nBands);
262
268void ims_shoebox_coreWorkspaceDestroy(void** phWork);
269
277void ims_shoebox_echogramCreate(void** phEcho,
278 int include_rt_vars);
279
290void ims_shoebox_echogramResize(void* hEcho,
291 int numImageSources,
292 int nChannels);
293
303void ims_shoebox_echogramCopy(void* hEchoX,
304 void* hEchoY);
305
311void ims_shoebox_echogramDestroy(void** phEcho);
312
343void ims_shoebox_coreInitT(void* hWork,
344 float room[3],
345 ims_pos_xyz src,
346 ims_pos_xyz rec,
347 float maxTime,
348 float c_ms);
349
361void ims_shoebox_coreInitN(void* hWork,
362 float room[3],
363 ims_pos_xyz src,
364 ims_pos_xyz rec,
365 int maxN,
366 float c_ms);
367
377void ims_shoebox_coreRecModuleSH(void* hWork,
378 int sh_order);
379
392void ims_shoebox_coreAbsorptionModule(void* hWork,
393 float** abs_wall);
394
406void ims_shoebox_renderRIR(void* hWork,
407 int fractionalDelayFLAG,
408 float fs,
409 float** H_filt,
410 ims_rir* rir);
411
412
413#ifdef __cplusplus
414} /* extern "C" */
415#endif /* __cplusplus */
416
417#endif /* __REVERB_INTERNAL_H_INCLUDED__ */
#define IMS_MAX_NUM_SOURCES
TODO: Arbitrary array receiver option; Directional source option; finish ims_shoebox_renderRIRs() fun...
Definition saf_reverb.h:52
#define IMS_MAX_NUM_RECEIVERS
Maximum number of receivers supported by an instance of the IMS simulator.
Definition saf_reverb.h:55
Include header for SAF externals.
Main header for the reverb processing module (SAF_REVERB_MODULE)
void ims_shoebox_coreWorkspaceCreate(void **phWork, int nBands)
Creates an instance of the core workspace.
RECEIVER_TYPES
Supported receiver types.
@ RECEIVER_SH
Spherical harmonic receiver.
#define IMS_LAGRANGE_ORDER
Order of lagrange interpolation filters.
void ims_shoebox_coreWorkspaceDestroy(void **phWork)
Destroys an instance of the core workspace.
void ims_shoebox_coreRecModuleSH(void *hWork, int sh_order)
Imposes spherical harmonic directivies onto the echogram computed with ims_shoebox_coreInit() for a s...
#define IMS_LAGRANGE_LOOKUP_TABLE_SIZE
Lagrange interpolator look-up table size.
void ims_shoebox_echogramResize(void *hEcho, int numImageSources, int nChannels)
Resizes an echogram container.
void ims_shoebox_coreAbsorptionModule(void *hWork, float **abs_wall)
Applies boundary absoption per frequency band, onto the echogram computed with ims_shoebox_coreRecMod...
void ims_shoebox_renderRIR(void *hWork, int fractionalDelayFLAG, float fs, float **H_filt, ims_rir *rir)
Renders a room impulse response for a specific source/reciever combination.
void ims_shoebox_echogramCreate(void **phEcho, int include_rt_vars)
Creates an instance of an echogram container.
void ims_shoebox_echogramCopy(void *hEchoX, void *hEchoY)
Copies echogram data from container 'X' into container 'Y' (also resizing 'Y' as needed)
void ims_shoebox_coreInitN(void *hWork, float room[3], ims_pos_xyz src, ims_pos_xyz rec, int maxN, float c_ms)
Calculates an echogram of a rectangular space using the image source method, for a specific source/re...
void ims_shoebox_echogramDestroy(void **phEcho)
Destroys an instance of an echogram container.
void * voidPtr
Void pointer (just to improve code readability when working with arrays of handles)
void ims_shoebox_coreInitT(void *hWork, float room[3], ims_pos_xyz src, ims_pos_xyz rec, float maxTime, float c_ms)
Calculates an echogram of a rectangular space using the image source method, for a specific source/re...
#define IMS_EG_NUM_SLOTS
Number of echogram slots.
Main header for the Spherical Harmonic Transform and Spherical Array Processing module (SAF_SH_MODULE...
Main header for the utilities module (SAF_UTILITIES_MODULE)
Echogram structure.
float ** value
Echogram magnitudes per image source and channel; nChannels x numImageSources.
float ** contrib
Total contribution (i.e.
int numImageSources
Number of image sources in current echogram.
int ** order
Reflection order for each image and dimension; numImageSources x 3.
int * rIdx
Current circular buffer read indices; numImageSources x 1.
ims_pos_xyz * coords
Reflection coordinates (Cartesian); numImageSources x 3.
int nChannels
Number of channels.
float ** h_frac
Current fractional delay coeffs; (IMS_LAGRANGE_ORDER+1) x numImageSources x.
float ** cb_vals
Current circular buffer values (per channel & image source); nChannels x numImageSources.
int include_rt_vars
0: the below vars are disabled, 1: enabled
float * time
Propagation time (in seconds) for each image source; numImageSources x 1.
int * sortedIdx
Indices that sort the echogram based on propagation time in ascending order; numImageSources x 1.
float * tmp1
1st temporary vector; numImageSources x 1
float * ones_dummy
Just a vector of ones, for the cblas_sdot sum hack, and fmodf; numImageSources x 1.
float * tmp2
2nd temporary vector; numImageSources x 1
Helper structure, comprising variables used when computing echograms and rendering RIRs.
void * hEchogram_rec
Echogram with the receiver directivities applied (multi-channel)
voidPtr * hPrevEchogram_abs
Previous echograms (hEchogram_abs), one per band, which can be used for cross- fading.
ims_pos_xyz rec
Receiver position.
voidPtr * hEchogram_abs
Echograms with the receiver directivities and also wall absorption applied (multi- channel); one echo...
int refreshEchogramFLAG
1: Refresh needed, 0: refresh not needed
void * hEchogram
Pressure echogram (single-channel)
int N_max
Maximum reflection order.
ims_pos_xyz src
Source position.
int nBands
Number of bands.
float d_max
Maximum distance, in meters.
Union struct for Cartesian coordinates (access as .x,.y,.z, or .v[3])
float y
y Cartesian coordinate, in metres
float z
z Cartesian coordinate, in metres
float x
x Cartesian coordinate, in metres
Receiver object.
RECEIVER_TYPES type
Receiver type (see RECEIVER_TYPES enum)
int nChannels
Number of channels for receiver.
ims_pos_xyz pos
Receiver position.
int ID
Unique receiver ID.
float ** sigs
Receiver signal pointers (one per channel)
Output format of the rendered room impulse responses (RIR)
Definition saf_reverb.h:58
Main structure for IMS.
float * band_cutofffreqs
Octave band CUTOFF frequencies; (nBands-1) x 1.
long nSources
Current number of sources.
float c_ms
Speed of sound, in ms^1.
float * interpolator_fIn
framesize x 1
int nBands
Number of frequency bands.
float ** abs_wall
Wall aborption coeffs per wall; nBands x 6.
float *** src_sigs_bands
nSources x nBands x nSamples
float * band_centerfreqs
Octave band CENTRE frequencies; nBands x 1.
float * tmp_frame
framesize x 1
int framesize
Curent framesize in samples.
long nReceivers
Current number of receivers.
voidPtr ** hCoreWrkSpc
One per source/receiver combination.
ims_rir ** rirs
One per source/receiver combination.
float ** H_filt
nBands x (IMS_FIR_FILTERBANK_ORDER+1)
float * interpolator_fOut
framesize x 1
float fs
Sampling rate.
voidPtr * hFaFbank
One per source.
Source object.
ims_pos_xyz pos
Source position.
int ID
Unique source ID.
float * sig
Source signal pointer.