• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

build/H07-May-2022-109

cmake/H29-Nov-2021-4134

share/H03-May-2022-

src/H03-May-2022-8,4245,986

tests/H03-May-2022-637483

windows/H29-Nov-2021-3,4151,563

.cprojectH A D29-Nov-20215.6 KiB8786

.projectH A D29-Nov-2021762 2726

CODE_OF_CONDUCT.mdH A D29-Nov-20213.3 KiB7757

LICENSEH A D29-Nov-20211.4 KiB3325

README.mdH A D29-Nov-20216.9 KiB166118

SECURITY.mdH A D29-Nov-20211.6 KiB3017

libmysofa.pc.cmakeH A D29-Nov-2021309 1210

params.jsonH A D29-Nov-2021175 66

README.md

1<div align="right">
2<a href="https://mysofa.audio/">
3	<img alt="Symonics MySofa" width="320px" src="https://raw.githubusercontent.com/hoene/libmysofa/master/symonics-mysofa.png"/>
4</a>
5</div
6
7#
8
9# libmysofa
10
11## Introduction
12This is a simple set of C functions to read AES SOFA files, if they contain HRTFs
13stored according to the AES69-2015 standard [http://www.aes.org/publications/standards/search.cfm?docID=99].
14
15## Badges
16
17<div align="center">
18<a href="https://travis-ci.com/hoene/libmysofa">
19<img alt="Travis CI Status" src="https://travis-ci.com/hoene/libmysofa.svg?branch=master"/>
20</a>
21<a href="https://ci.appveyor.com/project/hoene/libmysofa-s142k">
22<img alt="AppVeyor Status" src="https://ci.appveyor.com/api/projects/status/mk86lx4ux2jn9tpo/branch/master?svg=true"/>
23</a>
24<a href="https://scan.coverity.com/projects/hoene-libmysofa">
25<img alt="Coverity Scan Build Status" src="https://scan.coverity.com/projects/13030/badge.svg"/>
26</a>
27<a href="https://codecov.io/gh/hoene/libmysofa">
28  <img src="https://codecov.io/gh/hoene/libmysofa/branch/master/graph/badge.svg" />
29</a>
30<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=GUN8R6NUQCS3C&source=url">
31<img src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif" alt="Donate with PayPal button" />
32</a>
33</div>
34
35## Compile
36
37On Ubuntu, to install the required components, enter
38
39> sudo apt install zlib1g-dev libcunit1-dev libcunit1-dev
40
41Then, to compile enter following commands
42
43> cd build
44
45> cmake -DCMAKE_BUILD_TYPE=Debug ..
46
47> make all test
48
49If you need an Debian package, call
50
51> cd build && cpack
52
53To check for memory leaks and crazy pointers
54
55> export ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer
56
57> export ASAN_OPTIONS=symbolize=1
58
59> cmake -DCMAKE_BUILD_TYPE=Debug -DADDRESS_SANITIZE=ON -DVDEBUG=1 ..
60
61> make all test
62
63
64## Usage
65
66Libmysofa has a few main function calls.
67
68To read a SOFA file call
69
70```
71#include <mysofa.h>
72
73int filter_length;
74int err;
75struct MYSOFA_EASY *hrtf = NULL;
76
77hrtf = mysofa_open("file.sofa", 48000, &filter_length, &err);
78if(hrtf==NULL)
79	return err;
80```
81
82This call will normalize your hrtf data upon opening. For non-normalized data, replace the call to mysofa_open by:
83
84```
85hrtf = mysofa_open_no_norm("file.sofa", 48000, &filter_length, &err);
86```
87
88Or for a complete control over neighbors search algorithm parameters:
89
90```
91bool norm = true; // bool, apply normalization upon import
92float neighbor_angle_step = 5; // in degree, neighbor search angle step (common to azimuth and elevation)
93float neighbor_radius_step = 0.01; // in meters, neighbor search radius step
94hrtf = mysofa_open_advanced("file.sofa", 48000, &filter_length, &err, norm, neighbor_angle_step, neighbor_radius_step);
95```
96
97(The greater the neighbor_*_step, the faster the neighbors search. The algorithm will end up skipping true nearest neighbors if these values are set too high. To be define based on the will-be-imported sofa files grid step. Default mysofa_open method is usually fast enough for classical hrtf grids not to bother with the advanced one.)
98
99To free the HRTF structure, call:
100```
101mysofa_close(hrtf);
102```
103
104If you need HRTF filter for a given coordinate, just call
105```
106short leftIR[filter_length];
107short rightIR[filter_length];
108int leftDelay;          // unit is samples
109int rightDelay;         // unit is samples
110
111mysofa_getfilter_short(hrtf, x, y, z, leftIR, rightIR, &leftDelay, &rightDelay);
112```
113and then delay the audio signal by leftDelay and rightDelay samples and do a FIR filtering with leftIR and rightIR. Alternative, if you are using float values for the filtering, call
114```
115float leftIR[filter_length]; // [-1. till 1]
116float rightIR[filter_length];
117float leftDelay;          // unit is sec.
118float rightDelay;         // unit is sec.
119
120mysofa_getfilter_float(hrtf, x, y, z, leftIR, rightIR, &leftDelay, &rightDelay);
121```
122
123using ``mysofa_getfilter_float_nointerp`` instead of ``mysofa_getfilter_float`` (same arguments), you can bypass the linear interpolation applied by ``mysofa_getfilter_float`` (weighted sum of nearest neighbors filters coefficients), and get the exact filter stored in the sofa file nearest to the [x,y,z] position requested.
124
125If you have spherical coordinates but you need Cartesian coordinates, call
126```
127void mysofa_s2c(float values[3])
128```
129with phi (azimuth in degree, measured counterclockwise from the X axis), theta (elevation in degree,  measured up from the X-Y plane), and r (distance between listener and source) as parameters in the float array and x,y,z as response in the same array. Similar, call
130```
131void mysofa_c2s(float values[3])
132```
133The coordinate system is defined in the SOFA specification and is the same as in the SOFA file. Typically, the X axis vector (1 0 0) is the listening direction. The Y axis (0 1 0) is the left side of the listener and Z (0 0 1) is upwards.
134
135
136Sometimes, you want to use multiple SOFA filters or if you have to open a SOFA file multiple times, you may use
137```
138hrtf1 = mysofa_open_cached("file.sofa", 48000, &filter_length, &err);
139hrtf2 = mysofa_open_cached("file.sofa", 48000, &filter_length, &err);
140hrtf3 = mysofa_open_cached("file.sofa", 8000, &filter_length, &err);
141hrtf3 = mysofa_open_cached("file2.sofa", 8000, &filter_length, &err);
142mysofa_close_cached(hrtf1);
143mysofa_close_cached(hrtf2);
144mysofa_close_cached(hrtf3);
145mysofa_close_cached(hrtf4);
146...
147mysofa_cache_release_all();
148```
149Then, all HRTFs having the same filename and sampling rate are stored only once in memory. If your program is using several threads, you must use appropriate synchronisation mechanisms so only a single thread can access the mysofa_open_cached and mysofa_close_cached functions at a given time.
150
151## OS support
152
153Libmysofa compiles for Linux operating systems, OSX and Windows. By default, each commit is compiled with Travis CI under Ubuntu 14.04 and OSX 7.3 and with AppVeyor for Windows Visual Studio 2015 on a x64 system. In addition, FFmpeg is compiling libmysofa with MinGW under Windows using their own build system.
154
155
156## References
157
158 * Christian Hoene and Piotr Majdak, "HDF5 under the SOFA – A 3D audio case in HDF5 on embedded and mobile devices", HDF Blog, https://www.hdfgroup.org/2017/04/hdf5-under-the-sofa-hdf5-on-embedded-and-mobile-devices/, April 26, 2017.
159 * Christian Hoene, Isabel C. Patiño Mejía, Alexandru Cacerovschi, "MySofa: Design Your Personal HRTF", Audio Engineering Society
160 Convention Paper 9764, Presented at the 142nd Convention, May 2017, Berlin, Germany, http://www.aes.org/e-lib/browse.cfm?elib=18640
161
162## Disclaimer
163
164The SOFA files are from https://www.sofaconventions.org/, Piotr Majdak <piotr@majdak.com>. The K-D tree algorithm is by John Tsiombikas <nuclear@member.fsf.org>. The resampler is by Jean-Marc Valin. The remaining source code is by Christian Hoene <christian.hoene@symonics.com>, <a href="https://symonics.com/">Symonics GmbH</a>, and available under BSD-3-Clause license. This work has been funded by German <a href="https://www.bmbf.de">Federal Ministry of Education and Research</a>, funding code 01IS14027A.
165
166