hoene / libmysofa

Reader for AES SOFA files to get better HRTFs
Other
138 stars 73 forks source link

this library doe not work with current SOFA files? #186

Closed SDX-LV closed 2 years ago

SDX-LV commented 2 years ago

Hi, I noticed that https://github.com/kcat/openal-soft/blob/master/utils/makemhr/loaddef.cpp is using "mysofa_check" function and the rest of this library.

The problem is that in my tests no recently saved SOFA file opens with this library.

Worse, I got one old sofa file from SADIE database which does work, but if I open this sofa file and re-save it, it is no longer compatible with makemhr.exe (which supposedly uses libmysofa). I did the test in Octave using "SOFA API for Matlab and Octave 1.1.3" and in Python using "sofar" package.

Can anyone confirm that this package opens any recently created SOFA files? If it is really obsolete, could you recommend an alternative? @petibub , is https://github.com/sofacoustics/API_Cpp more up to date?

I can provide example sofa files if needed (both the one that works and the newer ones that do not).

Best regards, Sergejs

SDX-LV commented 2 years ago

OK, it looks that getting this library fixed is even more important. For example, FFMPEG is using this library as well: https://ffmpeg.org/pipermail/ffmpeg-cvslog/2017-June/107777.html

I tested with more recent Mesh2HRTF generated SOFA files, no matter if they are saved from Matlab API 1.1.3 or Python sofar - they all error out in ffmpeg:

[Parsed_sofalizer_0 @ 000002c87f15c440] Selected SOFA file is invalid. Please select valid SOFA file.
[Parsed_sofalizer_0 @ 000002c87f15c440] Error while loading SOFA file: 'HRIR_Default_44100.sofa'
[Parsed_sofalizer_0 @ 000002c87f15c440] No valid SOFA file could be loaded. Please specify valid SOFA file.
[auto_aresample_0 @ 000002c87f15e740] [SWR @ 000002c87f170840] Requested output sample rate 0 is invalid
[auto_aresample_0 @ 000002c87f15e740] Failed to configure output pad on auto_aresample_0
umlaeute commented 2 years ago

what's a "recently saved SOFA file"? (most likely it has nothing to do with date of saving)

i think an example file would be great (and if you can provide both the an original (working) and re-saved (non-working) file, all the better)

SDX-LV commented 2 years ago

Fair enough. Recent I meant that I couldn't get any SOFA file created in current version of sofar or Octave API to open in these 2 programs which rely on libmysofa. But as I am not qualified to debug C or C++ directly, I really don't know where lies the problem.

1- This old file works both in OpenAL-soft makemhr.exe and in ffmpeg-git-full.7z - H6_48K_24bit_256tap_FIR_SOFA - works.zip

2- This new file from Mesh2HRTF project does not work in any of these - HRIR_Default_48000 - new, does not work.zip

3- Finally I re-saved file that works using command sofar.write_sofa('path', loaded_H6_48K_24bit_256tap_FIR_SOFA, version='match', compression=9) and now it still does not work in OpenAL-soft makemhr.exe but it does work in ffmpeg - resaved_H6_48K_24bit_256tap_FIR_SOFA.zip

So based on this, my guess is that the latest version of libmysofa does not like .GLOBAL_Version = '2.0' set by sofar even if all files follow SimpleFreeFieldHRIR 1.0 . Plus there are other non-fatal issues in mysofa_check function, but I don't mind as long as the .sofa file can be opened.

Would appreciate that you can confirm which version of libmysofa is compatible with sofar exported files (as used by Mesh2HRTF v1.0), basically the HRIR_Default_48000 - new, does not work.zip example file.

The use case is to enable use of SOFA files in OpenAL-Soft and HeSuVi as described here.

thanks!

hoene commented 2 years ago

Got it. HDF is a moving target. Sometimes, they do breaking changes. A new version of libmysofa shall be realized in a few weeks. Be patient.

SDX-LV commented 2 years ago

Thanks, this library is really important to enable other software to work with SOFA format. If you manage to update the compatibility with packages like https://github.com/pyfar/sofar then it should automatically fix compatibility with Mesh2HRTF and many other new SOFA files :)

hoene commented 2 years ago

Please provide a failing test case. I cannot reproduce your bug report.

hoene commented 2 years ago

Add it here: https://github.com/hoene/libmysofa/tree/issue-186

SDX-LV commented 2 years ago

Hello, Sorry I was away. So you did try the attached file: HRIR_Default_48000 - new, does not work.zip and it works as intended?

In post https://github.com/hoene/libmysofa/issues/186#issuecomment-1204119761 I explained how I tested it. If it works for you, please tell me how you tested it or perhaps there is some compiled test code that I could try on my end? So far I only used other programs that rely on libmysofa and I am very curious to check.

Sometimes the issues may be quite file-specific, for example SPARTA plugins had a memory related crashing issue that affected only SOFA files with not-128 sampling points - turns out most SOFA files have exactly 128 frequency steps and the issue went unnoticed for a long time :)

hoene commented 2 years ago

Please test it with mysofa2json tool that comes with this library. I would also need to understand, which version of libmysofa is used in those other applications.

