Jump to content
The Dark Mod Forums

Playing Sounds using OpenAL


Recommended Posts

I've managed to play WAV files from within DarkRadiant using a newly written AudioManager module, which is basing on the OpenAL architecture. So far I did it in Linux only, I'll have to check if the support for OpenAL in Windows is sufficient.

 

There is a tutorial available for playing OGG sounds as well, which will be needed in order to play the Doom3 sound shaders.

 

The current AudioManager interface is fairly simple:

class IAudioManager
{
public:
INTEGER_CONSTANT(Version, 1);
STRING_CONSTANT(Name, "audio");

// Tries to load and play the sound from the given <fileName>
virtual void playSound(const std::string& fileName) = 0;
};

At the moment, only WAV files are supported, I haven't implemented the OGG support yet. I'll first go back to Windows and try to setup the required libraries and headers. If I don't succeed with the Windows support, there's no point in going further in Linux either, but I'm positive here.

 

I'll commit the current module soon.

Link to comment
Share on other sites

It's great that this is being looked into, but are you sure than OpenAL isn't overkill for such a simple task? The webpage seems to focus on 3D spatial sound (as used in games) rather than simple playback of wave files.

 

You might want to look into PortAudio as a solution more taylored to simple sound playback.

Link to comment
Share on other sites

Hm, the PortAudio stuff seems to be more complicated than the OpenAL interface.

 

This is needed in OpenAL to play a sound:

virtual void playSound(const std::string& fileName) {
	std::cout << "Playing sound.\n";

	_buffer = alutCreateBufferFromFile(fileName.c_str());

	// Assign the buffer to the source and play it
	alSourcei(_source, AL_BUFFER, _buffer);
	alSourcePlay(_source);
	alutSleep(0);
}

Whereas PortAudio is setup with streams and callbacks and operates at low level (from what I understand). example Are you sure that this is the better library here? I did a quick google for "portaudio ogg" and this didn't yield very many references.

Link to comment
Share on other sites

Ah well, if it is that easy to use OpenAL then we might as well go with it.

 

I'm pretty sure that PortAudio won't support Ogg directly, you would need to use libogg/libvorbis to decode it first. If OpenAL supports Ogg Vorbis natively then this is another plus.

Link to comment
Share on other sites

There is this tutorial on playing OGG files with OpenAL and it doesn't appear too hard (the ogg libraries are of course needed here as well).

 

Still, I have to check, if the Windows support is sufficient - this might be a show stopper for OpenAL too.

Link to comment
Share on other sites

I'm pretty sure all of these are cross platform libraries, so I don't see that there would be any showstoppers on Windows. It might require some messing around with DLLs just like GTK does, but that is not insurmountable.

Link to comment
Share on other sites

The windows build is now OpenAL-enabled as well, this was rather easy. It took longer to recompile from scratch than to find the libraries and to adapt the sconscript. :)

 

I originally planned to add this method to the GlobalAudioManager interface:

virtual void playSoundShader(const std::string& soundShader) = 0;

which resolves the soundshader information, takes the according sound and passes them to playSound() which in turn catches the OGG files and takes the right action.

 

There is the other sound module which already parses the soundshaders. To avoid fuzzy competences between these two modules, what do you suggest as the right workflow/dependency here: should the AudioManager (or SoundManager or whatever it will be called in the end, I'm open to suggestions) be the client of the Sound module or the other way round? Or something completely else?

Link to comment
Share on other sites

There are two options I can see:

 

1. The existing sound module parses the shaders, and allows you to retrieve a sound data object of some sort which can be passed to the audio module to play via OpenAL. The audio module would have no knowledge of shaders or files, it would just accept the audio data passed to it.

2. The two modules are merged into one -- a client could query the list of sound shaders, and then instruct the module to play a particular sound from an existing shader (or from the VFS itself).

Link to comment
Share on other sites

Placing Speaker entities has always been possible in DarkRadiant (since 0.9.0 there is also a sound shader selector list available).

 

After we're finished with this you will be able to click on a sound shader, see the encapsulated sound files and hear them as "preview".

Link to comment
Share on other sites

Yes, these files are required for the latest SVN build (they aren't included in the previous releases).

 

There is an OpenAL installer for Windows here: http://developer.creative.com/articles/art...p=38&aid=46

 

And the freeAlut library (alut.dll) can be downloaded here:

http://openal.org/openal_webstf/downloads/...t-1.1.0-bin.zip (take the DLL from the lib/ folder within and move it into your Windows\system32\ folder).

 

Both links above are from http://openal.org/downloads.html, btw.

Link to comment
Share on other sites

The OGG playback basically works now, with some issues:

 

- The Linux OGG playback sounds like crap, at least on my system. The Win32 playback is fine.

- Some OGG files refuse to play. I can play them with a media player, but not in DarkRadiant (Linux and Win32).

- Some sounds get cut off a bit at the end (Linux and Win32)

 

Apart from that, the functionality is there. As I was somehow unable to compile the libvorbis/libogg libraries on my own using MinGW, I downloaded the according DLLs from some other SVN repository and the vorbisfile.dll from some DLL-downloading site. Not very professional, but I didn't want to spent the whole day with just the libraries, and it seems to work for now.

 

If anybody has troubles getting DarkRadiant to work under Windows, the according DLLs can be found in darkradiant\w32\vorbis\lib, place them somewhere in your PATH.

 

Under Linux, the libvorbis-dev package is needed, I'm sure you'll find it easily in Synaptic or using emerge.

Link to comment
Share on other sites

Ok, I could resolve the two major issues (sounds got cut off at the end, some sounds not playing at all). Maybe this resolves the Linux issue (crap playback quality) as well, I'll have to check that.

Link to comment
Share on other sites

The playback quality is still crap in my Linux, I can't see what I can do about this (WAV files are play fine as far as I can tell).

 

Maybe you (OrbWeaver or mohij) could check this on your end as well? You'll need to install the libvorbis-dev package to test it. Just create a speaker and choose a sound shader from the Entity Inspector (after adding the s_shader spawnarg).

Link to comment
Share on other sites

I already tested with a few sounds, but I haven't seen any OGG files so far.

I think all of the vanilla Doom 3 sounds are OGGs, the extension in the shader is ignored or at least automatically corrected when the wav file is not found. That's what the SoundManager currently does as well.

 

Hmmm, it looks for an ogg.dll when I start up, but I can't find it in the drsource directory.

 

Edit: Got it working by renaming libogg.dll and libvorbis.dll to 'ogg' and 'vorbis'. Plays ogg and wav perfectly. :)

Hm, I didn't need to rename any file, but maybe there have already been some DLLs installed by other applications or packages on my end. We'll have to check that before the next release, I've already added this to the memo issue on the tracker.

 

Thanks for testing!

Link to comment
Share on other sites

Yes, there are quite a few soundshaders that refer to non-existent sound files. It was a bit annoying during development, because I couldn't tell if the sound module wasn't working or the sound file actually didn't exist (I had to dig up the according path in the game003.PK4 each time).

 

However, all of the Dark Mod-specific sounds seem to work correctly, which is the more important thing. :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recent Status Updates

    • taffernicus

      i am so euphoric to see new FMs keep coming out and I am keen to try it out in my leisure time, then suddenly my PC is spouting a couple of S.M.A.R.T errors...
      tbf i cannot afford myself to miss my network emulator image file&progress, important ebooks, hyper-v checkpoint & hyper-v export and the precious thief & TDM gamesaves. Don't fall yourself into & lay your hands on crappy SSD
       
      · 2 replies
    • OrbWeaver

      Does anyone actually use the Normalise button in the Surface inspector? Even after looking at the code I'm not quite sure what it's for.
      · 7 replies
    • Ansome

      Turns out my 15th anniversary mission idea has already been done once or twice before! I've been beaten to the punch once again, but I suppose that's to be expected when there's over 170 FMs out there, eh? I'm not complaining though, I love learning new tricks and taking inspiration from past FMs. Best of luck on your own fan missions!
      · 4 replies
    • The Black Arrow

      I wanna play Doom 3, but fhDoom has much better features than dhewm3, yet fhDoom is old, outdated and probably not supported. Damn!
      Makes me think that TDM engine for Doom 3 itself would actually be perfect.
      · 6 replies
    • Petike the Taffer

      Maybe a bit of advice ? In the FM series I'm preparing, the two main characters have the given names Toby and Agnes (it's the protagonist and deuteragonist, respectively), I've been toying with the idea of giving them family names as well, since many of the FM series have named protagonists who have surnames. Toby's from a family who were usually farriers, though he eventually wound up working as a cobbler (this serves as a daylight "front" for his night time thieving). Would it make sense if the man's popularly accepted family name was Farrier ? It's an existing, though less common English surname, and it directly refers to the profession practiced by his relatives. Your suggestions ?
      · 9 replies
×
×
  • Create New...