Open fbirot opened 4 years ago
I think the problem with any solution will be accessing files in the app sandbox. OpenAL Soft only uses standard I/O functions and no Java, so it can only read files that can be opened with fopen
/std::ifstream
. I don't know if those can read files in an Android app package or sandbox or whatever. Assuming it can, however, does Android not have the setenv
function to set the ALSOFT_LOCAL_PATH
or ALSOFT_CONF
environment variables? Is there no way to have those env vars set when your app executes?
I think using standard C function to read the file will work even if the file is in the app sandbox. We will test it and let you know. Yet, unfortunately there is no setenv
or equivalent function that can be called in java.
It is indeed possible to read a config file that is in the app sandbox from C/C++. We have tested replacing "/etc/openal/alsoft.conf" by a sandbox path in alconfig.cpp, and it worked. The only issue is that ReadOpenALConfig needs to have the appropriate config file path, which is dependent from the application.
Do you have recommendation on the best way to implement it ? I actually think that passing the path as an attribute to alcResetDeviceSOFT isn't the best way, because we already pass the id of the HRTF file that we want to use as an attribute to this function (ALC_HRTF_ID_SOFT), but we can't get the id of the hrtf if it doesn't already have the hrtf-path (which we would like to define in the config file). This mean that we would need to call alcResetDeviceSOFT two times (one time to set the path of the config file, and one to set the hrtf id).
So I think that it would be great to have a function that permits to set the config file path. What do you think ? If so, in which file would you put it and do you have advices on the name would you give it ?
Thanks
Sorry for the delay.
Presuming OpenAL Soft is able to get the executable path and name within the sandbox, it should load a config file in the same directory as the executable. You can either do that to set the hrtf-paths
config option, or set the current working directory to some place in the sandbox where the mhr files are.
No worries, thank you for your answer.
The problem is that, as far as I know, it is not possible to get the app/executable path from C/C++. So I think that the easiest way would be to get the config file path (or the path of the folder that contains the config file) in Java, and pass it to OpenAL Soft so that it can know where to look for the config file. But this mean that a new function should be created in OpenALSoft, to be able to pass that path.
So what about /proc/self/exe
that link to current executable?
Android 5.0 has setenv
which is most likely what you want, unless you're targetting as low as API 14.
On unrelated note, /proc/self/exe
works but that's most likely not what you want.
My apologies @khanhduytran0 , I had not noticed your message before now. Reading /proc/self/exe from C++ code would indeed probably work. I need to try that!
@MikuAuahDark : I don't remember whether we have tested that function and that it didn't work as expected or if we did not notice that this function exists (probably option 2).
Yet, we unfortunately need it to work for Android 4.4 also. For now, we have added a function "SetALConfigFilePath" in alconfig.cpp to be able to set the path of the configuration file. I think that in any way, it would be more handy to either have a way to set a config file path, or even better to configure everything from code without any config file.
Well, looking by it, the best option is to create thin wrapper in native code that simply expose setenv
C function to Java via JNI. Protip: If you're using SDL in Android, you can use nativeSetenv
function provided by SDLActivity
after you called super.onCreate
.
On unrelated note,
/proc/self/exe
works but that's most likely not what you want.
When I said that, I mean /proc/self/exe
won't return value you'd expect. In older Android it returns /system/bin/app_process
. I'd guess it returns internal path to some internal executable which most likely you won't have read (let alone write) access to.
@MikuAuahDark oh ok /proc/self/exe
is indeed not what we want. Making a wrapper function for setenv would probably be the best way, good idea (we are not using SDL)
For anyone still wondering how to do this, this info might help https://github.com/gkv311/sview/pull/125
Hello,
we are able to compile openalsoft for android without problems, but we would like to be able to configure it via a configuration file. The main reason why we would like to be able to use a configuration file is to set the hrtf-path, so that it points to a directory in our app where we put all the hrtf files. I've seen the issue https://github.com/kcat/openal-soft/issues/46 , but it did not help me much with this.
On iOS, we have managed to use a configuration file by setting the enviroment variable AL_SOFT_CONFIG so that it points to the file that is in the app sandbox. Yet on Android, it is not possible to set any environment variable. What I think would be great is to be able to either set the configuration file path from a function (that would be called from java code) or to be able to pass this path as an attribute when calling alcResetDeviceSOFT (for instance ALC_CONFIG_FILE).
What solution do you think would be best to implement ?
Thank you