kcat / openal-soft

OpenAL Soft is a software implementation of the OpenAL 3D audio API.
Other
2.16k stars 522 forks source link

hrtf files loading #105

Open mmarkell opened 7 years ago

mmarkell commented 7 years ago

Hello! I am implementing a c++ 3d sound system on Ubuntu. Everything with OpenAL is working great, but the builtin HRTF doesn't seem too precise, so I followed the guide here https://www.reddit.com/r/oculus/comments/1fzonq/psa_for_games_using_openal_including_minecraft/cagd3lb/.

Unfortunately, I am getting an error when I run my system, "AL lib: (WW) OpenDataFile: Could not open oalsoft_hrtf_44100.mhr" "AL lib: (WW) OpenDataFile: Could not open /home/ubuntu/.local/share/openal/hrtf/oalsoft_hrtf_44100.mhr" "AL lib: (WW) OpenDataFile: Could not open /usr/local/share//openal/hrtf/oalsoft_hrtf_44100.mhr" "AL lib: (WW) OpenDataFile: Could not open /usr/share//openal/hrtf/oalsoft_hrtf_44100.mhr"

What I assume is happening is a permission error, or something is corrupt with the mhr file. I can see it tries to find the file in so many different locations (for me, it should be located in ~), but I am just at a loss as for how to go forward.

If you have any recommendations, or in general, what steps to take if I want to incorporate some really good HRTF's into my implementation, please let me know :)

Thank you so much! Michael

kcat commented 7 years ago

Place the file in ~/.local/share/openal/hrtf. OpenAL Soft will automatically look there for the file named by hrtf_tables, and starting with 1.18, the way HRTFs are discovered and selected has been changed and it will need to be there to be seen.

You can alter the built-in HRTFs by switching the files hrtf/default-44100.mhr and hrtf/default-48000.mhr for different ones when building the lib. Just be aware that HRTFs are highly dependent on the person listening, and an HRTF that may sound good for one person can sound poor for another, and vice-versa.

mmarkell commented 7 years ago

It's still telling me that it can't open the file for some reason, even though it's in that directory. Could it be something else?

Thank you for your help! On Mon, Apr 24, 2017 at 11:33 PM kcat notifications@github.com wrote:

Place the file in ~/.local/share/openal/hrtf. OpenAL Soft will automatically look there for the file named by hrtf_tables, and starting with 1.18, the way HRTFs are discovered and selected has been changed and it will need to be there to be seen.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/kcat/openal-soft/issues/105#issuecomment-296887845, or mute the thread https://github.com/notifications/unsubscribe-auth/AKYxm-VOyRs6PP0hm9UOOGCL3AwpD1_eks5rzWmYgaJpZM4NG5n2 .

-- [image: Brown logo] http://brown.edu/ Michael Markell ‘18 B.S. Computer Science Candidate 302 229 0419

mmarkell commented 7 years ago

Specifically, "Al lib: (ww) opendatafile: could not open oalsoft_hrtf_44100.mhr"

On Tue, Apr 25, 2017 at 9:35 PM Michael Markell michael_markell@brown.edu wrote:

It's still telling me that it can't open the file for some reason, even though it's in that directory. Could it be something else?

Thank you for your help!

On Mon, Apr 24, 2017 at 11:33 PM kcat notifications@github.com wrote:

Place the file in ~/.local/share/openal/hrtf. OpenAL Soft will automatically look there for the file named by hrtf_tables, and starting with 1.18, the way HRTFs are discovered and selected has been changed and it will need to be there to be seen.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/kcat/openal-soft/issues/105#issuecomment-296887845, or mute the thread https://github.com/notifications/unsubscribe-auth/AKYxm-VOyRs6PP0hm9UOOGCL3AwpD1_eks5rzWmYgaJpZM4NG5n2 .

-- [image: Brown logo] http://brown.edu/ Michael Markell ‘18 B.S. Computer Science Candidate 302 229 0419

-- [image: Brown logo] http://brown.edu/ Michael Markell ‘18 B.S. Computer Science Candidate 302 229 0419

kcat commented 7 years ago

Specifically, "Al lib: (ww) opendatafile: could not open oalsoft_hrtf_44100.mhr"

It will say that since the file isn't in the current directory. But it should be found in /home/ubuntu/.local/share/openal/hrtf/. Can you give a full trace log (set the ALSOFT_LOGLEVEL env var to 3 when you run the app)?

fatalfeel commented 7 years ago

I modify in hrtf.c

