Saturday, December 22, 2007

Open Source Audio on Windows with OpenAl.Net and Tao.OpenAl

I for some reason have a passion for Open Source Audio on Windows. I've got no idea why I don't just cross over and use Linux and its already fantastic collection of Audio programs (Hydrogen - an advanced drum machine, Rosegarden - Composition tool with MIDI support, Ardour - professional audio editing, multi-track audio mixing etc.) but for some reason I just enjoy C# and the IDE so I'm not moving, at least for the time being ;-)

Any way to get going with Open Source audio libraries in the .Net world there are a few good choices - so far I've used SDL.Net and OpenAl.Net (With Tao.OpenAl - it's a dependency for OpenAl.Net and Tao.SDL - it's a dependency for SDL.Net) and have had really good results.

Currently OpenSebJ - vScaleNotes, the high quality audio, fully sampled, virtual instrument tool, utalises SDL.Net for all of the sample playback and it will soon be using OpenAl.Net for all of the stream to disk recording.

I'm starting down the path of migrating OpenSebJ to Open Source only dependencies, currently OpenSebJ still requires the Managed DirectX libraries to function and as I've spoke of previously, accessibility is a serious issue here - that and the fact that Microsoft aren't further developing the MDX libraries. So a serious port is needed here, hopefully my object encapsulation is going to make this fairly easy ;-) Although I know some functions won't be supported going forward.

The fun part about using these libraries is making sure that you can package all of the dependencies in a single installer and make it really easy for people to use, rather than requiring a separate installation - some times though, the documentation can be a little lacking. So here's a little documentation for those looking for the requirements:

OpenAl.Net
OpenAl.Net requires the Tao.OpenAl framework; the Tao.OpenAl framework does the leg work interop'ing with the OpenAl DLL's.

To use OpenAl.Net in your project:
  1. Add a dependency linking to OpenAl.Net
  2. OpenAl.Net has a dependency to Tao.OpenAL but if you load Tao.OpenAl into your project make sure it is linked properly
  3. Make sure the OpenAl DLL's are accessible, for instance in the output directory. You need alut.dll , OpenAL32.dll & wrap_oal.dll - if you don't have all 3, like if you only have alut.dll you will get an error message from the compiler saying that it can't find alut.dll - you need the other ones even though the compiler error message is wrong - I hate that, any way that's why I'm writing this ;-)
  4. So in your directory with your program you should have alut.dll , OpenAL32.dll , wrap_oal.dll , OpenALDotNet.dll , Tao.OpenAl.dll , AdvanceMath.dll , csogg.dll , csvorbis.dll

SDL.Net

Similar to OpenAL.Net SDL.Net needs Tao.SDL to do the leg work with the underlying SDL DLL's. SDL.Net is fairly similar to setup but doesn't have audio recording support.

To use it in your project:
  1. Add a reference to SDL.Net
  2. SDL.Net has a dependency to Tao.SDL but if you load Tao.SDL into your project make sure it is linked properly
  3. Make sure the SDL DLL's are available - you need a copy of SDL.dll , SDL_gfx.dll , SDL_mixer.dll - just throw them in the output directory if you don't care about locations ;-)
  4. Now in the output directory you should have SDL.dll , SDL_gfx.dll , SDL_mixer.dll, SdlDotNet.dll & Tao.Sdl.dll

The really cool thing is that all of these files can be bundled in the installer. Keep a copy of the original sources, as per the GPL and make sure they are included or accessible. Too easy, well once you know the score any way.

Happy Open Source Audio Programing ;-)

No comments: