SAF
Loading...
Searching...
No Matches
test__sofa_reader_module.c
Go to the documentation of this file.
1/*
2 * Copyright 2020-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
25#include "saf_test.h"
26
27#ifndef SAF_TEST_SOFA_FILE_PATH
28# define SAF_TEST_SOFA_FILE_PATH "/Users/mccorml1/Documents/FABIAN_HRTF_DATABASE_V1/1 HRIRs/SOFA/FABIAN_HRIR_measured_HATO_20.sofa"
29#endif
30
31#ifdef SAF_ENABLE_SOFA_READER_MODULE
32
36 for(int i=0; i<1 /* increase if timing... */; i++){
37 /* Note that saf_sofa_open() reverts to mysofa_load(), if SAF_ENABLE_NETCDF is not defined */
38 error = saf_sofa_open(&sofa, SAF_TEST_SOFA_FILE_PATH, SAF_SOFA_READER_OPTION_DEFAULT);
39 saf_sofa_close(&sofa);
40 }
41}
42
44 int err;
45 struct MYSOFA_HRTF *hrtf;
46 for(int i=0; i<1 /* increase if timing... */; i++){
47 hrtf = mysofa_load(SAF_TEST_SOFA_FILE_PATH, &err);
48 mysofa_free(hrtf);
49 }
50}
51
53#ifdef SAF_ENABLE_NETCDF
56 int err;
57 struct MYSOFA_HRTF *hrtf;
58
59 /* Load the same SOFA file */
60 error = saf_sofa_open(&sofa, SAF_TEST_SOFA_FILE_PATH, SAF_SOFA_READER_OPTION_NETCDF);
61 hrtf = mysofa_load(SAF_TEST_SOFA_FILE_PATH, &err);
62
63 /* If both SOFA loaders were successful */
64 if(error==SAF_SOFA_OK && err==MYSOFA_OK){
65 /* Check that data is equivalent */
66 for(unsigned int i=0; i<hrtf->M * hrtf->R * hrtf->N; i++)
67 TEST_ASSERT_TRUE(fabsf(sofa.DataIR[i]- hrtf->DataIR.values[i])<0.000001f);
68 for(unsigned int i=0; i<hrtf->M * hrtf->C; i++)
69 TEST_ASSERT_TRUE(fabsf(sofa.SourcePosition[i]- hrtf->SourcePosition.values[i])<0.000001f);
70 for(unsigned int i=0; i<hrtf->M * hrtf->C; i++)
71 TEST_ASSERT_TRUE(fabsf(sofa.SourcePosition[i]- hrtf->SourcePosition.values[i])<0.000001f);
72 for(unsigned int i=0; i<hrtf->_I * hrtf->R; i++)
73 TEST_ASSERT_TRUE(fabsf(sofa.DataDelay[i]- hrtf->DataDelay.values[i])<0.000001f);
74 }
75
76 saf_sofa_close(&sofa);
77 mysofa_free(hrtf);
78#endif /* SAF_ENABLE_NETCDF */
79}
80
81#endif /* SAF_ENABLE_SOFA_READER_MODULE */
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_READER_OPTION_NETCDF
If SAF_ENABLE_NETCDF is defined, then an alternative SOFA reader may be used.
@ SAF_SOFA_OK
None of the error checks failed.
Unit test program for the Spatial_Audio_Framework.
SOFA container struct comprising all possible data that can be extracted from SOFA 1....
float * DataDelay
Delay in samples; nReceivers x 1.
float * SourcePosition
Source positions (refer to SourcePositionType & SourcePositionUnits for the convention and units); FL...
float * DataIR
The impulse response (IR) Data; FLAT:nSources x nReceivers x DataLengthIR.
void test__mysofa_load(void)
Testing the dependency free mysofa SOFA reader.
void test__saf_sofa_open(void)
Testing the SAF SOFA reader that uses the netcdf library.
void test__sofa_comparison(void)
Testing that the two SOFA readers produce the same results.