Vahokif's picture

Managed audio

The great thing about GameWindow is that it talks to the system libraries directly, avoiding a native middleman, which is great because you can write AnyCPU OpenGL apps without having to run in 32-bit mode for SDL or Glut. However, this isn't the case for OpenAL. Are there any plans for a managed audio abstraction layer, avoiding OpenAL?


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

OpenTK is defined as an OpenGL/OpenAL/OpenCL wrapper for .Net, hence there are no such plans.

You *can* write AnyCPU applications that use OpenAL, as long as the correct OpenAL library is installed. This is always the case on Mac OS X and about 50% of Linux distributions. On Windows, you need to distribute and install oalinst.exe from Creative's website (you could do this as part of your installation or startup process) or use another workaround that does not require administrative rights.

There are several reasons why OpenAL cannot be replaced:

  • OpenAL is the only way to get hardware-accelerated sound on Windows.
  • OpenAL, unlike native APIs, implements 3d audio. Recreating this in managed code would be a larger project than OpenTK itself.
  • A managed audio layer would have to implement a large amount of backends to become usable: DSound, ALSA, OSS, PulseAudio and CoreAudio at the very least. Even these wouldn't be enough to achieve coverage equivalent to OpenAL.

I agree that OpenAL is problematic since it's not installed on all systems, but there is nothing OpenTK can do about that.

Vahokif's picture

What about DirectSound on Windows and OpenAL everywhere else? They have similar features.

the Fiddler's picture

It is quite possible to create a managed wrapper around DirectSound or XAudio (see e.g. SlimDX), but this project does not belong inside OpenTK.

For the record, DirerctSound is deprecated in favor of XAudio.

the Fiddler's picture

If your primary concern is using the same binary in AnyCPU mode, there is a relatively simple solution:

Compile OpenAL Soft for Windows in x86 and amd64 modes and add the dlls as resources into your application. At startup, check if you are running on Windows and extract the correct dll to a temp folder. Finally, p/invoke LoadLibrary() on this dll to load it into your process space.

This will ensure DllImports will work correctly regardless of the architecture, even if the user doesn't have OpenAL drivers installed.

Inertia's picture

With OpenAL you're facing the same problem as with OpenGL under windows: it is not as convenient as running dxsetup and you're done.

We've had some discussions about the topic already (search the forum for "installer") but IIRC the conclusion was that there's nothing we can do about it right now besides pointing towards http://www.opentk.com/doc/chapter/1/troubleshooting because you cannot even assume .Net|Mono to be present to run any driver installer you might come up with.

There's ofcourse alternatives like FMOD, BASS, etc. but OpenAL has it's syntax closely related to OpenGL and you will find your way around pretty easy. Once the appropriate AL driver is installed for the target platform, things go well in my experience.

Vahokif's picture
Inertia wrote:

With OpenAL you're facing the same problem as with OpenGL under windows: it is not as convenient as running dxsetup and you're done.

We've had some discussions about the topic already (search the forum for "installer") but IIRC the conclusion was that there's nothing we can do about it right now besides pointing towards http://www.opentk.com/doc/chapter/1/troubleshooting because you cannot even assume .Net|Mono to be present to run any driver installer you might come up with.

There's ofcourse alternatives like FMOD, BASS, etc. but OpenAL has it's syntax closely related to OpenGL and you will find your way around pretty easy. Once the appropriate AL driver is installed for the target platform, things go well in my experience.

The problem isn't availability but having to use a native library to talk to the system libraries, instead of talking directly to the system like GameWindow does.

Is it possible to use DirectSound/XAudio2 from an AnyCPU binary? SlimDX has seperate x86/x64 builds.

the Fiddler's picture
Vahokif wrote:
Inertia wrote:

With OpenAL you're facing the same problem as with OpenGL under windows: it is not as convenient as running dxsetup and you're done.

We've had some discussions about the topic already (search the forum for "installer") but IIRC the conclusion was that there's nothing we can do about it right now besides pointing towards http://www.opentk.com/doc/chapter/1/troubleshooting because you cannot even assume .Net|Mono to be present to run any driver installer you might come up with.

There's ofcourse alternatives like FMOD, BASS, etc. but OpenAL has it's syntax closely related to OpenGL and you will find your way around pretty easy. Once the appropriate AL driver is installed for the target platform, things go well in my experience.

The problem isn't availability but having to use a native library to talk to the system libraries, instead of talking directly to the system like GameWindow does.

Is it possible to use DirectSound/XAudio2 from an AnyCPU binary? SlimDX has seperate x86/x64 builds.

OpenAL *is* a system library on Windows, just like OpenGL. If you have the correct hardware you will see your sound card appear in OpenAL's device list. This device is hardware accelerated: OpenAL talks to it directly and offloads mixing and parts of the 3d calculations, according to its capabilities. Only if you *don't* have the neccessary hardware will OpenAL use DirectSound (or another system library) to render audio.

Note that OpenAL is the only audio library that supports hardware acceleration on Windows. DirectSound/XAudio are always software accelerated.

It should be possible to use DirectSound/XAudio from AnyCPU wrappers, but I am not aware of any such wrappers. However, before you actually commit to such a solution, make sure you are not taking a step in the wrong direction:

  • OpenAL *can* be used from AnyCPU applications.
  • OpenAL speaks to the hardware directly if you have the correct hardware. DirectSound/XAudio don't do that.

Edit: for the record, the UT3 engine relies on OpenAL (Mass Effect, Bioshock, etc...) It can't be that bad, right? :)