<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to Basic_HRTF_post_processing</title><link>https://sourceforge.net/p/mesh2hrtf-tools/wiki/Basic_HRTF_post_processing/</link><description>Recent changes to Basic_HRTF_post_processing</description><atom:link href="https://sourceforge.net/p/mesh2hrtf-tools/wiki/Basic_HRTF_post_processing/feed" rel="self"/><language>en</language><lastBuildDate>Mon, 25 Jul 2022 21:56:58 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/mesh2hrtf-tools/wiki/Basic_HRTF_post_processing/feed" rel="self" type="application/rss+xml"/><item><title>Basic_HRTF_post_processing modified by Sergejs</title><link>https://sourceforge.net/p/mesh2hrtf-tools/wiki/Basic_HRTF_post_processing/</link><description>&lt;div class="markdown_content"&gt;&lt;h1 id="saving-hrtf-sofa-files"&gt;Saving HRTF SOFA files&lt;/h1&gt;
&lt;p&gt;The post-processing generates the final HRTF and HRIR .sofa files out of hundreds of individual raw simulation result files. &lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;------------------------------------------------------------&lt;/th&gt;
&lt;th&gt;Part of the the &lt;a class="" href="/p/mesh2hrtf-tools/wiki/Basic_HRTF_tutorial/"&gt;Complete Beginner’s tutorial&lt;/a&gt; for Mesh2HRTF &lt;a class="" href="https://github.com/SDX-LV/Mesh2HRTF_contributions/releases/tag/v0.99" rel="nofollow"&gt;v2022-06&lt;/a&gt; - &lt;em&gt;No longer updated!!!&lt;/em&gt;&lt;/th&gt;
&lt;th&gt;------------------------------------------------------------&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Previous &amp;lt;&amp;lt;&amp;lt; &lt;a class="" href="/p/mesh2hrtf-tools/wiki/Basic_HRTF_NumCalc_Simulation/"&gt;The HRTF Simulation&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;See the latest releases and &lt;a class="" href="https://github.com/Any2HRTF/Mesh2HRTF/wiki/Tutorials" rel="nofollow"&gt;tutorials&lt;/a&gt; here: &lt;a class="" href="https://github.com/Any2HRTF/Mesh2HRTF/releases" rel="nofollow"&gt;GitHub-Mesh2HRTF&lt;/a&gt;!&lt;/td&gt;
&lt;td&gt;The Last part. (&lt;a class="" href="https://sourceforge.net/p/mesh2hrtf-tools/wiki/Basic_HRTF_tutorial/#additional-hrtf-help"&gt;Extra Application notes&lt;/a&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;hr/&gt;
&lt;p&gt;Video version of this tutorial:&lt;/p&gt;
&lt;iframe height="180" src="https://www.youtube.com/embed/-DRuF0DOtbs" title="YouTube video player" width="320"&gt;&lt;/iframe&gt;

&lt;hr/&gt;
&lt;div class="toc"&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#saving-hrtf-sofa-files"&gt;Saving HRTF SOFA files&lt;/a&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href="#background"&gt;Background&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#generate-hrtf-sofa-file"&gt;Generate HRTF SOFA file&lt;/a&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href="#troubleshooting"&gt;Troubleshooting&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="#advanced-post-processing"&gt;Advanced post-processing&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#tips-on-use-of-hrtf-sofa-files"&gt;Tips on use of HRTF SOFA files&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;h2 id="background"&gt;Background&lt;/h2&gt;
&lt;p&gt;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". &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;For reference:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;The official post-processing code of the Mesh2HRTF project that is responsible for converting raw simulation results into SOFA files is: "&lt;a class="" href="https://github.com/Any2HRTF/Mesh2HRTF/tree/develop/mesh2hrtf/Output2HRTF/Python/" rel="nofollow"&gt;output_to_hrtf.py&lt;/a&gt;" that runs in Python and requires installation of &lt;a class="" href="https://sourceforge.net/p/mesh2hrtf-tools/wiki/Installation_2/#mesh2hrtf-python-package-installation"&gt;mesh2hrtf&lt;/a&gt; Python package. &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;To launch the Python post-processing each Blender generated project folder has a script called "Output2HRTF.py".&lt;/li&gt;
&lt;li&gt;The Python post-processing has a number of extra functions that can be accessed from Python - see &lt;strong&gt;&lt;a class="" href="https://mesh2hrtf.readthedocs.io/" rel="nofollow"&gt;Mesh2HRTF Python API&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;This post processing has a possibility to join Left and Right side projects into a complete HRTF. "merge_sofa_files" function is accessible using Python API commands (it requires some Python scripting). &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;There is an alternative post-processing code of the Mesh2HRTF project which requires commercial Matlab software to run - "&lt;a class="" href="https://github.com/SDX-LV/Mesh2HRTF_contributions/releases/tag/v0.99" rel="nofollow"&gt;Output2HRTF_Main.m&lt;/a&gt;". Matlab post-processing has very similar functionality to the Python post-processing and is recommended only for advanced Matlab users.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;To launch the Matlab post processing each Blender generated project folder has a script called "Output2HRTF.m".&lt;/li&gt;
&lt;li&gt;NOTE: currently this post processing handles just 1 project and that means that &lt;em&gt;it can not automatically produce complete HRTF&lt;/em&gt; if the simulation contains 2 project folders.&lt;/li&gt;
&lt;li&gt;NOTE: even if Mesh2HRTF is used in "Both ears" mode to simulate both ears in one project, the Matlab post-processing produces SOFA files that may not be compatible with for example SPARTA Binauralizer.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The “&lt;strong&gt;&lt;a class="" href="https://sourceforge.net/p/mesh2hrtf-tools/code/ci/master/tree/Finalize_HRTF_simulation/"&gt;finalize_hrtf_simulation.py&lt;/a&gt;&lt;/strong&gt;” script 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":&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Executes "Output2HRTF.py" files inside both Left and Right side project folders.&lt;/li&gt;
&lt;li&gt;Joins Left and Right halves of the HRTF into a complete HRTF.&lt;/li&gt;
&lt;li&gt;Produces &lt;em&gt;multi_samplingrate_hrirs&lt;/em&gt; - in addition to the maximum possible sampling rate defined by "Max. frequency" project setting, the "finalize_hrtf_simulation.py" will produce extra HRIR.sofa files at all possible common sampling rates using naming convention as described &lt;a class="" href="https://www.flux.audio/2020/07/21/managing-and-importing-hrtf/" rel="nofollow"&gt;here&lt;/a&gt;. Typically this is used to generate 44.1kHz and 48kHz sofa files from a single Mesh2HRTF simulation that uses 150 of 75 Hz frequency step setting.&lt;/li&gt;
&lt;li&gt;Plots the SOFA HRIR data for both ears to give graphical confirmation that the simulation produced valid results.&lt;/li&gt;
&lt;li&gt;Has some extra data quality checks and user feedback features to make post-processing more intuitive and help in troubleshooting.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;hr/&gt;
&lt;h2 id="generate-hrtf-sofa-file"&gt;Generate HRTF SOFA file&lt;/h2&gt;
&lt;p&gt;The "finalize_HRTF_simulation.py" script is optimized for beginners and executes the complete post-processing in a couple of simple steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Move both Mesh2HRTF project folders into the  folder that contains “&lt;a class="" href="https://github.com/SDX-LV/Mesh2HRTF_contributions/releases/tag/v0.99" rel="nofollow"&gt;finalize_hrtf_simulation.py&lt;/a&gt;”&lt;/strong&gt; (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.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Run: "finalize_hrtf_simulation.py"&lt;/strong&gt; in the correct Python environment (environment where you &lt;a class="" href="https://sourceforge.net/p/mesh2hrtf-tools/wiki/Installation_2/#mesh2hrtf-python-package-installation"&gt;installed&lt;/a&gt; “mesh2hrtf” package).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;On Windows, launching can be as easy as &lt;strong&gt;double click the "finalize_hrtf_simulation.py" file&lt;/strong&gt;. This works in case of &lt;a class="" href="https://sourceforge.net/p/mesh2hrtf-tools/wiki/Installation_2/#alt-1-direct-python-installation"&gt;Direct Python installation&lt;/a&gt; (here the "&lt;a class="" href="https://sourceforge.net/p/mesh2hrtf-tools/wiki/Installation_2/#mesh2hrtf-python-package-installation"&gt;pip install -e .&lt;/a&gt;" part of installation is required). In some Python installations, if double-click does not work - use "Open with" ==&amp;gt; "Python 3.x".&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;For Linux, Mac, Windows &lt;a class="" href="https://sourceforge.net/p/mesh2hrtf-tools/wiki/Installation_2/#alt-2-anaconda-python-installation"&gt;Anaconda&lt;/a&gt; installations or any other Python environment cases it is always possible to write &lt;code&gt;python finalize_hrtf_simulation.py&lt;/code&gt;(or possibly "python3 finalize_hrtf_simulation.py") in the command line of the environment where &lt;a class="" href="https://sourceforge.net/p/mesh2hrtf-tools/wiki/Installation_2/#mesh2hrtf-python-package-installation"&gt;"mesh2hrtf" Python package&lt;/a&gt; was installed. &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Be careful on Windows: &lt;strong&gt;do not click inside the Python window&lt;/strong&gt;. 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.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Done.&lt;/strong&gt; The final HRTF 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" for each &lt;a class="" href="https://sourceforge.net/p/mesh2hrtf-tools/wiki/Basic_Project_export/#evaluation-grids"&gt;Evaluation Grid&lt;/a&gt; (in this example "ARI") will be:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;HRIR_ARI_48000.sofa&lt;/code&gt; - main "HRTF" file to use if sound card is used at 48kHz sampling rate ("the DVD sampling rate" - common in video files).&lt;/li&gt;
&lt;li&gt;&lt;code&gt;HRIR_ARI_44100.sofa&lt;/code&gt; - main "HRTF" file to use if sound card is used at 44.1kHz sampling rate ("the CD sampling rate" - common among music files).&lt;/li&gt;
&lt;li&gt;&lt;em&gt;any additional HRIR sampling rates&lt;/em&gt; - if the simulation "Max frequency" was higher than 24kHz, then there will be additional HRIR.sofa files. Note, while it is technically possible to simulate 96kHz, 192kHz and other extended frequency range sampling rates, there is almost no practical reason in doing so.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;HRTF_ARI_48000.sofa&lt;/code&gt; - frequency domain HRTF file. (contains practically the same information as HRIR file).  &lt;/li&gt;
&lt;li&gt;&lt;code&gt;HRIR_ARI_48000.png&lt;/code&gt; - image file with a plot of the HRIR.sofa data for quick &lt;strong&gt;visual inspection&lt;/strong&gt; that SOFA files look similar to known examples.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;HRXX_ARI_xxxxx_2D.pdf&lt;/code&gt; - one more plot of the HRIR/HRTF.sofa data generated by standard Mesh2HRTF function &lt;a class="" href="https://mesh2hrtf.readthedocs.io/en/latest/mesh2hrtf.html#mesh2hrtf.inspect_sofa_files" rel="nofollow"&gt;inspect_sofa_files&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;HRXX_ARI_xxxxx_3D.jpeg&lt;/code&gt; - one more plot of the HRIR/HRTF.sofa data generated by standard Mesh2HRTF function &lt;a class="" href="https://mesh2hrtf.readthedocs.io/en/latest/mesh2hrtf.html#mesh2hrtf.inspect_sofa_files" rel="nofollow"&gt;inspect_sofa_files&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Info.txt&lt;/code&gt; - a simple copy of the project Info file generated by Blender. Can be useful for keeping track of the origin of the SOFA files.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;em&gt;example of good simulated HRIR data plotted and saved by "finalize_hrtf_simulation.py" v1.2 for graphical comparison&lt;/em&gt;&lt;br/&gt;
&lt;img src="https://sourceforge.net/p/mesh2hrtf-tools/wiki/wiki_Attachments/attachment/HRIR_ARI_50400.png" width="60%"/&gt;&lt;/p&gt;
&lt;h3 id="troubleshooting"&gt;Troubleshooting&lt;/h3&gt;
&lt;p&gt;Normally the post-processing itself should be very quick and mostly automatic, but different issues can still get detected during post-processing:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;The final &lt;strong&gt;SOFA file does not work in a program "X"&lt;/strong&gt; - even though &lt;a class="" href="https://www.sofaconventions.org" rel="nofollow"&gt;SOFA format&lt;/a&gt; is a standardized by AES (&lt;a class="" href="https://www.aes.org/publications/standards/search.cfm?docID=99" rel="nofollow"&gt;AES69-2020&lt;/a&gt;) there is no guarantee that specific software will support all variants of the SOFA format and there simply can be bugs. &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;First &lt;strong&gt;try a known working SOFA file&lt;/strong&gt; in your application. The de-facto reference SOFA file format that is likely supported by majority of software is the format used in &lt;a class="" href="https://www.oeaw.ac.at/isf/das-institut/software/hrtf-database" rel="nofollow"&gt;ARI HRTF database&lt;/a&gt;. The most up-to-date files from ARI database can be downloaded here: &lt;a href="http://sofacoustics.org/data/database/ari/" rel="nofollow"&gt;http://sofacoustics.org/data/database/ari/&lt;/a&gt; . For example you can download and try &lt;strong&gt;&lt;a class="" href="http://sofacoustics.org/data/database/ari/dtf_nh15.sofa" rel="nofollow"&gt;dtf_nh15.sofa&lt;/a&gt;&lt;/strong&gt; file. Note that files produced by "finalize_hrtf_simulation.py" follow almost exactly the same format as the reference ARI database SOFA files.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Try another software. The files produced by "finalize_hrtf_simulation.py" should work in examples described in &lt;a class="" href="https://sourceforge.net/p/mesh2hrtf-tools/wiki/Basic_HRTF_tutorial/#additional-hrtf-help"&gt;SOFA application notes&lt;/a&gt;. &lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Various &lt;em&gt;"ERROR"&lt;/em&gt; and &lt;em&gt;"PROBLEM"&lt;/em&gt; printouts from "finalize_hrtf_simulation.py" usually are symptoms of issues encountered during simulation - please &lt;a class="" href="https://sourceforge.net/p/mesh2hrtf-tools/wiki/Basic_HRTF_NumCalc_Simulation/#troubleshooting"&gt;go to Simulation Troubleshooting&lt;/a&gt; for more guidance. &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Additional details and statistics on the simulation are saved by "output_to_hrtf.py" in each project folder under sub-folder /Output2HRTF/. For example "report_source_X.csv" file contains most of the stats. &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Crash of "finalize_hrtf_simulation.py" - this is most likely a bug - seek support by opening &lt;a class="" href="https://github.com/Any2HRTF/Mesh2HRTF/issues" rel="nofollow"&gt;support issue&lt;/a&gt; and providing the error information. It is important to read the error printouts. &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;If the script is executed by double-clicking, the "finalize_hrtf_simulation.py" window will close itself in case of code errors. In such case it is necessary to launch the "finalize_hrtf_simulation.py" from command line. Write &lt;code&gt;python finalize_hrtf_simulation.py&lt;/code&gt;(or possibly "python3 finalize_hrtf_simulation.py") in the command line of the environment where "mesh2hrtf" Python package was installed (For &lt;a class="" href="https://sourceforge.net/p/mesh2hrtf-tools/wiki/Installation_2/#alt-1-direct-python-installation"&gt;Direct Python installation&lt;/a&gt; on Windows a suitable command line is just "cmd.exe" in the folder where "finalize_hrtf_simulation.py" is located).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;As "finalize_hrtf_simulation.py" calls "Output2HRTF.py" in each project folder, which in turn runs "&lt;a class="" href="https://github.com/Any2HRTF/Mesh2HRTF/tree/develop/mesh2hrtf/Output2HRTF/Python/" rel="nofollow"&gt;output_to_hrtf.py&lt;/a&gt;" it may be useful to identify which project causes a problem in the Python post-processing by running  &lt;code&gt;python Output2HRTF.py&lt;/code&gt;directly in each project folder. &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;hr/&gt;
&lt;h2 id="advanced-post-processing"&gt;Advanced post-processing&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;"finalize_hrtf_simulation.py" has additional command line arguments which can be useful for advanced use (open the script itself for details).  &lt;/li&gt;
&lt;li&gt;In case “finalize_hrtf_simulation.py" script is too limiting for your simulation needs, advanced users should study the methods and functions in &lt;a class="" href="https://mesh2hrtf.readthedocs.io/" rel="nofollow"&gt;Mesh2HRTF Python API&lt;/a&gt; to access all available features through Python scripting or make their own scripts just like “finalize_hrtf_simulation.py".&lt;/li&gt;
&lt;/ul&gt;
&lt;hr/&gt;
&lt;h2 id="tips-on-use-of-hrtf-sofa-files"&gt;Tips on use of HRTF SOFA files&lt;/h2&gt;
&lt;p&gt;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:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Most software that supports .sofa files actually expects the &lt;strong&gt;"HRIR.sofa"&lt;/strong&gt; files even if it may be referred to as "HRTF".&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The resulting sofa files assume &lt;strong&gt;completely flat&lt;/strong&gt; headphone response on input. To use these files, at least a basic "diffuse field" equalization needs to be applied (such as available in &lt;a class="" href="https://leomccormack.github.io/sparta-site/docs/plugins/sparta-suite/#binauraliser" rel="nofollow"&gt;SPARTA Binauralizer&lt;/a&gt;) or use even more sophisticated headphone EQs. Individual equalization of headphones for use with HRTFs is a topic for a separate tutorial with many alternative approaches.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;See (partial) list of software with SOFA support on the &lt;a class="" href="https://www.sofaconventions.org/mediawiki/index.php/Software_and_APIs" rel="nofollow"&gt;sofaconventions.org&lt;/a&gt; to find more tools and applications for SOFA files.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;See &lt;a class="" href="https://sourceforge.net/p/mesh2hrtf-tools/wiki/Basic_HRTF_tutorial/#additional-hrtf-help"&gt;SOFA application notes&lt;/a&gt; for more tutorials.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr/&gt;
&lt;p&gt;The Last part. (&lt;a class="" href="https://sourceforge.net/p/mesh2hrtf-tools/wiki/Basic_HRTF_tutorial/#additional-hrtf-help"&gt;Extra Application notes&lt;/a&gt;)&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Sergejs</dc:creator><pubDate>Mon, 25 Jul 2022 21:56:58 -0000</pubDate><guid>https://sourceforge.netd6143bee48c1888f8a9de2f025b8b573e2e13954</guid></item></channel></rss>