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
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 )
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/* ========================================================================== */
65/* Structures */
66/* ========================================================================== */
67
72typedef struct _spreader
73{
74 /* audio buffers and time-frequency transform */
75 float** inputFrameTD;
76 float** outframeTD;
77 float_complex*** inputframeTF;
78 float_complex*** protoframeTF;
79 float_complex*** decorframeTF;
80 float_complex*** spreadframeTF;
81 float_complex*** outputframeTF;
82 int fs;
83 float freqVector[HYBRID_BANDS];
84 void* hSTFT;
86 /* Internal */
87 int Q;
88 int nGrid;
89 int h_len;
90 float h_fs;
91 float* h_grid;
92 float_complex* H_grid;
93 float_complex** HHH[HYBRID_BANDS];
96 float* weights;
98 float* angles;
99 float_complex** Cproto[SPREADER_MAX_NUM_SOURCES];
100 float_complex** Cy[SPREADER_MAX_NUM_SOURCES];
101 float_complex** prev_M[SPREADER_MAX_NUM_SOURCES];
102 float** prev_Mr[SPREADER_MAX_NUM_SOURCES];
103 float_complex** new_M;
104 float** new_Mr;
105 float_complex* interp_M;
106 float* interp_Mr;
107 float_complex* interp_Mr_cmplx;
108 float interpolatorFadeIn[TIME_SLOTS];
109 float interpolatorFadeOut[TIME_SLOTS];
111 /* For visualisation */
112 int* dirActive[SPREADER_MAX_NUM_SOURCES];
114 /* Optimal mixing solution */
115 void* hCdf;
116 void* hCdf_res;
117 float* Qmix;
118 float_complex* Qmix_cmplx;
119 float* Cr;
120 float_complex* Cr_cmplx;
122 // Hotfix:
123 float_complex* _tmpFrame, *_H_tmp, *_Cy;
124 float_complex* _E_dir, *_V, *_D;
125 float_complex* _Cproto;
126
127 /* flags/status */
135 /* user parameters */
139 float src_spread[SPREADER_MAX_NUM_SOURCES];
140 float src_dirs_deg[SPREADER_MAX_NUM_SOURCES][2];
145
146
147/* ========================================================================== */
148/* Internal Functions */
149/* ========================================================================== */
150
152void spreader_setCodecStatus(void* const hSpr,
153 CODEC_STATUS newStatus);
154
155
156#ifdef __cplusplus
157} /* extern "C" { */
158#endif /* __cplusplus */
159
160#endif /* __SPREADER_INTERNAL_H_INCLUDED__ */
PROC_STATUS
Current status of the processing loop.
Definition _common.h:219
CODEC_STATUS
Current status of the codec.
Definition _common.h:201
#define TIME_SLOTS
Number of STFT timeslots.
#define HYBRID_BANDS
Number of frequency bands.
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
void spreader_setCodecStatus(void *const hSpr, CODEC_STATUS newStatus)
Sets codec status (see CODEC_STATUS enum)
Main structure for spreader.
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
float ** inputFrameTD
time-domain input frame; MAX_NUM_INPUTS x SPREADER_FRAME_SIZE
float covAvgCoeff
Covariance matrix averaging coefficient, [0..1].
void * hSTFT
afSTFT handle
int new_nSources
New number of input signals (current value will be replaced by this after next re-init)
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 progressBar0_1
Current (re)initialisation progress, between [0..1].
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.
int h_len
Length of time-domain filters, in samples.
float * Qmix
Identity; FLAT: Q x Q.
float_complex * Qmix_cmplx
Identity; FLAT: Q x Q.
float_complex *** outputframeTF
time-frequency domain output frame; HYBRID_BANDS x MAX_NUM_OUTPUTS x TIME_SLOTS
float_complex ** new_M
mixing matrices; HYBRID_BANDS x FLAT:(Q x Q)
SPREADER_PROC_MODES procMode
See SPREADER_PROC_MODES.
float ** new_Mr
residual mixing matrices; HYBRID_BANDS x FLAT:(Q x Q)
float h_fs
Sample rate used to measure the filters.
int useDefaultHRIRsFLAG
1: use default HRIRs in database, 0: use the measurements from SOFA file (can be anything,...
float ** outframeTD
time-domain output frame; MAX_NUM_OUTPUTS x SPREADER_FRAME_SIZE
PROC_STATUS procStatus
see PROC_STATUS
float_complex *** decorframeTF
time-frequency domain decorrelated frame; HYBRID_BANDS x MAX_NUM_OUTPUTS x TIME_SLOTS
char * progressBarText
Current (re)initialisation step, string.
char * sofa_filepath
SOFA file path.
float * Cr
Residual covariance; FLAT: Q x Q.
SPREADER_PROC_MODES new_procMode
See SPREADER_PROC_MODES (current value will be replaced by this after next re-init)
int Q
Number of channels in the target playback setup; for example: 2 for binaural.
float * angles
angles; nGrid x 1
float * interp_Mr
Interpolated residual mixing matrix; FLAT:(Q x Q)
int nSources
Current number of input signals.
CODEC_STATUS codecStatus
see CODEC_STATUS
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.
int nGrid
Number of directions/measurements/HRTFs etc.
float * weights
Integration weights; nGrid x 1.
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.