Just in case I take part…

Just in case I enter this weekends Ludum Dare competition and use this, here’s a wrapper I started working on for SunVox. It’s C#, dirty as hell, mostly uncommented… but it does work with XNA (Visual Studio 2010, XNA 4).

Quick intro goes like this…

  using SoftAnswer.SunVox;
  ...
  SunVox.sv_init("",44100,2,0);
  SunVox.sv_load_and_play(0,"Content\\8bit_tales.sunvox");

So, to recap that briefest of introductions… you must call sv_init, these parameters work fine. 44100 is the sample rate and 2 is the number of channels to use on the output device I believe. The first empty string specifies a device… I have yet to find out exactly how to use this. The last parameter are the initialisation flags, specified using a binary OR with values from SunVoxInitFlags.

SunVox works on slots. sv_load_and_play(slot,name) will load a file into the slot specified by slot. The file specified by name (which can be a path relative to the executable) is loaded and played from the beginning. You should use sv_stop(slot) to stop playback. If you only call stop once, any effects such as reverb will continue. If you want to have a dead stop, there is the helper sv_dead_stop which simply calls sv_stop twice.

If a function succeeds, it should return 0 (as far as I can tell), with one exception… sv_init which appears to return a non-zero value, the meaning of which I have yet to determine :-)

When you’ve done with a slot, close it using sv_close_slot(slot). There are a bunch of other functions that I have not implemented in this wrapper yet. If you are aware of better wrapper that is actively maintained, please feel free to add a comment to this post. I did try and find one but failed miserably and so I started writing my own. For more information about the library, I’ll have to refer you to the library itself which comes with headers.

Since you can only use publicly available code the competition that is available before the competition, I’m making this available just in case anyone else wants to use it. If you’ve not encountered SunVox, check it out. Classic tracker style composition but with what I can only describe as an awesome modular synth engine. Very light weight, very flexible.

The wrapper is being made available under the terms of the Mozilla Public Licence Version 2.0. Details in the file along with a link to the full text of the licence.

SunVox Library Wrapper for C#

Disclaimer – In case it’s not clear from the licence, this file is being made available as is with no warranty of any kind. I accept no responsibility or liability of any kind that may arise as a result of your use of it.

Leave a Reply

 

Bad Behavior has blocked 172 access attempts in the last 7 days.

communication