Dynamical Lib-Linking (PulseAudio only when used)

Archives Forums/Linux Discussion/Dynamical Lib-Linking (PulseAudio only when used)

Derron(Posted 2014) [#1]
Hi.

the last days I communicated a lot with a user because he had trouble getting PulseAudio to work in his slackware installation.

He never needed PulseAudio - except my game uses it because it relies on rtAudio.

rtAudio itself can use multiple engines. So you init the audiodriver for "PulseAudio" to use PulseAudio, you use "Alsa" for Alsa and so on.

Now this principle includes the requirement of installing "pulseaudio" - which is a no go for some users (or they do not have the privileges to do so).

So what I seem to need is this: checking for an installed pulseaudio, if not installed, do not use it at all and use Alsa for it. Sounds like something in the likes of "dynamical library linking/loading".

If not possible it all ends in creating a bunch of binaries for each "exceptional case" ... a "gameNoPulseAudio", a "gameNoAL", a "game", ...
For "opengl" it works with "try catch" and then falling back to directx (of course on Windows).

It is similar to this Post without an answer.


Is there anybody out there with a "practical" solution to this problem?



EDIT: I tried to set "LINUX_ALSA" as "to use audio driver" on a Knoppix live (no pulseaudio installed but "pulse-simple") but it throws an rtError that the output cannot be started because of "Device or resource busy". This is the same error I get when using Alsa on my local computer while playing an internet radio stream. As rtAudio writes to "std:cerr" Blitzmax thinks it is a real error (even if only a warning) and ends the program... hmpf.


EDIT 2: ok I have redone some parts of rtAudio so it does not spit out errors if an engine is not initiateable - means, I can now traverse through all potential engines and if none of them inititialized successful, I can switch my sound engine to "do nothing".

For this:
- open up maxmod2.mod/rtaudio.mod/rtaudiodriver.cpp
- search for RtAudioDriver::Startup(){
- replace
		audio->openStream( &parameters, NULL, RTAUDIO_FLOAT32, 44100, &bufferFrames, &RtCallback, this, &options );
		audio->startStream();


with
	//Ron: wrap try-catch around so "false" can get returned
	try {
		audio->openStream( &parameters, NULL, RTAUDIO_FLOAT32, 44100, &bufferFrames, &RtCallback, this, &options );
		audio->startStream();
	}
	catch( RtError& e ) {
		//e.printMessage();
		return 0;
	}


If you still want the error message to get displayed each time: uncomment e.printMessage();

Now TMaxModRtAudioDriver.Init(engineName) returns False or True. Prior it never returned on initialization errors (rtAudio with its rtError writes to std::cerr - even for warnings, but BlitzMax is recognizing it as something to stop the application).


But the original problem - of the binaries needing "libpulse-simple.so.0" is still existent.
Ideas?


bye
Ron


Armitage 1982(Posted 2014) [#2]
Hi Ron

Guess what!
I'm the author of "this Post without an answer." and, just like you, I'm back because a Linux user refuse to install PulseAudio on his system.

Unfortunately, I'm here to find answers too and I don't have any solutions :(
The worst is I remember hacking freeaudio.mod in order to switch from PulseAudio to the default broken BlitzMax Audio driver and eventually turning off the Audio support if no solution is to be found.
My whole project is on my old computer with BlitzMax 1.48 and a Mint distro (probably 2012). I don't think upgrading anything is currently possible for me. I remember customizing some others modules for my own needs so it's a tricky situation. Plus no official patch was made since then and I completely dropped BlitzMax...

I don't remember if I tried the fix from skidracer (from OSS to ALSA), maybe I will try before anything else.

So with each new version of Linux this problem will reappear again and again?

I can't believe Mark didn't fix that problem since all this time.
Linux users are far more difficult to manage.


Derron(Posted 2014) [#3]
For me I solved this currently in a cumbersome way:

I have "rtAudio.mod" and a "rtAudioNoPulse.mod". The NoPulse one just links everything from rtAudio.mod ("../rtAudio.mod") but leaves out the definition of PulseAudio, so it wont get linked during module building.

Now I have in my source this line

Import maxmod2.rtaudio
'Import maxmod2.rtaudionopulse

If I need a binary without pulseAudio, I comment the first out and uncomment the second one.

Tedious, but works at least.


Think similar can be done with freeaudio.


bye
Ron


Armitage 1982(Posted 2014) [#4]
Sorry for what I'm gonna say but...
It's a non sense :s

I also have a similar switch system with a freeaudio mod hacked to bones but it won't work in this case.

I may eventually build a separate ALSA version of the executable and pack it along the default one but geez ! What the heck with that "Linux" !?

Plus this solution is not compatible with all the Store that require a single executable like Desura or Steam...

Is there anything I can plug to quickly switch my old 1.48 BlitzMax system in ALSA build and forget about it ?
I don't have a single idea of what is rtAudio. Will it work better than the ALSA Skidracer fix ?

Thanks


Armitage 1982(Posted 2014) [#5]
Look like I've been able to build a separate ALSA version of my game thanks to the Skidracer Patch.

Once again, it gives various results. Both works correctly for me but some users report weird music play rates.
At least no more crash for this version and good SFX output :)


Derron(Posted 2014) [#6]
it is similar to freeaudio but maxmod2 (with its rtaudio backend) allow streaming audio - which is a must for me as I allow custom playlists (my game has some modding options).

As it is opensource/freeware I do not care if it contains 1,2,3... binaries - albeit I do not like the hassle of building all of them each time I release a "monthly zip".

The only way I know to work: let the user define what he wants before _he_ compiles the binary himself.
Another option is something like "dynamic linking", so as long as nothing requests pulseAudio/alsa, its libs wont get loaded (or tried to load).
But such a thing is way out of my skill/time (more skill than time problems :D).

PS: rtAudio is using Alsa differently to freeaudio (I have problems with simultaneous audio from "rtaudio-alsa" and other apps playing audio while this works with freeaudio. So on my machine I have to use the pulseAudio-driver).


bye
Ron


Derron(Posted 2014) [#7]
I just asked skidracer by email ... if he sees a possibility to move the dependency from "start" to "request" (so only if you request to init with pulseaudio, it is tried to load the dependency).

I also asked if he could add some "data loader"-callback-function (you call it with offset etc - and it returns a datablock for playback) as this would allow to code streamed playback.


bye
Ron