How to use the tools from https://sourceforge.net/p/mesh2hrtf-tools/code/ci/master/tree/convert_n_analyse_HRTF/ .
Currently the tools are:
plot_sofa_hrtf.py
hesuvi_to_sofa_converter.py
sofa_to_hesuvi_ir_extractor.py
(by direct IR data extraction)Tutorial Status | Date Written | Date Last Updated |
---|---|---|
Complete | 2022-11-27 | 2022-11-28 |
Example: plotting of any SOFA file by double-clicking "plot_sofa_hrtf.py":
The scripts are made for Python 3.8+ (tested in 3.10) and all dependency packages can be installed directly from pip install missing_package_name
. Main dependencies are:
pip install sofar
andpip install pyfar
(which also installs several necessary common packages).If you need help installing Python itself check Mesh2HRTF Python installation tutorial. (Pip is included with Python).
If you do not want to risk your main Python installation. consider installing pyfar and sofar in a separate Python environment such as "python -m venv venv" in a specific folder (read more details here).
Good to know stuff:
All scripts can be used in 3 ways:
"Double click" direct execution - if you just run the script in Python without any input arguments it will search for valid input files next to it and produce the default result (which is usually what is needed). Note, this works only if "sofar" is installed in the main Python environment.
Command line with arguments - run from system command line using optional input arguments, for example try python sofa_to_hesuvi_ir_extractor.py --help
or python sofa_to_hesuvi_ir_extractor.py --input_dir="TestFiles/Third.sofa" --diagnostic_plot="True"
import plot_sofa_hrtf
and then a usual function call plot_sofa_hrtf.main()
"input_1" is a flexible input parameter:
input_1=False
- default. Input files are searched next to this script.input_1=folder_path
- SOFA file is searched inside Input folder. "input_1=path.file_extention
- specific input file is used directly.Scripts NEVER modify input data (there is no such option and it would be a major bug) - they can only produce additional new files.
SOFA is the master format! it means that:
hesuvi_to_sofa_converter.py
.A typical chain of events is that when you run "SOFA to XYZ converter", it will also call "XYZ to SOFA converter" in order to plot XYZ data using standard "SOFA plotter" scripts. (Note that scripts that are sequentially called will use the result output folder as their input folder and will process any file that fits their input data criteria.)
You can copy/move the scripts to any folder where you wish to run them. It may be more convenient than moving the input data. Only remember that scripts often need one-another.
Example: plot of a Mesh2HRTF simulated individual SOFA file after level normalization ("plot_sofa_hrtf.py" v1.02):
Troubleshooting:
pip install sofar
and pip install pyfar
.pip list --outdated
and pip install --user --upgrade ThePackageYouNeed
.For more specific How-To instructions:
Have fun!
Examples how these scripts can be used:
Goal: Make any SOFA HRTF usable in HeSuVi by directly extracting impulse responses stored inside SOFA file
Same principle can be applied to other conversion scripts to other formats.
Example: output files from converting SOFA to HeSuVi by double-clicking the "sofa_to_hesuvi_ir_extractor.py" script:
Step by Step (assuming the basics are in place):
Convert your Mesh2HRTF SOFA file to HeSuVi using the direct IR extraction script:
python sofa_to_hesuvi_ir_extractor.py
in the correct Python environment)Note that new "output" folder will contain:
Done.
Note, there are more-than 3 different methods to convert SOFA to HeSuVi. This "sofa_to_hesuvi_ir_extractor.py" method is the easiest and also 100% true to the SOFA file original.
Goal: Double Check that "sofa_to_hesuvi_ir_extractor.py" script does not damage the source HRTF data
Same principle can be applied to other conversion scripts to other formats.
Step by Step (assuming the basics are in place):
Convert your Mesh2HRTF SOFA file to HeSuVi using the direct IR extraction script:
python sofa_to_hesuvi_ir_extractor.py
in the correct Python environment)Note that new "output" folder will contain:
Re-Convert SOFA file created together with HeSuVi output file Again into HeSuVi file:
Execute "sofa_to_hesuvi_ir_extractor.py" script again. As a result:
Confirm that the data is not degraded:
visually compare the equivalent plots from converted and re-converted SOFA files. For example:
Note, HeSuVi data can also be compared to the source SOFA file without any HeSuVi conversion:
Bonus numerical check in Python using "sofar" (optional):
import sofar as sf
converted_data = sf.read_sofa("yourFile_HeSuVi_direct_from_HeSuVi.sofa")
re_converted_data = sf.read_sofa("yourFile_HeSuVi_direct_from_HeSuVi_HeSuVi_direct_from_HeSuVi.sofa")
converted_data.GLOBAL_Title = "Making sure title is the same"
re_converted_data.GLOBAL_Title = "Making sure title is the same"
sf.equals(converted_data, re_converted_data)
# answer True means that the two files are identical in every way despite repeated conversions
Note, there are more-than 3 different methods to convert SOFA to HeSuVi. And then there are various options in the advanced methods. Using these plotting and conversion tools, it is possible to visually see how the methods differ from one another.
Goal: Visually show the frequency response applied by HeSuVi processing using various HRTFs. Plus make all the HeSuVi profiles available in SOFA format.
Example: plot of OpenAL HRTF provided by HeSuVi:
Newly created "output" folder will contain: