Ok, so thanks to the nice clean code from Laurent @ SFML (http://www.sfml-dev.org/) I was able to create a wrapper for an OpenAL sound player. It uses Libsndfile for most file format loading but can also load .ogg files (although no mp3 yet).
This is an of addon which enables you to plug different sound players in or out depending on your needs. So if you want to ditch FMOD in favour of a totally open source solution and use OpenAL then this is for you
So far there are FMOD and OpenAL backends, which you can switch by changing a #define statement. Shout out to Memo for the base classes which sped up the development of this package.
It’s an alpha release of sorts, but the OpenAL code is pretty solid. However, there are a few small differences from the current FMOD based ofSoundPlayer:
-
setMultiplay() only works on mono samples. In the FMOD version it also works on stereo samples. Neither version works with streams.
-
Streamed sounds can be mono or stereo, but the stereo versions cannot be panned. Stereo samples however _can_ be panned, as can mono samples.
-
ofxSoundGetSpectrum() is not yet implemented in the OpenAL version
-
setPosition() does not work on OpenAL streams (it works on samples though). but it will in the future
-
setSpeed() in the OpenAL player does not accept negative values, i.e. it can’t play backwards…yet!
I’ve implemented some experimental effects using the OpenAL EFX extension. They don’t work on OSX, work somewhat on Windows and work best on Linux. Sorry…this is not high priority right now.
If you are using an older version of OpenFrameworks (prior to 0.062) you may need to make a small modification to ofxThread. Please add this function to the ofxThread addon:
In ofxThread.cpp:
void ofxThread::waitForThread()
{
if (threadRunning)
{
// Wait for the thread to finish
#ifdef TARGET_WIN32
WaitForSingleObject(myThread, INFINITE);
CloseHandle(myThread);
#else
pthread_join(myThread, NULL);
#endif
myThread = NULL;
// Reset the thread state
threadRunning = false;
}
}
In ofxThread.h:
void waitForThread();
The addon example can be downloaded here:
http://code.google.com/p/digitalstarcode/downloads/list
On Windows and Linux I am using the OpenAL soft implementation (http://kcat.strangesoft.net/openal.html)
On OSX I am using the default OpenAL framework.
On Linux you need to install libsndfile and the OpenAL development packages from the repos:
sudo apt-get install libsndfile1-dev
sudo apt-get install libopenal-dev
I’ve included a static library of openal-soft for linux even though it is also in the repositories because the package version is not the latest, and the latest also had a bug in the echo fx code (which is fixed in my version thanks to the openal-devlist)
There are codeblocks projects for Linux and Windows, and an XCode project.
I’ve probably forgotten something, but give it a try and let me know how you go…