The post-processing generates the final HRTF and HRIR .sofa files out of hundreds of individual raw simulation results.
| ------------------------------------------------------------ | Part of the the Complete Beginner’s tutorial | ------------------------------------------------------------ |
|---|---|---|
| Previous <<< The HRTF Simulation | \\\ Express tutorial /// | The Last part. (Extra Application notes) |
UNDER CONSTRUCTION!
Post processing for Mesh2HRTF has several parts, but for most users who just need to create their HRTF everything comes down to running a single file: "finalize_HRTF_simulation.py".
For reference:
The official post-processing code of the Mesh2HRTF project that is responsible for converting raw simulation results into SOFA files is: "Output2HRTF_Main.py (github.com)" that runs in Python and requires installation of mesh2hrtf Python package.
There is an alternative post-processing code of the Mesh2HRTF project which requires commercial Matlab software to run - "Output2HRTF_Main.m (github.com)". This code has very similar functionality to the Python post-processing and because it requires very expensive Matlab software to use - is not covered in this tutorial.
“finalize_HRTF_simulation.py (sourceforge.net)” file is a script that is made to compliment the main Python post-processing of the Mesh2HRTF. This script is currently not part of the Mesh2HRTF project, but it implements a few useful features, all from a single "double-click":
The "finalize_HRTF_simulation.py" script is optimized for beginners and executes the complete post-processing in a couple of simple steps:
Move both Mesh2HRTF project folders into the folder that contains “finalize_HRTF_simulation.py (sourceforge.net)” (one project folder for the left side and one folder for the right side). If you followed all tutorial recommendations then the correct /Finalize_HRTF_simulation/ should be right next to your 2 project folders, so a simple drag-and-drop in the Windows Explorer should do the trick.
Run: "finalize_HRTF_simulation.py" in the correct Python environment (environment where you installed “mesh2hrtf” package).
On Windows, launching can be as easy as double click the "finalize_HRTF_simulation.py" file. This works in case of Direct Python installation (here the "pip install -e ." part of installation is required). In some Python installations, if double-click does not work - use "Open with" ==> "Python 3.x".
For Linux, Mac, Windows Anaconda installations or any other Python environment cases it is always possible to write python finalize_HRTF_simulation.py(or possibly "python3 finalize_HRTF_simulation.py") in the command line of the environment where "mesh2hrtf" Python package was installed.
Be careful on Windows: do not click inside the Python window. If you see a “white square cursor” – the running script will be paused and it will not do anything. To escape the problem: press “Esc” key until “white square cursor” disappears.
In case you need to re-run the "finalize_HRTF_simulation.py" - just delete the folder with the merged SOFA files that it creates and it is possible to run again.

Done. The final "HRTF.sofa" and "HRIR.sofa" files will be saved next to the input project folders (path is visible in the printouts of the "finalize_HRTF_simulation.py" script). the typical final output from Mesh2HRTF simulation after the "finalize_HRTF_simulation.py" will be:
HRIR_ARI_48000.sofa - the main "HRTF" file to use if sound card is used at 48kHz sampling rate ("the DVD sampling rate" - common in video files).HRIR_ARI_44100.sofa - the main "HRTF" file to use if sound card is used at 44.1kHz sampling rate ("the CD sampling rate" - common among music files).HRTF_ARI_48000.sofa - the frequency domain HRTF file. Not as popular as HRIR files. HRIR_ARI_48000.png - the image file with the plot of the HRIR.sofa data for quick graphical test that SOFA files look reasonable compared to other examples. (the plot is only generated if "pyfar" Python package is installed.)Info.txt - a simple copy of the project Info file generated by Blender. Can be useful for keeping track of the origin of the SOFA files.example of good simulated HRIR data plotted and saved by "finalize_HRTF_simulation.py" v1.2 for graphical comparison

Normally the post-processing itself should be very quick and mostly automatic, but different issues can still get detected during post-processing:
The final SOFA file does not work in a program "X" - even though SOFA format is a standardized by AES (AES69-2020) there is no guarantee that specific software will support all variants of the SOFA format and there simply can be bugs.
First try a known working SOFA file in your application. The de-facto reference SOFA file format that is likely supported by majority of software is the format used in ARI HRTF database. The most up-to-date files from ARI database can be downloaded here: http://sofacoustics.org/data/database/ari/ . For example you can download and try dtf_nh15.sofa (sofacoustics.org) file. Note that files produced by "finalize_HRTF_simulation.py" follow almost exactly the same format as the reference ARI database SOFA files.
Try another software. The files produced by "finalize_HRTF_simulation.py" should work in examples described in SOFA application notes.
Various "ERROR" and "PROBLEM" printouts from "finalize_HRTF_simulation.py" usually are symptoms of issues encountered during simulation - please go to Simulation Troubleshooting for more guidance.
Crash of "finalize_HRTF_simulation.py" - this is most likely a bug - seek support by opening issue and providing the error information. If it is not possible to read the error printouts:
python finalize_HRTF_simulation.py(or possibly "python3 finalize_HRTF_simulation.py") in the command line of the environment where "mesh2hrtf" Python package was installed (For Direct Python installation on Windows a suitable command line is just "cmd.exe" in the folder where "finalize_HRTF_simulation.py" is located).python Output2HRTF.py from the specific project folder (folder that contains "Output2HRTF.py"). In case “finalize_HRTF_simulation.py" script is too limiting for your simulation needs, advanced users should study the methods and function within the "Output2HRTF_Main.py (github.com)" to access all available features through Python scripting.
The main scope of Mesh2HRTF and this tutorial stops at delivering the sofa files. Here is some additional information that can help in practical use of the HRTF files generated by Mesh2HRTF:
Most software that supports .sofa files actually expects the "HRIR.sofa" files even if it may be referred to as "HRTF".
The resulting sofa files assume completely flat headphone response on input. To use these files, at least a basic "diffuse field" equalization needs to be applied (such as available in SPARTA Binauralizer) or use even more sophisticated headphone EQs. If there are no advanced headphone EQ options available, a simple 7-band parametric EQ should give enough controls to manually design your own headphone compensation EQ using some trusted speakers in direct-sound conditions (listening in nearfield and/or mostly room-reflection free conditions).
See (partial) list of software with SOFA support on the sofaconventions.org (www.sofaconventions.org) to find more tools and applications for SOFA files.
See SOFA application notes for more tutorials.
The Last part. (Extra Application notes)