SDX-LV commented 2 years ago

Hi, I very much do not know what am I doing, but I downloaded v 1.2.1 release source code and compiled in Visual Studio 2022:

1>libmysofa.vcxproj -> C:\Users\zzz\Downloads\libmysofa-1.2.1\windows\bin\x64\Debug\mysofa.lib 1>Done building project "libmysofa.vcxproj". ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ========== and 1>testApp.vcxproj -> C:\Users\zzz\Downloads\libmysofa-1.2.1\windows\testApp\x64\Debug\testApp.exe 1>Done building project "testApp.vcxproj". ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

but I did not find any "mysofa2json tool" or other trick to test the library directly.

Could you point me to the right file; tutorial or perhaps attach a binary for Windows?

hoene commented 2 years ago

Please use Linux and follow the README.md

richardpl commented 2 years ago

Just compiled libmysofa.1.2.2 and linked sofa from zip file above does not work.

ThreeDeeJay commented 2 years ago

I got some good news I forked PR #189 and linked it to a forked ffmpeg compiler github actions and I was able to convert Mesh2HRTF SOFAs to HeSuVi HRIR I put together a test script so you just gotta extract my patched ffmpeg.exe (or the unpatched one to confirm it didn't work) into the Resources folder then run the .bat script. SOFAlizer-HeSuVi_converter.zip

resaved_H6_48K_24bit_256tap_FIR_SOFA.zip works with both versions.

However, there are still a handful of SOFAs that still fail to convert even with my patched ffmpeg. For example, when I try to convert this 3D3A SOFA (or any *IR), I get this error which is seems to be the same one as the second post (just different filename, hash and 3 extra lines which my have been cut out):

[Parsed_sofalizer_0 @ 00000229608d8fc0] Selected SOFA file is invalid. Please select valid SOFA file. [Parsed_sofalizer_0 @ 00000229608d8fc0] Error while loading SOFA file: 'Subject1_HRIRs.sofa' [Parsed_sofalizer_0 @ 00000229608d8fc0] No valid SOFA file could be loaded. Please specify valid SOFA file. [auto_aresample_0 @ 0000022960926b40] [SWR @ 0000022960931800] Requested output sample rate 0 is invalid [auto_aresample_0 @ 0000022960926b40] Failed to configure output pad on auto_aresample_0 Error reinitializing filters! Failed to inject frame into filter network: Invalid argument Error while processing the decoded data for stream #0:0

umlaeute commented 2 years ago

I get this error which seems to be the same one as the second post:

Would it be possible to copy the actual error message as text, rather than using screenshots?

(If the answer is yes, consider editing your comment and replacing the image with text.)

SDX-LV commented 2 years ago

I got some good news I forked PR #189 and linked it to a forked ffmpeg compiler github actions and I was able to convert Mesh2HRTF SOFAs to HeSuVi HRIR I put together a test script so you just gotta extract my patched ffmpeg.exe

I can confirm that this new build of ffmpeg now resolved the issue with "[HeSuVi] SOFA to WAV.bat" conversion for all Mesh2HRTF generated SOFA files I tested. That includes "HRIR_Default_48000 - new, does not work.zip" file from the 4th post. And a couple of my other HRIR files.

If the same libsofa version will be integrated into OpenAL-soft makemhr.exe then at least for Mesh2HRTF generated SOFA files everything will be perfect (when the fixes are commited and integrated into ffmpeg adn OpenAL-soft).

ThreeDeeJay commented 2 years ago

I also noticed H6_48K_24bit_256tap_FIR_SOFA.sofa works (despite a warning), but resaved_H6_48K_24bit_256tap_FIR_SOFA.sofa fails to convert to MHR > using OpenAL Soft's SOFA to MHR converter.

Generating "H6_48K_24bit_256tap_FIR_SOFA-48000.mhr"
Reading HRTF data from H6_48K_24bit_256tap_FIR_SOFA.sofa...
Warning: Supposedly malformed source file 'H6_48K_24bit_256tap_FIR_SOFA.sofa' (Invalid format).
Detecting compatible layout...
Using 794 of 2818 IRs.
Loading HRIRs... 2818 of 2818
Calculating diffuse-field average...
Performing diffuse-field equalization...
Performing minimum phase reconstruction...
100% done (1588 of 1588)
Truncating minimum-phase HRIRs...
Synthesizing missing elevations...
Normalizing final HRIRs...
Calculating impulse delays...
Creating MHR data set Output\H6_48K_24bit_256tap_FIR_SOFA\H6_48K_24bit_256tap_FIR_SOFA-48000.mhr...
Operation completed.

Generating "resaved_H6_48K_24bit_256tap_FIR_SOFA-48000.mhr"
Reading HRTF data from resaved_H6_48K_24bit_256tap_FIR_SOFA.sofa...
Error: Could not load resaved_H6_48K_24bit_256tap_FIR_SOFA.sofa: Invalid format

Mesh2HRTF SOFAs also fail with the same error:

Generating "Mesh2HRTF_HRIR_Default_48000-48000.mhr"
Reading HRTF data from Mesh2HRTF_HRIR_Default_48000.sofa...
Error: Could not load Mesh2HRTF_HRIR_Default_48000.sofa: Invalid format

