Skip to main content
GameDev.net gamedev.net
🔒 Locked

Using SDL from within .NET

Started by benryves Sep 29, 2005 at 5:13 AM 7 replies 4.4k views
Original Post
benryves
benryves
Looking for the above brought up something called SDL.Net, which seemed a bit of a problem as it was not simple and didn't allow me to directly use the sound hardware. Which is why I want SDL in the first place! [smile] Unless there is a way to get around that... I tried declaring the SDL calls inside VB.NET, and SDL_Init() returned zero (whether that means "it works!" or "that function did nothing and returned zero as a default", I'm not so sure) but got stumped as to how I should declare the SDL functions to open an audio device and provide a callback function (which is what I need, after all). So, er, is there anyone who has managed to use SDL properly from within .NET?
[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]
Rob Loach
Rob Loach
SDL.NET makes reference to SDL through the Tao Framework's Tao.Sdl. It provides direct bindings to SDL using P/Invokes within the assembly. I think this is exactly what you're looking for. They're still working on providing prebuilt DLLs of the assembly published on their website, so in the mean time, you can get my build of Tao.Sdl right here. All you have to do is reference Tao.Sdl.dll, have the XML file in the same directory as the DLL and you're set to make direct calls to SDL.
Rob Loach [Website] [Projects] [
benryves
benryves
Heh, I just PMed you, so ignore that - looks like you've answered my question!
If all I want is plain SDL, which DLL do I need? Just the Tao.Sdl.dll?
[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]
Rob Loach
Rob Loach
Haha, I just saw that PM.... Anyway, yup, you're right! If you want to use SDL in .NET, all you need to do is make reference to Tao.Sdl.DLL and then you'll have access to the Tao.Sdl namespace which has bindings to SDL in classes like the Sdl class (for bindings to SDL), the SdlGfx class (bindings to SDL_gfx), SdlNet (for SDL_net), etc. Of course, you'll need to include the SDL dependancies (sdl.dll) in with your compiled application path.

If you want to have the in-code documentation (ex documented intellisense), you'll have to put Tao.Sdl.xml in the same directory as where you made reference to Tao.Sdl.dll. Also, you don't even really need the whole DLL; you could just include the individual Tao.Sdl classes you need with your project since the Tao libaries are released under the (very open) MIT licence. You can find the source here or as a tarball here.

I'ver never used the basic SDL audio system, is it worth looking at?
Rob Loach [Website] [Projects] [
samuraicrow
samuraicrow
SDL_Mixer is a wrapper for MikMod and can therefore play most music module formats. It can also play .OGG files and .WAV files. The Linux version plays .MP3s but not any other platform (including Windows) will it work. It will also play .MID files but on the Linux version (and several others not including Windows) you'll require the Timidity MIDI player.

If you want to play more formats you might look into SDL_Sound which wraps ModPlug Tracker player as well as MikMod.

The biggest drawback of SDL_Mixer is that you can't play continuous loops in the sample formats, only the module formats will.
benryves
benryves
The reason I want to avoid SDL_Mixer is because I want to directly output to the sound card. The callback function provides you with a pointer to a stream to write to and the number of samples you need to write and you just cycle through writing to the buffer.
For my Game Gear game I'm going to need some music, so need to write a music editing tool. I've written a PSG (the sound chip in the GG) emulator in C using SDL's basic audio system - a VGM player that uses that PSG emulation can be downloaded here with source - so it would be nice to be able to use that emulation inside the music editor so I can hear what I'm writing without having to resort to compiling and running in an emulator.
If I wanted nicer features (like MP3 playback, for example) I'd stick to FMOD, but this isn't the case - I want low-level control!
[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]
Rob Loach
Rob Loach
Did you get it working? What platform are you running it on again?
Rob Loach [Website] [Projects] [
benryves
benryves
No, I didn't get it working. I can create the variables for my AudioSpec, but I can't work out how I can get the pointers of these. The documentation for Tao contains the C documentation for SDL rather than its own, and I need to somehow turn my AudioSpecs into an IntPtr. [help]
It's the SDL_OpenAudio() call, and it should be SDL_OpenAudio(&desired, &actual); in C - but for VB, I can't work out how to do it!
[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]
jendave
jendave
For turning a struct into a IntPtr is using the Marshal.StructToPtr call. Try that out. If that does not work I can take a look at the way I marshalled it. Callbacks are problematic with P/Invoke. Also there is a void pointer in the audiospec struct as well which is know to cause marshalling problems. That said low-level control is not C# strong point.
SDL.NET http://cs-sdl.sourceforge.netTao.Sdlhttp://mono-project.com/Tao

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.