Pulse Audio Driver
Archives Forums/Linux Discussion/Pulse Audio Driver
| ||
Below is a new pulse audio driver for BlitzMax Linux users. Before rebuilding modules grab the following two files and grab the PulseAudio headers using: sudo apt-get install libpulse-dev Many thanks to those that have the time to test, and don't forget to post your results and the version of Linux you are running. %BlitzMax%/mod/freeaudio.mod/pulseaudiodevice.cpp: // pulseaudiodevice.cpp // sudo apt-get install libpulse-dev #ifdef __linux #include "freeaudio.h" #include <unistd.h> #include <pulse/simple.h> #include <pthread.h> extern "C" audiodevice *OpenPulseAudioDevice(); void *pulseaudiothread(void*dev); #define LINUXFRAG 2048 struct pulseaudiodevice:audiodevice{ pthread_t audiothread; int threadid; int running; int playing; int error; short *buffer; int buffersize; //in bytes pa_simple *simple; static void *pulseaudiothread(void *arg){ pulseaudiodevice* audio; audio=(pulseaudiodevice*)arg; audio->run(); return 0; } int reset(){ pa_sample_spec stereo16; running=0; playing=0; stereo16.format=PA_SAMPLE_S16LE; stereo16.rate=44100; stereo16.channels=2; simple=pa_simple_new(NULL,"freeaudio",PA_STREAM_PLAYBACK,NULL,"playback",&stereo16,NULL,NULL,&error); if (simple==NULL) return -1; mix=new mixer(LINUXFRAG); mix->freq=44100; mix->channels=2; buffer=new short[LINUXFRAG]; buffersize=LINUXFRAG*2; pthread_attr_t attr; pthread_attr_init(&attr); running=1; threadid=pthread_create(&audiothread,&attr,pulseaudiothread,(void*)this); return 0; } int close(){ int timeout; running=0; timeout=500; while (timeout-- && playing){ usleep( 10*1000 ); } pa_simple_free(simple); return 0; } void run(){ int data; int res; playing=1; while (playing && running){ mix->mix16(buffer); int err=pa_simple_write(simple, buffer, buffersize, &error); if (err<0) break; } playing=0; } }; audiodevice *OpenPulseAudioDevice(){ return new pulseaudiodevice(); } #endif and backup then replace %BlitzMax%/mod/freeaudio.mod/freeaudio.bmx: Last edited 2011 Last edited 2011 |
| ||
Works great here :D (no sound before with FreeAudio Driver) I tried to SetAudioDrivers()[*] to * AudioDrivers()[0] 'OpenAl" AudioDrivers()[1] 'FreeAudio" AudioDrivers()[2] 'FreeAudio OSS" and every single of them worked. OpenAl seems to be a little bit more silent. I think this should be included in the next version. Last edited 2011 |
| ||
Thanks for testing. |
| ||
It worked! (Well, all of the drivers except "FreeAudio OSS", which apparently I don't have) Anyway, thanks a million! Mark, can this be made part of 1.42? Russell |
| ||
Did I forget a lib or something? Ubuntu 10.10. Compiling:pulseaudiodevice.cpp /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp:6: error: invalid preprocessing directive #Include /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp:8: error: invalid preprocessing directive #Include /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp:9: error: invalid preprocessing directive #Include /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp:10: error: invalid preprocessing directive #Include /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp:97: error: invalid preprocessing directive #EndIf /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp:4: error: unterminated #ifdef /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp:12: error: expected constructor, destructor, or type conversion before string constant /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp:18: error: expected class-name before €{€ token /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp:19: error: €pthread_t€ does not name a type /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp:20: error: €Int€ does not name a type /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp:22: error: €Int€ does not name a type /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp:23: error: €Int€ does not name a type /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp:24: error: €Int€ does not name a type /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp:26: error: ISO C++ forbids declaration of €Short€ with no type /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp:26: error: expected €;€ before €*€ token /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp:27: error: €Int€ does not name a type /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp:29: error: ISO C++ forbids declaration of €pa_simple€ with no type /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp:29: error: expected €;€ before €*€ token /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp:38: error: €Int€ does not name a type /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp:67: error: €Int€ does not name a type /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp: In static member function €static void* pulseaudiodevice::pulseaudiothread(void*)€: /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp:35: error: €Return€ was not declared in this scope /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp:35: error: expected €;€ before numeric constant /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp: In member function €void pulseaudiodevice::run()€: /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp:79: error: €Int€ was not declared in this scope /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp:79: error: expected €;€ before €data€ /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp:80: error: expected €;€ before €res€ /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp:82: error: €playing€ was not declared in this scope /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp:83: error: €running€ was not declared in this scope /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp:83: error: €While€ was not declared in this scope /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp:83: error: expected €;€ before €{€ token /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp: At global scope: /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp:93: error: expected constructor, destructor, or type conversion before €*€ token Build Error: failed to compile /home/kedric/BlitzMax/mod/pub.mod/freeaudio.mod/pulseaudiodevice.cpp |
| ||
No, you pasted cpp code into a BlitzMax file so it got capitalized. In MaxIDE you should have saved a new file as .cpp THEN pasted the code. Last edited 2011 |
| ||
Ohhh... Yikes. Sorry about that. :/ Edit: Works amazingly! Last edited 2011 |
| ||
works great! |
| ||
aparently I'm doing something wrong here. |
| ||
nevermind, got the package to download :D will be testing as soon as I work in the headers |
| ||
It works! :D thanks bunches! |
| ||
If you are running in Ubuntu 11.04, use Synaptic Package Manager and search for libpulse-dev. Mark it for installation and then allow it to select the rest of what it needs. Apply the changes and then proceed with the rest of the changes skidracer describes :) |
| ||
I have Ubuntu 11.04 and for me this driver works only in debug build. A pity since original OSS driver for MAX has pretty bad compatibility with various Linux distros. EDIT: Ok, now it works also in the release mode. I was putting some WriteStdouts in the freeaudio.bmx to see what went wrong and it started to work somehow :) Thanks a lot for this driver. Last edited 2011 Last edited 2011 |
| ||
I've waited a long while to get linux blitzmax sound and I'm almost there. I've never worked at this low level before so excuse ignorance. I managed to follow the instructions: 1. Install libpulse-dev 2. New file: BlitzMax\mod\pub.mod\freeaudio.mod\pulseaudiodevice.cpp 3. Replace BlitzMax\mod\pub.mod\freeaudio.mod\freeaudio.bmx 4. Rebuild all modules Result: sound works in Debug mode only. Checked BlitzMax\mod\pub.mod\freeaudio.mod\ and found only 4 files with today's date - the above two and: freeaudio.debug.linux.x86.i freeaudio.debug.linux.x86.a I guess my problem is that they both say "debug" but I don't know what to do about it! Hope someone can help. Peter PS I'm using Ubuntu 10.04 on a USB. Last edited 2011 |
| ||
You can recompile the mod manually from the shell in non-debug mode. from the blitzmax/bin folder: bmk makemods -a pub.freeaudio and the threaded version: bmk makemods -a -h pub.freeaudio (The -a forces the recompile even when it thinks it probably won't need it) |
| ||
Or you could try rebuilding modules again, I think it is most likely you interrupted the process before it finished or there was an error that you missed. |
| ||
Thanks to you both. @skidracer - I had tried that already - there is a Compile error right near the end but I've always had that. @xlsior worked fine - but for the benefit of any other Linux noob reading this ... I had to precede bmk with "./" Again ... many thanks to you both ... this is gonna make a lot of people happy! Peter |
| ||
Report: Built app on Ubuntu 10.04 Result successfully run on Ubuntu 10.04 Linux Mint 11 Fedora 14 but on Debian 6.0.2 got "Assertion 's' failed at pulse/simple.c:256, function pa_simple_free()" and app aborted. Peter PS All Linuxes on USB |
| ||
App also successful on OpenSUSE 11.3 (Live CD version) Peter |
| ||
Thanks Peter, I will post a fix soon for your Debian config so it doesn't crash. |
| ||
I have solved my problem on Debian by installing PulseAudio using the commandapt-get install pulseaudio Peter |
| ||
After making these changes, my MacIDE is hanging during at freeaudio when building modules. Any ideas? |
| ||
Yes, for me hangs in build modules means a syntax error. |
| ||
Works fine in ubuntu 10.4 (dell laptop, max 1.45) in debug or release mode. Sound working fine with old freeaudio driver too. When I get the drivers: For Local driver:String = EachIn AudioDrivers() Print driver Next It gives "FreeAudio, FreeAudio OpenSound System, Null" and both work. I don't know how to set up OpenAl on linux so I can't test it. Last edited 2011 |
| ||
Ho my... You save my life Skid ! Working perfectly on a Mint Distro. Does the users is required to install something related to the pulse driver or does the source dev. code does everything ? Man! The Default Freeaudio driver sux. This must be official. |
| ||
The feedback I've got from my customers is that the pulse audio driver is just as flaky as the default driver, with the downside of not being as commonly installed on systems. The only consistent driver on Linux seems to be the OpenAL one. In the end though I just allowed the end user to select which driver worked for them. |
| ||
Bad... Linux... really ! Can you believe that my current Nvidia driver isn't good too ? My Cg isn't correctly supported ! And about OpenAL ? Do you have to install the redistribuable to hear something like in Windows ? Because with OpenAl on my system after 3 songs everything is mute ! Last edited 2012 |
| ||
Is user required to install something related to the pulse driver or does the source dev. code does everything ? No your users do not need to install anything. There is also an issue with freeaudioaudio.bmx in brl.mods/freeaudio where free audio driver names have been hard coded. Ideally ALSA, OSS and Pulse should all be listed if mountable. I have no idea of the implications of OpenAL on Linux, as long as it plays nice with the other mixer API's in the system and the user has correct speaker and headphone levels. |
| ||
Hi skidracer ... good to see you back in this thread - does this mean that you might now be able to attend to my problem? Thanks Peter, I will post a fix soon for your Debian config so it doesn't crash. Thanks ... Peter |
| ||
A fix for that problem would be awesome ! Something to draw back to OpenAL like Odd suggested ? I probably need to find how to use it by default, hope it's not a breaker. |
| ||
The feedback I've got from my customers is that the pulse audio driver is just as flaky as the default driver, with the downside of not being as commonly installed on systems. Whatever the reasons most Linux users simply refuse to install the PulseAudio driver and find it more easy to ask the developer himself to implement an abstraction layer like OpenAL. The thing is that OpenAL module is BUGGY like FreeAudio so if I do understand nothing for sounds is really working under Linux... Will someone address this problem once and for all? I cannot fix my game under Linux because of that and it breaks my balls. |
| ||
Agreed! Audio in Linux, and especially as it pertains to BMax is really disappointing. I can't imagine why this is still an issue after all these years... (For Linux and Bmax as well). Russell |
| ||
Yes but how do I SetAudioDriver() to Pulse Audio Free Audio? I include Import pub.freeaudio SetAudioDriver("PulseAudio") And the terminal says: austin@austin-Inspiron-N5110:~$ sudo apt-get install libpulse-dev [sudo] password for austin: Reading package lists... Done Building dependency tree Reading state information... Done libpulse-dev is already the newest version. The following packages were automatically installed and are no longer required: wine1.3-gecko python3.2 gettext libpython3.2 libunistring0 python3.2-minimal Use 'apt-get autoremove' to remove them. 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. austin@austin-Inspiron-N5110:~$ Last edited 2012 |
| ||
As long as rebuild modules finishes without errors then you should be OK. You don't need the SetAudioDriver as it is hardcoded for Linux. Have you tested your setup with other music / sound players to make sure your basic Linux audio is working? |
| ||
Yes I have tested my linux audio. My media player works fine. Is this designed to work on Ubuntu 11.10? Do I need to import the module like Import BRL.FreeAudioAudio or Import pub.freeaudio??? Am I forgetting something? |
| ||
My son just installed Ubuntu on an old Dell laptop so I am planning on testing BlitzMax audio support soon. If you want to be pragmatic you should consider avoiding Linux altogether. Spend the time writing better games for Mac OS/ Windows. |
| ||
What a coincidence, I installed Ubuntu on my dell laptop too! :D Not old though (Inspiron 15R N5110) Last edited 2012 |
| ||
How exactly am I supposed to set the driver to free audio properly? I followed all the steps in the first post but no sound :( SRS Premium Sound |
| ||
Shouldn't this be:static void *pulseaudiothread(void *arg){ pulseaudiodevice* audio; audio=(pulseaudiodevice*)arg; if (audio) { audio->run(); return 0; } else { return audio; } } Now I'm just guessing - didn't test it yet, but maybe with this change, this could work: device=OpenPulseAudioDevice() if (device=null) then device=OpenALSADevice() Edit 2: After changing it I'm having other problems - now everything I compile it hits me with 'undefined reference to `pa_simple_write' - and I do have pulseaudio and libpulse-dev installed :( |
| ||
It's been ages since I did any thing C/C++ related, but I would have thought that pulseaudiothread would need to return a value my self instead of void. |
| ||
That's what I tought - but looking at the OSS and Alsa drivers, they are implemented the same way, with "void". Edit: found out my problem, I forgot to include Import "-lpulse-simple" in freeaudio.bmx. Now it compiles and appears to work ok. Just have to test on the liveCD to see if the program crashes because it doesn't have pulseaudio as default. Edit: No crashes! I even remove pulseaudio from the live-cd (with apt-get remove pulseaudio) and it worked without any issues :) |
| ||
Trying this on Ubuntu 12.04. Not working. Followed all of Skid's original advice. Just not getting any sound. What can I do to test if I have everything set up correctly? |
| ||
Got OpenAl to Works on Ubuntu 13.04 I created the files separately and pasted in the code and saved them, then put them in the respective dirs. Didn't use blitzmax to make the files, as that was one of the issues I read some where. |
| ||
If anyone is using this driver / wants it added to the official blitzmax git, please reply. If a moderator reads this, please unpin. |
| ||
Shouldnt we use the freeaudio thing adjusted by brucey to runtime link to pulseaudio? Without runtime linking ("on request") your app will require pulseaudio libs even when using alsa. So apps might not run on certain distros (which is why I have to do two linux builds of my game...with and w/o pulseaudio). Or did I mix things up now? Bye Ron |
| ||
link? |
| ||
Starting at post #30 (#30 - runtime linking for alsa, #49 brucey added runtime linking for pulseaudio) This results in: https://github.com/maxmods/pub.mod/tree/master/freeaudio.mod which leads to v1.23: ModuleInfo "History: 1.23" ModuleInfo "History: Use ALSA instead of OSS on Linux." ModuleInfo "History: Added PulseAudio driver as default Linux sound driver." ModuleInfo "History: ALSA and Pulse audio drivers now link at runtime." bye Ron |