SAF
Loading...
Searching...
No Matches
spreader_internal.h
Go to the documentation of this file.
1/*
2 * Copyright 2021 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
31
32#ifndef __SPREADER_INTERNAL_H_INCLUDED__
33#define __SPREADER_INTERNAL_H_INCLUDED__
34
35#include "spreader.h" /* Include header for this example */
36#include "saf.h" /* Main include header for SAF */
37#include "saf_externals.h" /* To also include SAF dependencies (cblas etc.) */
38
39#ifdef __cplusplus
40extern "C" {
41#endif /* __cplusplus */
42
43/* ========================================================================== */
44/* Internal Parameters */
45/* ========================================================================== */
46
47#if !defined(SPREADER_FRAME_SIZE)
48# if defined(FRAME_SIZE) /* Use the global framesize if it is specified: */
49# define SPREADER_FRAME_SIZE ( FRAME_SIZE )
50# else /* Otherwise, the default framesize for this example is: */
51# define SPREADER_FRAME_SIZE ( 512 )
52# endif
53#endif
54#define MAX_SPREAD_FREQ ( 16e3f )
55#define HOP_SIZE ( 128 )
56#define HYBRID_BANDS ( HOP_SIZE + 5 )
57#define TIME_SLOTS ( SPREADER_FRAME_SIZE / HOP_SIZE )
58
59/* Checks: */
60#if (SPREADER_FRAME_SIZE % HOP_SIZE != 0)
61# error "SPREADER_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 SPREADER_PROC_MODES _Atomic_SPREADER_PROC_MODES;
66#else
67 typedef SPREADER_PROC_MODES _Atomic_SPREADER_PROC_MODES;
68#endif
69
70/* ========================================================================== */
71/* Structures */
72/* ========================================================================== */
73
78typedef struct _spreader
79{
80 /* audio buffers and time-frequency transform */
81 float** inputFrameTD;
82 float** outframeTD;
83 float_complex*** inputframeTF;
84 float_complex*** protoframeTF;
85 float_complex*** decorframeTF;
86 float_complex*** spreadframeTF;
87 float_complex*** outputframeTF;
88 int fs;
90 void* hSTFT;
91
92 /* Internal */
93 _Atomic_INT32 Q;
94 _Atomic_INT32 nGrid;
95 _Atomic_INT32 h_len;
96 _Atomic_FLOAT32 h_fs;
97 float* h_grid;
98 float_complex* H_grid;
99 float_complex** HHH[HYBRID_BANDS];
102 float* weights;
104 float* angles;
106 float_complex** Cy[SPREADER_MAX_NUM_SOURCES];
109 float_complex** new_M;
110 float** new_Mr;
111 float_complex* interp_M;
112 float* interp_Mr;
113 float_complex* interp_Mr_cmplx;
116
117 /* For visualisation */
119
120 /* Optimal mixing solution */
121 void* hCdf;
122 void* hCdf_res;
123 float* Qmix;
124 float_complex* Qmix_cmplx;
125 float* Cr;
126 float_complex* Cr_cmplx;
127
128 // Hotfix:
129 float_complex* _tmpFrame, *_H_tmp, *_Cy;
130 float_complex* _E_dir, *_V, *_D;
131 float_complex* _Cproto;
132
133 /* flags/status */
134 _Atomic_CODEC_STATUS codecStatus;
135 _Atomic_FLOAT32 progressBar0_1;
137 _Atomic_PROC_STATUS procStatus;
138 _Atomic_INT32 new_nSources;
139 _Atomic_SPREADER_PROC_MODES new_procMode;
140
141 /* user parameters */
142 _Atomic_SPREADER_PROC_MODES procMode;
144 _Atomic_INT32 nSources;
147 _Atomic_INT32 useDefaultHRIRsFLAG;
148 _Atomic_FLOAT32 covAvgCoeff;
149
151
152
153/* ========================================================================== */
154/* Internal Functions */
155/* ========================================================================== */
156
158void spreader_setCodecStatus(void* const hSpr,
159 CODEC_STATUS newStatus);
160
161
162#ifdef __cplusplus
163} /* extern "C" { */
164#endif /* __cplusplus */
165
166#endif /* __SPREADER_INTERNAL_H_INCLUDED__ */
CODEC_STATUS
Current status of the codec.
Definition _common.h:205
Main include header for the Spatial_Audio_Framework (SAF)
Include header for SAF externals.
An arbitrary array panner (HRIRs, microphone array IRs, etc.) with coherent and incoherent spreading ...
SPREADER_PROC_MODES
Available processing modes.
Definition spreader.h:55
#define SPREADER_MAX_NUM_SOURCES
Maximum number of sources supported by the spreader example.
Definition spreader.h:52
#define TIME_SLOTS
Number of STFT timeslots.
void spreader_setCodecStatus(void *const hSpr, CODEC_STATUS newStatus)
Sets codec status (see CODEC_STATUS enum)
#define HYBRID_BANDS
Number of frequency bands.
Main structure for spreader.
_Atomic_FLOAT32 covAvgCoeff
Covariance matrix averaging coefficient, [0..1].
float interpolatorFadeOut[TIME_SLOTS]
Linear Interpolator - Fade out.
_Atomic_INT32 h_len
Length of time-domain filters, in samples.
void * hCdf_res
covariance domain framework handle for the residual
int fs
Host sampling rate, in Hz.
float_complex *** spreadframeTF
time-frequency domain spread frame; HYBRID_BANDS x MAX_NUM_OUTPUTS x TIME_SLOTS
_Atomic_CODEC_STATUS codecStatus
see CODEC_STATUS
float ** inputFrameTD
time-domain input frame; MAX_NUM_INPUTS x SPREADER_FRAME_SIZE
_Atomic_FLOAT32 h_fs
Sample rate used to measure the filters.
void * hSTFT
afSTFT handle
float_complex ** prev_M[SPREADER_MAX_NUM_SOURCES]
previous mixing matrices; HYBRID_BANDS x FLAT:(Q x Q)
float_complex *** inputframeTF
time-frequency domain input frame; HYBRID_BANDS x MAX_NUM_INPUTS x TIME_SLOTS
float_complex * interp_Mr_cmplx
Complex variant of interp_Mr.
float * h_grid
FLAT: nGrid x Q x h_len.
float * grid_dirs_xyz
Grid directions as unit-length Cartesian coordinates; FLAT: nGrid x 3.
float_complex ** Cy[SPREADER_MAX_NUM_SOURCES]
Target covariance matrices; HYBRID_BANDS x FLAT:(Q x Q)
float * Qmix
Identity; FLAT: Q x Q.
float_complex * Qmix_cmplx
Identity; FLAT: Q x Q.
float_complex ** HHH[HYBRID_BANDS]
Pre-computed array outer-products; HYBRID_BANDS x nGrid x FLAT: (Q x Q)
float ** prev_Mr[SPREADER_MAX_NUM_SOURCES]
previous residual mixing matrices; HYBRID_BANDS x FLAT:(Q x Q)
float_complex *** outputframeTF
time-frequency domain output frame; HYBRID_BANDS x MAX_NUM_OUTPUTS x TIME_SLOTS
void * hDecor[SPREADER_MAX_NUM_SOURCES]
handles for decorrelators
_Atomic_INT32 Q
Number of channels in the target playback setup; for example: 2 for binaural.
float_complex ** new_M
mixing matrices; HYBRID_BANDS x FLAT:(Q x Q)
float ** new_Mr
residual mixing matrices; HYBRID_BANDS x FLAT:(Q x Q)
int * dirActive[SPREADER_MAX_NUM_SOURCES]
1: IR direction currently used for spreading, 0: not
_Atomic_FLOAT32 src_spread[SPREADER_MAX_NUM_SOURCES]
Source spreading, in degrees.
float ** outframeTD
time-domain output frame; MAX_NUM_OUTPUTS x SPREADER_FRAME_SIZE
float_complex *** decorframeTF
time-frequency domain decorrelated frame; HYBRID_BANDS x MAX_NUM_OUTPUTS x TIME_SLOTS
char * progressBarText
Current (re)initialisation step, string.
_Atomic_FLOAT32 src_dirs_deg[SPREADER_MAX_NUM_SOURCES][2]
Source directions, in degrees.
char * sofa_filepath
SOFA file path.
float * Cr
Residual covariance; FLAT: Q x Q.
_Atomic_SPREADER_PROC_MODES new_procMode
See SPREADER_PROC_MODES (current value will be replaced by this after next re-init)
float_complex ** Cproto[SPREADER_MAX_NUM_SOURCES]
Current prototype covariance matrices; HYBRID_BANDS x FLAT:(Q x Q)
float freqVector[HYBRID_BANDS]
Frequency vector (filterbank centre frequencies)
float * angles
angles; nGrid x 1
_Atomic_INT32 nSources
Current number of input signals.
float * interp_Mr
Interpolated residual mixing matrix; FLAT:(Q x Q)
_Atomic_INT32 new_nSources
New number of input signals (current value will be replaced by this after next re-init)
_Atomic_INT32 useDefaultHRIRsFLAG
1: use default HRIRs in database, 0: use the measurements from SOFA file (can be anything,...
_Atomic_FLOAT32 progressBar0_1
Current (re)initialisation progress, between [0..1].
float_complex * H_grid
FLAT: HYBRID_BANDS x Q x nGrid.
void * hCdf
covariance domain framework handle
float * grid_dirs_deg
Grid directions, in degrees; FLAT: nGrid x 2.
_Atomic_PROC_STATUS procStatus
see PROC_STATUS
float interpolatorFadeIn[TIME_SLOTS]
Linear Interpolator - Fade in.
float * weights
Integration weights; nGrid x 1.
_Atomic_SPREADER_PROC_MODES procMode
See SPREADER_PROC_MODES.
_Atomic_INT32 nGrid
Number of directions/measurements/HRTFs etc.
float_complex * interp_M
Interpolated mixing matrix; FLAT:(Q x Q)
float_complex *** protoframeTF
time-frequency domain prototype frame; HYBRID_BANDS x MAX_NUM_OUTPUTS x TIME_SLOTS
float_complex * Cr_cmplx
Residual covariance; FLAT: Q x Q.