SAF
Loading...
Searching...
No Matches
powermap_internal.c
Go to the documentation of this file.
1/*
2 * Copyright 2016-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
32#include "powermap.h"
33#include "powermap_internal.h"
34
35void powermap_setCodecStatus(void* const hPm, CODEC_STATUS newStatus)
36{
37 powermap_data *pData = (powermap_data*)(hPm);
38 if(newStatus==CODEC_STATUS_NOT_INITIALISED){
39 /* Pause until current initialisation is complete */
41 SAF_SLEEP(10);
42 }
43 pData->codecStatus = newStatus;
44}
45
46void powermap_initAna(void* const hPm)
47{
48 powermap_data *pData = (powermap_data*)(hPm);
49 powermap_codecPars* pars = pData->pars;
50 int i, j, n, N_azi, N_ele, nSH_order, order;
51 float scaleY, hfov, vfov, fi, aspectRatio;
52 float* Y_grid_N, *grid_x_axis, *grid_y_axis;
53
54 order = pData->new_masterOrder;
55
56 /* Store Y_grid per order */
57 int geosphere_ico_freq = 9;
58 pars->grid_dirs_deg = (float*)__HANDLES_geosphere_ico_dirs_deg[geosphere_ico_freq];
59 pars->grid_nDirs = __geosphere_ico_nPoints[geosphere_ico_freq];
60 Y_grid_N = malloc1d(((order+1)*(order+1))*(pars->grid_nDirs)*sizeof(float));
61 getRSH(order, pars->grid_dirs_deg, pars->grid_nDirs, Y_grid_N);
62 for(n=1; n<=order; n++){
63 nSH_order = (n+1)*(n+1);
64 scaleY = 1.0f/(float)nSH_order;
65 free(pars->Y_grid[n-1]);
66 free(pars->Y_grid_cmplx[n-1]);
67 pars->Y_grid[n-1] = malloc1d(nSH_order * (pars->grid_nDirs)*sizeof(float));
68 pars->Y_grid_cmplx[n-1] = malloc1d(nSH_order * (pars->grid_nDirs)*sizeof(float_complex));
69 memcpy(pars->Y_grid[n-1], Y_grid_N, nSH_order * (pars->grid_nDirs)*sizeof(float));
70 utility_svsmul(pars->Y_grid[n-1], &scaleY, nSH_order * (pars->grid_nDirs), NULL);
71 for(i=0; i<nSH_order; i++)
72 for(j=0; j<pars->grid_nDirs; j++)
73 pars->Y_grid_cmplx[n-1][i*(pars->grid_nDirs)+j] = cmplxf(pars->Y_grid[n-1][i*(pars->grid_nDirs)+j], 0.0f);
74 }
75
76 /* generate interpolation table for current display settings */
77 switch(pData->HFOVoption){
78 default:
79 case HFOV_360: hfov = 360.0f; break;
80 }
81 switch(pData->aspectRatioOption){
82 default:
83 case ASPECT_RATIO_2_1: aspectRatio = 2.0f; break;
84 }
85 N_azi = pData->dispWidth;
86 N_ele = (int)((float)pData->dispWidth/aspectRatio + 0.5f);
87 grid_x_axis = malloc1d(N_azi * sizeof(float));
88 grid_y_axis = malloc1d(N_ele * sizeof(float));
89 vfov = hfov/aspectRatio;
90 for(fi = -hfov/2.0f, i = 0; i<N_azi; fi+=hfov/N_azi, i++)
91 grid_x_axis[i] = fi;
92 for(fi = -vfov/2.0f, i = 0; i<N_ele; fi+=vfov/N_ele, i++)
93 grid_y_axis[i] = fi;
94 free(pars->interp_dirs_deg);
95 pars->interp_dirs_deg = malloc1d(N_azi*N_ele*2*sizeof(float));
96 for(i = 0; i<N_ele; i++){
97 for(j=0; j<N_azi; j++){
98 pars->interp_dirs_deg[(i*N_azi + j)*2] = grid_x_axis[j];
99 pars->interp_dirs_deg[(i*N_azi + j)*2+1] = grid_y_axis[i];
100 }
101 }
102 free(pars->interp_table);
103 generateVBAPgainTable3D_srcs(pars->interp_dirs_deg, N_azi*N_ele, pars->grid_dirs_deg, pars->grid_nDirs, 0, 0, 0.0f, &(pars->interp_table), &(pars->interp_nDirs), &(pars->interp_nTri));
105
106 /* reallocate memory for storing the powermaps */
107 free(pData->pmap);
108 pData->pmap = malloc1d(pars->grid_nDirs*sizeof(float));
109 free(pData->prev_pmap);
110 pData->prev_pmap = calloc1d(pars->grid_nDirs, sizeof(float));
111 for(i=0; i<NUM_DISP_SLOTS; i++){
112 free(pData->pmap_grid[i]);
113 pData->pmap_grid[i] = calloc1d(pars->interp_nDirs,sizeof(float));
114 }
115
116 pData->masterOrder = order;
117
118 free(Y_grid_N);
119 free(grid_x_axis);
120 free(grid_y_axis);
121}
122
124(
125 void* const hPm
126)
127{
128 powermap_data *pData = (powermap_data*)(hPm);
129 int nSH, new_nSH;
130
131 nSH = (pData->masterOrder+1)*(pData->masterOrder+1);
132 new_nSH = (pData->new_masterOrder+1)*(pData->new_masterOrder+1);
133 if(pData->hSTFT==NULL)
134 afSTFT_create(&(pData->hSTFT), new_nSH, 0, HOP_SIZE, 0, 1, AFSTFT_BANDS_CH_TIME);
135 else if(nSH!=new_nSH){
136 afSTFT_channelChange(pData->hSTFT, new_nSH, 0);
138 memset(pData->Cx, 0 , MAX_NUM_SH_SIGNALS*MAX_NUM_SH_SIGNALS*HYBRID_BANDS*sizeof(float_complex));
139 }
140}
@ HFOV_360
360 degrees
Definition _common.h:180
#define MAX_NUM_SH_SIGNALS
Maximum number of spherical harmonic components/signals supported.
Definition _common.h:239
CODEC_STATUS
Current status of the codec.
Definition _common.h:201
@ CODEC_STATUS_NOT_INITIALISED
Codec has not yet been initialised, or the codec configuration has changed.
Definition _common.h:204
@ CODEC_STATUS_INITIALISING
Codec is currently being initialised, input audio should not be processed.
Definition _common.h:207
@ ASPECT_RATIO_2_1
ASPECT_RATIO_2_1 - 2:1.
Definition _common.h:189
void afSTFT_clearBuffers(void *const hSTFT)
Flushes time-domain buffers with zeros.
Definition afSTFTlib.c:519
void afSTFT_create(void **const phSTFT, int nCHin, int nCHout, int hopsize, int lowDelayMode, int hybridmode, AFSTFT_FDDATA_FORMAT format)
Creates an instance of afSTFT.
Definition afSTFTlib.c:143
void afSTFT_channelChange(void *const hSTFT, int new_nCHin, int new_nCHout)
Re-allocates memory to support a change in the number of input/output channels.
Definition afSTFTlib.c:477
@ AFSTFT_BANDS_CH_TIME
nBands x nChannels x nTimeHops
Definition afSTFTlib.h:80
#define HOP_SIZE
STFT hop size.
#define HYBRID_BANDS
Number of frequency bands.
#define NUM_DISP_SLOTS
Number of display slots.
void getRSH(int N, float *dirs_deg, int nDirs, float *Y)
Computes real-valued spherical harmonics [1] for each given direction on the unit sphere.
Definition saf_hoa.c:119
const int __geosphere_ico_nPoints[17]
3LD geosphere number of points (freq = [0 0], [1 0],..., [16 0])
const float * __HANDLES_geosphere_ico_dirs_deg[17]
3LD geosphere HANDLES (freq = [0 0], [1 0],..., [16 0])
void utility_svsmul(float *a, const float *s, const int len, float *c)
Single-precision, multiplies each element in vector 'a' with a scalar 's', i.e.
void generateVBAPgainTable3D_srcs(float *src_dirs_deg, int S, float *ls_dirs_deg, int L, int omitLargeTriangles, int enableDummies, float spread, float **gtable, int *N_gtable, int *nTriangles)
Generates a 3-D VBAP [1] gain table based on specified source and loudspeaker directions,...
Definition saf_vbap.c:53
void VBAPgainTable2InterpTable(float *vbap_gtable, int nTable, int nDirs)
Renormalises a VBAP gain table (in-place) so it may be utilised for interpolation of data (for exampl...
Definition saf_vbap.c:370
void * malloc1d(size_t dim1_data_size)
1-D malloc (same as malloc, but with error checking)
Definition md_malloc.c:59
void * calloc1d(size_t dim1, size_t data_size)
1-D calloc (same as calloc, but with error checking)
Definition md_malloc.c:69
A sound-field visualiser, which utilises spherical harmonic signals as input; note this code is a rem...
void powermap_setCodecStatus(void *const hPm, CODEC_STATUS newStatus)
Sets codec status (see CODEC_STATUS enum)
void powermap_initTFT(void *const hPm)
Initialise the filterbank used by powermap.
void powermap_initAna(void *const hPm)
Intialises the codec variables, based on current global/user parameters.
A sound-field visualiser, which utilises spherical harmonic signals as input; note this code is a rem...
Contains variables for scanning grids, and beamforming.
float_complex * Y_grid_cmplx[MAX_SH_ORDER]
real SH basis (complex datatype); MAX_NUM_SH_SIGNALS x grid_nDirs
float * interp_dirs_deg
2D rectangular window interpolation directions, in degrees; FLAT: interp_nDirs x 2
float * interp_table
Spherical->2D interpolation table; FLAT: interp_nDirs x grid_nDirs.
int grid_nDirs
Number of scanning directions.
float * Y_grid[MAX_SH_ORDER]
real SH basis (real datatype); MAX_NUM_SH_SIGNALS x grid_nDirs
float * grid_dirs_deg
Spherical scanning grid directions, in degrees; FLAT: grid_nDirs x 2.
int interp_nTri
Number of triangles in the spherical triangulared grid.
int interp_nDirs
Number of interpolation directions.
Main structure for powermap.
powermap_codecPars * pars
codec parameters
int dispWidth
Number of pixels on the horizontal in the 2D interpolated powermap image.
float * prev_pmap
grid_nDirs x 1
int new_masterOrder
New maximum/master SH analysis order (current value will be replaced by this after next re-init)
HFOV_OPTIONS HFOVoption
see HFOV_OPTIONS
CODEC_STATUS codecStatus
see CODEC_STATUS
int masterOrder
Current maximum/master SH analysis order.
float * pmap
grid_nDirs x 1
ASPECT_RATIO_OPTIONS aspectRatioOption
see ASPECT_RATIO_OPTIONS
float_complex Cx[HYBRID_BANDS][MAX_NUM_SH_SIGNALS *MAX_NUM_SH_SIGNALS]
covariance matrices per band
float * pmap_grid[NUM_DISP_SLOTS]
powermap interpolated to grid; interp_nDirs x 1
void * hSTFT
afSTFT handle