33 *phTVCnv = (
void*)pData;
40 pData->inputFrameTD = NULL;
41 pData->outputFrameTD = NULL;
49 pData->sofa_filepath = NULL;
62 pData->nListenerPositions = 0;
63 pData->position_idx = 0;
64 for (
int d = 0; d < NUM_DIMENSIONS; d++){
65 pData->sourcePosition[d] = 0.0f;
66 pData->targetPosition[d] = 0.0f;
72 pData->progressBar0_1 = 0.0f;
74 strcpy(pData->progressBarText,
"");
94 free(pData->inputFrameTD);
95 free(pData->outputFrameTD);
128 float*
const*
const inputs,
129 float*
const*
const outputs,
137 int numInputChannels, numOutputChannels;
145 for(s=0; s<nSamples; s++){
148 pData->inFIFO[ch][pData->FIFO_idx] = inputs[ch][s];
149 for(; ch<numInputChannels; ch++)
150 pData->inFIFO[ch][pData->FIFO_idx] = 0.0f;
154 outputs[ch][s] = pData->outFIFO[ch][pData->FIFO_idx];
155 for(; ch<nOutputs; ch++)
156 outputs[ch][s] = 0.0f;
167 for(i=0; i < numInputChannels; i++)
170 if(pData->
hTVConv != NULL && pData->ir_length>0){
174 pData->position_idx);
218 if(pData->ir_length>0){
223 pData->nListenerPositions,
225 pData->position_idx);
246#ifdef SAF_ENABLE_SOFA_READER_MODULE
263 strcpy(pData->progressBarText,
"Initialising");
264 pData->progressBar0_1 = 0.0f;
266#ifdef SAF_ENABLE_SOFA_READER_MODULE
267 if(pData->sofa_filepath!=NULL){
268 strcpy(pData->progressBarText,
"Opening SOFA file");
269 pData->progressBar0_1 = 0.2f;
273 strcpy(pData->progressBarText,
"Loading IRs");
274 pData->progressBar0_1 = 0.5f;
289 pData->
irs = (
float**)
realloc2d((
void**)pData->
irs, pData->nListenerPositions, pData->
nIrChannels*pData->ir_length,
sizeof(float));
290 int tmp_length = pData->
nIrChannels * pData->ir_length;
291 for(i=0; i<pData->nListenerPositions; i++){
292 memcpy(pData->
irs[i], &(sofa.
DataIR[i*tmp_length]), tmp_length*
sizeof(
float));
295 strcpy(pData->progressBarText,
"Loading positions");
296 pData->progressBar0_1 = 0.8f;
325 pData->ir_length = 0;
326 saf_print_warning(
"This example requires SAF_ENABLE_SOFA_READER_MODULE to do anything");
329 pData->position_idx = 0;
334 strcpy(pData->progressBarText,
"Done!");
335 pData->progressBar0_1 = 1.0f;
342 pData->sofa_filepath =
malloc1d(strlen(path) + 1);
343 strcpy(pData->sofa_filepath, path);
351 saf_assert(dim >= 0 && dim < NUM_DIMENSIONS,
"Dimension out of scope");
352 pData->targetPosition[dim] = position;
399 return pData->position_idx;
405 saf_assert(dim >= 0 && dim < NUM_DIMENSIONS,
"Dimension out of scope");
406 return (
float) pData->targetPosition[dim];
412 saf_assert(dim >= 0 && dim < NUM_DIMENSIONS,
"Dimension out of scope");
413 return (
float) pData->sourcePosition[dim];
419 saf_assert(dim >= 0 && dim < NUM_DIMENSIONS,
"Dimension out of scope");
426 saf_assert(dim >= 0 && dim < NUM_DIMENSIONS,
"Dimension out of scope");
433 return pData->ir_length;
457 if(pData->sofa_filepath!=NULL)
458 return pData->sofa_filepath;
466 return pData->sofa_file_error;
472 return pData->codecStatus;
#define MAX_NUM_CHANNELS
Maximum number of input/output channels supported.
#define PROGRESSBARTEXT_CHAR_LENGTH
Length of progress bar string.
@ PROC_STATUS_ONGOING
Codec is processing input audio, and should not be reinitialised at this time.
@ PROC_STATUS_NOT_ONGOING
Codec is not processing input audio, and may be reinitialised if needed.
CODEC_STATUS
Current status of the codec.
@ CODEC_STATUS_NOT_INITIALISED
Codec has not yet been initialised, or the codec configuration has changed.
@ CODEC_STATUS_INITIALISED
Codec is initialised and ready to process input audio.
@ CODEC_STATUS_INITIALISING
Codec is currently being initialised, input audio should not be processed.
void saf_sofa_close(saf_sofa_container *c)
Frees all SOFA data in a sofa_container.
SAF_SOFA_ERROR_CODES saf_sofa_open(saf_sofa_container *h, char *sofa_filepath, SAF_SOFA_READER_OPTIONS option)
Fills a 'sofa_container' with data found in a SOFA file (GeneralFIR or SimpleFreeFieldHRIR),...
SAF_SOFA_ERROR_CODES
SOFA loader error codes.
@ SAF_SOFA_READER_OPTION_DEFAULT
The default option is SAF_SOFA_READER_OPTION_LIBMYSOFA.
@ SAF_SOFA_ERROR_INVALID_FILE_OR_FILE_PATH
Not a SOFA file, or no such file was found in the specified location.
@ SAF_SOFA_ERROR_NETCDF_IN_USE
NetCDF is not thread safe!
@ SAF_SOFA_OK
None of the error checks failed.
@ SAF_SOFA_ERROR_FORMAT_UNEXPECTED
The data-type of the SOFA data was not as expected.
@ SAF_SOFA_ERROR_DIMENSIONS_UNEXPECTED
Dimensions of the SOFA data were not as expected.
#define saf_assert(x, message)
Macro to make an assertion, along with a string explaining its purpose.
#define SAF_CLAMP(a, min, max)
Ensures value "a" is clamped between the "min" and "max" values.
void saf_TVConv_apply(void *const hTVC, float *inputSig, float *outputSig, int irIdx)
Performs the matrix convolution.
void saf_TVConv_create(void **const phTVC, int hopSize, float **H, int length_h, int nIRs, int nCHout, int initIdx)
Creates an instance of TVConv.
void utility_svvcopy(const float *a, const int len, float *c)
Single-precision, vector-vector copy, i.e.
void saf_TVConv_destroy(void **const phTVC)
Destroys an instance of matrixConv.
#define SAF_MIN(a, b)
Returns the minimum of the two values.
void unitSph2cart(float *dirs, int nDirs, int anglesInDegreesFLAG, float *dirs_xyz)
Converts spherical coordinates to Cartesian coordinates of unit length.
#define saf_print_warning(message)
Macro to print a warning message along with the filename and line number.
#define MIN_FRAME_SIZE
Minimum framesize, in time-domain samples.
#define MAX_FRAME_SIZE
Maximum framesize, in time-domain samples.
void ** realloc2d(void **ptr, size_t dim1, size_t dim2, size_t data_size)
2-D realloc which does NOT retain previous data order
void * malloc1d(size_t dim1_data_size)
1-D malloc (same as malloc, but with error checking)
void * realloc1d(void *ptr, size_t dim1_data_size)
1-D realloc (same as realloc, but with error checking)
void ** calloc2d(size_t dim1, size_t dim2, size_t data_size)
2-D calloc (contiguously allocated, so use free() as usual to deallocate)
#define FLATTEN2D(A)
Use this macro when passing a 2-D dynamic multi-dimensional array to memset, memcpy or any other func...
SOFA container struct comprising all possible data that can be extracted from SOFA 1....
int DataLengthIR
Length of the IRs, in samples.
float * SourcePosition
Source positions (refer to SourcePositionType & SourcePositionUnits for the convention and units); FL...
int nListeners
Number of listener positions.
char * SourcePositionType
{'cartesian'|'spherical'}
float * ListenerPosition
Listener position (The object incorporating all receivers; refer to ListenerPositionType & ListenerPo...
float DataSamplingRate
Sampling rate used to measure the IRs.
int nReceivers
Number of ears/number of mics etc.
float * DataIR
The impulse response (IR) Data; FLAT:nSources x nReceivers x DataLengthIR.
Main structure for tvconv
int host_fs
current samplerate of the host
int nOutputChannels
number of output channels (same as the number of channels in the loaded wav)
int reInitFilters
FLAG: 0: do not reinit, 1: reinit, 2: reinit in progress.
int hostBlockSize
current host block size
float ** irs
npositionsx x (FLAT: nfilters x filter_length)
int nIrChannels
number of filters per position
vectorND minDimensions
Minimum values across all dimensions.
int hostBlockSize_clamped
Clamped between MIN and MAX_FRAME_SIZE.
void * hTVConv
saf_TVConv handle
int nInputChannels
number of input channels
vectorND maxDimensions
Maximum values across all dimensions.
vectorND * listenerPositions
The listener positions; nListenerPositions x 3.
float tvconv_getListenerPosition(void *const hTVCnv, int index, int dim)
Returns the current coordinate of dimension dim (0 ... NUM_DIMENSIONS-1)
void tvconv_process(void *const hTVCnv, float *const *const inputs, float *const *const outputs, int nInputs, int nOutputs, int nSamples)
Performs the time-varying convolution processing.
int tvconv_getIRFs(void *const hTVCnv)
Returns the samplerate of the loaded filters
void tvconv_refreshParams(void *const hTVCnv)
Sets all intialisation flags to 1.
int tvconv_getProcessingDelay(void *const hTVCnv)
Returns the processing delay in samples (may be used for delay compensation features)
CODEC_STATUS tvconv_getCodecStatus(void *const hTVCnv)
Returns current codec status (see CODEC_STATUS enum)
void tvconv_setFiltersAndPositions(void *const hTVCnv)
Reads IRs and positions from the current sofa file path.
char * tvconv_getSofaFilePath(void *const hTVCnv)
Returns the current Sofa file path.
void tvconv_create(void **const phTVCnv)
Creates an instance of tvconv.
float tvconv_getSourcePosition(void *const hTVCnv, int dim)
Returns the source coordinate of dimension dim (0 ... NUM_DIMENSIONS-1)
void tvconv_setTargetPosition(void *const hTVCnv, float position, int dim)
Sets the target listener position.
int tvconv_getIRLength(void *const hTVCnv)
Returns the current filter length, in samples.
int tvconv_getNumListenerPositions(void *const hTVCnv)
Returns the number of listener positions in the loaded sofa file.
int tvconv_getNumIRs(void *const hTVCnv)
Returns the number of IR channels in the loaded sofa file.
int tvconv_getHostBlockSize(void *const hTVCnv)
Returns the currect host block size.
int tvconv_getHostFs(void *const hTVCnv)
Returns the samperate of the host.
SAF_TVCONV_ERROR_CODES tvconv_getSofaErrorState(void *const hTVCnv)
Returns the current Sofa file error state.
void tvconv_setSofaFilePath(void *const hTVCnv, const char *path)
Sets current sofa file path.
int tvconv_getListenerPositionIdx(void *const hTVCnv)
Returns the index of the current IR position.
float tvconv_getMinDimension(void *const hTVCnv, int dim)
Returns minimum cooridinate of dimension dim (0 ... NUM_DIMENSIONS-1)
float tvconv_getTargetPosition(void *const hTVCnv, int dim)
Returns the current coordinate of dimension dim (0 ... NUM_DIMENSIONS-1)
void tvconv_init(void *const hTVCnv, int sampleRate, int hostBlockSize)
Initialises an instance of tvconv with default settings.
float tvconv_getMaxDimension(void *const hTVCnv, int dim)
Returns minimum cooridinate of dimension dim (0 ... NUM_DIMENSIONS-1)
int tvconv_getNumInputChannels(void *const hTVCnv)
Returns the number input channels.
int tvconv_getNumOutputChannels(void *const hTVCnv)
Returns the number of output channels (the same as the number of channels in the loaded sofa file)
void tvconv_checkReInit(void *const hTVCnv)
Checks whether things have to be reinitialised, and does so if it is needed.
void tvconv_destroy(void **const phTVCnv)
Destroys an instance of tvconv.
A time-varying multi-channel convolver.
SAF_TVCONV_ERROR_CODES
SOFA loader error codes.
@ SAF_TVCONV_SOFA_ERROR_INVALID_FILE_OR_FILE_PATH
Not a SOFA file, or no such file was found in the specified location.
@ SAF_TVCONV_SOFA_ERROR_NETCDF_IN_USE
NetCDF is not thread safe!
@ SAF_TVCONV_SOFA_ERROR_FORMAT_UNEXPECTED
The data-type of the SOFA data was not as expected.
@ SAF_TVCONV_SOFA_ERROR_DIMENSIONS_UNEXPECTED
Dimensions of the SOFA data were not as expected.
@ SAF_TVCONV_SOFA_OK
None of the error checks failed.
@ SAF_TVCONV_NOT_INIT
Not initialized.
@ SAF_TVCONV_SOFA_LOADING
Loading file.
void tvconv_findNearestNeigbour(void *const hTVCnv)
Finds the index holding the nearest neigbour to the selected position.
void tvconv_setCodecStatus(void *const hTVCnv, CODEC_STATUS newStatus)
Sets codec status (see CODEC_STATUS enum)
void tvconv_setMinMaxDimensions(void *const hTVCnv)
Sets the smallest and the highest position of each dimension from the list of positions.
A time-varying multi-channel convolver.
float vectorND[NUM_DIMENSIONS]
Structure for a vector.