ValveSoftware / steam-audio

Steam Audio
https://valvesoftware.github.io/steam-audio/
Apache License 2.0
2.3k stars 159 forks source link

[Unity] Custom HRTF problem (LISTEN database) #241

Closed SiWaAzu closed 1 year ago

SiWaAzu commented 1 year ago

------env information -------- Windows 10 Unity version: 2019.4.40f Steam Audio version: 4.0.3 / 4.1.2 Other package or plug-in: SteamVR Matlab: 2022b SOFAtoolbox: 4.1.2 HRTF source: LISTEN database

I am working on project that need to use custom HRTFs. I think the HRTFs meet the things that are metioned in the user's manual (SimpleFreeFieldHRIR 1.0). However, the console kept giving the message saying that the HRTF cannot be loaded. (HRTF source: http://opendap.ircam.fr/download/SimpleFreeFieldHRIR/LISTEN/COMPENSATED/44100/)

I first checked the problem with another HRTF that I know it can be loaded, and this one can be loaded successfully in my implementation. Therefore, I think it might be the problem of the HRTFs I got from LISTEN database. The information I got from the previous issues is that I can try to use SOFAtoolbox. Two things I have done so far are saving a new copy and produce the sofa file from the LISTEN file with SOFAtoolbox. (LISTEN file: http://recherche.ircam.fr/equipes/salles/listen/download.html) (The sofa file I produced with SOFAtoolbox: https://drive.google.com/drive/folders/15aL9y5L2Iwa4WF0Mnt_whQSE8OLnVLz1?usp=share_link) Unfortunatelly, those HRTFs still cannot be loaded.

If someone can tell me what might be the cause of this problem, or other HRTF database that can be successfully used in Stean Audio, I will be very appreciate.

achandak commented 1 year ago

We use libmysofa as the underlying library to load the HRTFs. Currently, the library does not the load the files you linked.

Here is a workout which seems to work. The script below is for Octave. You can adapt it for Matlab. We basically convert the files into format library can load.

    sofa_rs = SOFAload(<original_sofa_file>);
    sofa_out = SOFAgetConventions('SimpleFreeFieldHRIR');
    sofa_out.Data.IR = sofa_rs.Data.IR;
    sofa_out.Data.SamplingRate = sofa_rs.Data.SamplingRate;
    sofa_out.GLOBAL_ListenerShortName = sofa_rs.GLOBAL_ListenerShortName;
    sofa_out.GLOBAL_History = sofa_rs.GLOBAL_History;
    sofa_out.ListenerPosition = sofa_rs.ListenerPosition;
    sofa_out.ListenerView = sofa_rs.ListenerView;
    sofa_out.ListenerUp = sofa_rs.ListenerUp;
    sofa_out.SourcePosition = sofa_rs.SourcePosition;
    sofa_out = SOFAupdateDimensions(sofa_out);
    SOFAsave(HRTFFilesOutput{i}, sofa_out);
portoaj commented 1 year ago

For people interested in the workaround mentioned above in the future, you first need to add SOFAToolbox to your matlab/ octave path. Additionally, you need to run SOFAstart before the aforementioned script or it won't work. Here's my full script:

SOFAstart; sofa_rs = SOFAload('inputsofapathhere'); sofa_out = SOFAgetConventions('SimpleFreeFieldHRIR'); sofa_out.Data.IR = sofa_rs.Data.IR; sofa_out.Data.SamplingRate = sofa_rs.Data.SamplingRate; sofa_out.GLOBAL_ListenerShortName = sofa_rs.GLOBAL_ListenerShortName; sofa_out.GLOBAL_History = sofa_rs.GLOBAL_History; sofa_out.ListenerPosition = sofa_rs.ListenerPosition; sofa_out.ListenerView = sofa_rs.ListenerView; sofa_out.ListenerUp = sofa_rs.ListenerUp; sofa_out.SourcePosition = sofa_rs.SourcePosition; sofa_out = SOFAupdateDimensions(sofa_out); SOFAsave('outputsofapathhere', sofa_out);