SAF
Loading...
Searching...
No Matches
safmex_generateVBAPgainTable3D.c
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
25#include "safmex.h"
26
27/* ===================================================================== */
28/* Config */
29/* ===================================================================== */
30
31#define NUM_INPUT_ARGS ( 6 )
32#define NUM_OUTPUT_ARGS ( 1 )
33const MEX_DATA_TYPES inputDataTypes[NUM_INPUT_ARGS] = {
40};
41const MEX_DATA_TYPES outputDataTypes[NUM_OUTPUT_ARGS] = {
43};
44
45
46/* ===================================================================== */
47/* MEX Wrapper */
48/* ===================================================================== */
49
50void mexFunction
51(
52 int nlhs, /* Number of output argments */
53 mxArray *plhs[], /* Pointers for output arguments */
54 int nrhs, /* Number of input argments */
55 const mxArray *prhs[] /* Pointers for input arguments */
56)
57{
58 /* check for proper number of arguments and input argument datatypes */
59 checkNumInOutArgs(nrhs, nlhs, NUM_INPUT_ARGS, NUM_OUTPUT_ARGS);
60 checkArgDataTypes((mxArray**)prhs, (MEX_DATA_TYPES*)inputDataTypes, NUM_INPUT_ARGS);
61
62 /* mex variables */
63 int nDims;
64 int *pDims = NULL;
65
66 /* saf variables */
67 float* ls_dirs_deg = NULL;
68 float* gtable = NULL;
69 int L, az_res_deg, el_res_deg, omitLargeTriangles, enableDummies;
70 int N_gtable, nTriangles;
71 float spread;
72
73 /* prep */
74 MEXdouble2SAFsingle(prhs[0], &ls_dirs_deg, &nDims, &pDims);
75 L = pDims[0];
76 az_res_deg = (int)mxGetScalar(prhs[1]);
77 el_res_deg = (int)mxGetScalar(prhs[2]);
78 omitLargeTriangles = (int)mxGetScalar(prhs[3]);
79 enableDummies = (int)mxGetScalar(prhs[4]);
80 spread = (float)mxGetScalar(prhs[5]);
81
82 /* any extra checks */
83 if(pDims[1]!=2)
84 mexErrMsgIdAndTxt("MyToolbox:inputError","the second dimension of the first argument should be of size: 2");
85
86 /* call SAF function */
87// snprintf(message, MSG_STR_LENGTH, "L = %d,\n", L); mexPrintf(message);
88// snprintf(message, MSG_STR_LENGTH, "az_res_deg = %d,\n", az_res_deg); mexPrintf(message);
89// snprintf(message, MSG_STR_LENGTH, "el_res_deg = %d,\n", el_res_deg); mexPrintf(message);
90// snprintf(message, MSG_STR_LENGTH, "omitLargeTriangles = %d,\n", omitLargeTriangles); mexPrintf(message);
91// snprintf(message, MSG_STR_LENGTH, "enableDummies = %d,\n", enableDummies); mexPrintf(message);
92// snprintf(message, MSG_STR_LENGTH, "spread = %.5f,\n", spread); mexPrintf(message);
93 generateVBAPgainTable3D(ls_dirs_deg, L, az_res_deg, el_res_deg, omitLargeTriangles,
94 enableDummies, spread, &gtable, &N_gtable, &nTriangles);
95
96 /* output */
97 nDims = 2;
98 pDims = realloc1d(pDims, nDims*sizeof(int));
99 pDims[0] = N_gtable;
100 pDims[1] = L;
101 SAFsingle2MEXdouble(gtable, nDims, pDims, &plhs[0]);
102
103 /* clean-up */
104 free(pDims);
105 free(ls_dirs_deg);
106 free(gtable);
107
108 /* check output argument datatypes */
109 checkArgDataTypes((mxArray**)plhs, (MEX_DATA_TYPES*)outputDataTypes, NUM_OUTPUT_ARGS);
110}
void generateVBAPgainTable3D(float *ls_dirs_deg, int L, int az_res_deg, int el_res_deg, int omitLargeTriangles, int enableDummies, float spread, float **gtable, int *N_gtable, int *nTriangles)
Generates a 3-D VBAP gain table based on specified loudspeaker directions, with optional spreading [2...
Definition saf_vbap.c:172
void * realloc1d(void *ptr, size_t dim1_data_size)
1-D realloc (same as realloc, but with error checking)
Definition md_malloc.c:79
Main include header for safmex.
void MEXdouble2SAFsingle(const mxArray *in, float **out, int *nDims, int **pDims)
Convert a mex double-precision array into single precision array for SAF.
Definition safmex.h:151
MEX_DATA_TYPES
Supported SAF/MEX data conversions.
Definition safmex.h:33
@ SM_DOUBLE_REAL
Scalar, real valued; 1 x 1.
Definition safmex.h:37
@ SM_INT32
Integer; 1 x 1.
Definition safmex.h:34
@ SM_DOUBLE_REAL_2D
Real 2-D matrix; N x M.
Definition safmex.h:43
void SAFsingle2MEXdouble(float *in, int nDims, int *dims, mxArray **out)
Convert a single precision array used by SAF to mex double-precision array.
Definition safmex.h:309
void checkNumInOutArgs(int nInputs, int nOutputs, int nInputs_expected, int nOutputs_expected)
Helper function to check number of inputs/outputs arguments are as expected.
Definition safmex.h:51
void checkArgDataTypes(mxArray **hData, MEX_DATA_TYPES *dataTypes, int nArgs)
Helper function to check the format of the input/output arguments are as expected.
Definition safmex.h:64