Generating "Mesh2HRTF_HRTF_Default_48000-48000.mhr"
Reading HRTF data from Mesh2HRTF_HRTF_Default_48000.sofa...
Error: Could not load Mesh2HRTF_HRTF_Default_48000.sofa: Invalid format

SOFAlizer-OpenALSoft_converter.zip

Tthe weird thing is that resaved_H6_48K_24bit_256tap_FIR works with both the latest libmysofa in ffmpeg and fix-for-mesh2hrtf branch when converting to HeSuVi HRIR, but not in OpenAL Soft's converter. So I wonder if its SOFA implementation hasn't been updated in too long or if problematic SOFAs just don't met these conditions if they still apply. 🤔


EDIT: Scratch all that. I was using makemhr from openal-soft-1.20.1 (because it was the last version that has worked for me with older SOFAs) but looks like makemhr from openal-soft-1.22.2 is the version to use for newer SOFAs, at least for HRIR_Default_48000.sofa (Mesh2HRTF) (tho it seems requirements like uniform elevations still apply)

Generating "HRIR_ARI_48000-48000.mhr"
Using 2 threads.
Reading HRTF data from HRIR_ARI_48000.sofa...
Warning: Supposedly malformed source file 'HRIR_ARI_48000.sofa' (Unknown).
Unexpected sample rate attribute: _Netcdf4Coordinates = (null)
Unexpected delay attribute: _Netcdf4Coordinates = (null)
Unexpected IR attribute: _Netcdf4Coordinates = (null)
Detecting compatible layout...
Non-uniform elevations on field distance 1.200.
Got: -25.00, -20.00, +0.00, +20.00, +25.00, +55.00, +60.00, +70.00, +80.00
Using 0 of 1550 IRs.

Generating "HRIR_Default_48000-48000.mhr"
Using 2 threads.
Reading HRTF data from HRIR_Default_48000.sofa...
Warning: Supposedly malformed source file 'HRIR_Default_48000.sofa' (Unknown).
Unexpected sample rate attribute: _Netcdf4Coordinates = (null)
Unexpected delay attribute: _Netcdf4Coordinates = (null)
Unexpected IR attribute: _Netcdf4Coordinates = (null)
Detecting compatible layout...
Using 1850 of 1850 IRs.
Loading HRIRs... 1850 of 1850
Calculating HRIR onsets... 3700 of 3700
Calculating HRIR magnitudes... 3700 of 3700
Calculating diffuse-field average...
Performing diffuse-field equalization...
Synthesizing missing elevations...
Performing minimum phase reconstruction...
100% done (3700 of 3700)
Truncating minimum-phase HRIRs...
Normalizing final HRIRs...
Calculating impulse delays...
Creating MHR data set Output\HRIR_Default_48000\HRIR_Default_48000-48000.mhr...
Operation completed.

Generating "HRTF_ARI_48000-48000.mhr"
Using 2 threads.
Reading HRTF data from HRTF_ARI_48000.sofa...
Error: Could not load HRTF_ARI_48000.sofa: Invalid format

Generating "HRTF_Default_48000-48000.mhr"
Using 2 threads.
Reading HRTF data from HRTF_Default_48000.sofa...
Error: Could not load HRTF_Default_48000.sofa: Invalid format

Relevant excerpt from alsoft_error.txt (OpenAL Soft log file)

[ALSOFT] (II) Loading C:\Users\PC\AppData\Roaming\openal\hrtf\HRIR_Default_48000-48000.mhr...
[ALSOFT] (II) Detected data set format v3
[ALSOFT] (II) Found hrtf-size = "0"
[ALSOFT] (II) Loaded HRTF HRIR_Default_48000-48000 for sample rate 48000hz, 32-sample filter
[ALSOFT] (II) Found hrtf-mode = "full"
[ALSOFT] (II) 1st order + Full HRTF rendering enabled, using "HRIR_Default_48000-48000"
ThreeDeeJay commented 2 years ago

EAC Individualized HRTF Synthesis was just released as a standalone app, so generating personalized SOFAs is now a lot easier. However, I'm having trouble converting them to OpenAL Soft MHR using : makemhr.exe -r 44100 -i "EAC_44.1kHz.sofa" -o "EAC_44.1kHz-44100.mhr" If I use the makemhr from openal-soft-1.22.2 (latest stable release at the moment), I get this error:

Generating "EAC_44.1kHz-44100.mhr"
Using 2 threads.
Reading HRTF data from EAC_44.1kHz.sofa...
Unexpected delay attribute: _Netcdf4Coordinates = (null)
Unsupported delay dimensions: M,R

And if I use makemhr from openal-soft-1.20.1 (the last version that has worked for me with other SOFAs), I get this:

Generating "EAC_44.1kHz-44100.mhr"
Reading HRTF data from EAC_44.1kHz.sofa...
Error: Could not load EAC_44.1kHz.sofa: Unsupported format
hoene commented 2 years ago

@ThreeDeeJay Please add one of those SOFA files to the ticket #190