vector_EnumeratedHrtf EnumerateHrtf(const_al_string devname) { vector_EnumeratedHrtf list = VECTOR_INIT_STATIC(); const char defaulthrtf = ""; const char pathlist = ""; bool usedefaults = true; al_string hstr[2]; char* table[2] = { "/root/openal-soft-master/hrtf/default-44100.mhr", "/root/openal-soft-master/hrtf/default-48000.mhr" };

/*if(ConfigValueStr(alstr_get_cstr(devname), NULL, "hrtf-paths", &pathlist))
{
    al_string pname = AL_STRING_INIT_STATIC();
    while(pathlist && *pathlist)
    {
        const char *next, *end;

        while(isspace(*pathlist) || *pathlist == ',')
            pathlist++;
        if(*pathlist == '\0')
            continue;

        next = strchr(pathlist, ',');
        if(next)
            end = next++;
        else
        {
            end = pathlist + strlen(pathlist);
            usedefaults = false;
        }

        while(end != pathlist && isspace(*(end-1)))
            --end;
        if(end != pathlist)
        {
            vector_al_string flist;
            size_t i;

            alstr_copy_range(&pname, pathlist, end);

            flist = SearchDataFiles(".mhr", alstr_get_cstr(pname));
            for(i = 0;i < VECTOR_SIZE(flist);i++)
                AddFileEntry(&list, VECTOR_ELEM(flist, i));
            VECTOR_FOR_EACH(al_string, flist, alstr_reset);
            VECTOR_DEINIT(flist);
        }

        pathlist = next;
    }

    alstr_reset(&pname);
}
else if(ConfigValueExists(alstr_get_cstr(devname), NULL, "hrtf_tables"))
    ERR("The hrtf_tables option is deprecated, please use hrtf-paths instead.\n");*/

if(usedefaults)
{
    al_string ename = AL_STRING_INIT_STATIC();
    //vector_al_string flist;
    vector_al_string flist = VECTOR_INIT_STATIC();
    const ALubyte *rdata;
    size_t rsize, i;

    //flist = SearchDataFiles(".mhr", "openal/hrtf");
    for(i=0; i<2; i++)
    {
        AL_STRING_INIT(hstr[i]);
        alstr_copy_cstr(&hstr[i], table[i]);
        VECTOR_PUSH_BACK(flist, hstr[i]);
    }

    for(i = 0;i < VECTOR_SIZE(flist);i++)
        AddFileEntry(&list, VECTOR_ELEM(flist, i));
    VECTOR_FOR_EACH(al_string, flist, alstr_reset);
    VECTOR_DEINIT(flist);

    rdata = GetResource(IDR_DEFAULT_44100_MHR, &rsize);
    if(rdata != NULL && rsize > 0)
    {
        alstr_copy_cstr(&ename, "Built-In 44100hz");
        AddBuiltInEntry(&list, ename, IDR_DEFAULT_44100_MHR);
    }

    rdata = GetResource(IDR_DEFAULT_48000_MHR, &rsize);
    if(rdata != NULL && rsize > 0)
    {
        alstr_copy_cstr(&ename, "Built-In 48000hz");
        AddBuiltInEntry(&list, ename, IDR_DEFAULT_48000_MHR);
    }
    alstr_reset(&ename);
}

if(VECTOR_SIZE(list) > 1 && ConfigValueStr(alstr_get_cstr(devname), NULL, "default-hrtf", &defaulthrtf))
{
    const EnumeratedHrtf *iter;
    /* Find the preferred HRTF and move it to the front of the list. */

define FIND_ENTRY(i) (alstr_cmp_cstr((i)->name, defaulthrtf) == 0)

    VECTOR_FIND_IF(iter, const EnumeratedHrtf, list, FIND_ENTRY);

undef FIND_ENTRY

    if(iter == VECTOR_END(list))
        WARN("Failed to find default HRTF \"%s\"\n", defaulthrtf);
    else if(iter != VECTOR_BEGIN(list))
    {
        EnumeratedHrtf entry = *iter;
        memmove(&VECTOR_ELEM(list,1), &VECTOR_ELEM(list,0),
                (iter-VECTOR_BEGIN(list))*sizeof(EnumeratedHrtf));
        VECTOR_ELEM(list,0) = entry;
    }
}

return list;

}

kcat commented 7 years ago

I modify in hrtf.c

Why? What's wrong with it, and how does it help here?

fatalfeel commented 7 years ago

no wrong, just support a answer, i use it in android and linux...

kcat commented 7 years ago

You shouldn't use hard-coded paths like that, it'll just cause more problems, and definitely won't help here.

fatalfeel commented 7 years ago

ok will be follow! and help me to look issue #106