Now that I’ve played around with irrKlang a bit, it’s time to write down a first resume. The first and best experience was how easy irrKlang was to integrate.
As I wrote in my comparison, irrKlang has a straightforward and intuitive interface and it took me about an hour to integrate a first iteration into our DVW sound library. irrKlang has so-called File Factories which can be registered with the irrKlang device and allow to overwrite file access. Doing this was just a matter of creating two classes and implementing the interface methods. This way, I could easily use our own virtual filesystem to provide irrKlang with the data from our audio files. irrKlang also allows to setup default parameters for the sound sources and sounds which are created by irrKlang; this way, you don’t need to set parameters like volume or attenuation by distance each time you play a sound effect, irrKlang sets them automatically according to your defaults. irrKlang also offers to take over the threading itself and to listen for application focus changes in order to mute the sound if the application loses it. (I gladly accepted both options.) Fortunately, Niko has also provided quite a comprehensive documentation including some basic tutorials.
Since irrKlang was up and running so quickly, I quickly ran across some bugs though. Firstly, I recognized that the attenuation by distance does not work as expected. Setting a maximum distance and moving a sound farther from the listener doesn’t mute it, instead it’s still audible (someone already reported this bug in the forums but it looks to me like Niko didn’t quite get the problem – or neither the thread author nor me understood how attenuation by distance works). Secondly, I heard a crackle when I played long repeating sound effects. This was also reported on the forums. Niko suggested to update, but since I’m working with the latest version this issue obviously isn’t fixed yet. The workaround Niko presents works, though, but it’s definitely not an optimal solution. Finally, most but not all things are covered in the documentation. For example, it does not lose a single word about the IRRKLANG_STATIC macro which you need to define in order to link irrKlang statically if you have purchased a commercial version.
Niko, for your convenience I have prepared a little snippet. 😉
[source:cpp]#include
#include
#include
#pragma comment( lib, “irrKlang.lib” )
using namespace irr;
using namespace audio;
using namespace core;
int main( int argc, char* argv[] )
{
ISoundEngine* engine = createIrrKlangDevice(
ESOD_AUTO_DETECT,
ESEO_MULTI_THREADED | ESEO_MUTE_IF_NOT_FOCUSED | ESEO_USE_3D_BUFFERS
#ifdef _DEBUG
| ESEO_PRINT_DEBUG_INFO_TO_DEBUGGER
#endif
);
engine->setDefault3DSoundMinDistance( 20.0f ); // sound reaches its maximum volume if the distance is <= 20
engine->setDefault3DSoundMaxDistance( 100.0f ); // sound should get inaudible if the distance is > 100
vector3df pos( 0, 0, 0 );
vector3df lookdir( 0, -1, 0 );
engine->setListenerPosition( pos, lookdir );
// Take a long sound effect which does well for looping.
// Remove the second, optional parameter to hear the crackle when looping.
ISoundSource* source = engine->addSoundSource( “Drohne.wav”, ESM_NO_STREAMING );
// Create a sound effect at the very left side…
pos.X = -200.0f;
ISound* sound = engine->play3D( source, pos, true, false, true );
// …and then move to the right.
// The sound should start getting louder at -100 but is already audible at -200,
// and vice versa when it moves to the right side.
for( ; pos.X < 200.0f; pos.X += 1.0f )
{
sound->setPosition( pos );
std::cout << pos.X << " " << std::endl;
Sleep( 20 );
}
sound->drop();
engine->drop();
return 0;
}
[/source]
Update
Niko was able to reproduce this problem, seems to be a DirectSound issue. He promised the next release would have this bug fixed.
Published on October 28, 2007