libSunVox binding/wrapper for C#/.NET

Post Reply
tripflag
Posts: 20
Joined: Sun Dec 16, 2012 4:20 am

libSunVox binding/wrapper for C#/.NET

Post by tripflag »

Hello!

A friend of mine had to make a basic game for his XNA class in university, and wanted me to do the music. Since I had just started looking into SunVox, I thought it would be cool to use sunvox.dll to play the songs directly.

Right now, the library can buffer sound effects to memory (for instant playback) or render/stream sunvox files directly using sunvox.dll. Some of the approaches are a bit hackish (especially the SFX buffering method) but it works! Since that was all he needed, I don't think I will be doing any more work on this in the near future. In case anyone else would like to pick it up, I tried to keep it neat and tidy... a new experience for me, hehe.

Download source: https://ocv.me/dev/sunvoxsharp.7z

Example program: https://ocv.me/dev/sunvoxplayer.exe

Finally, I would like to thank NightRadio for the excellent SunVox. I have never been this productive with any other tracker before, absolutely love the workflow and design. Sitting on the bus, plotting ideas on my phone, then continuing where I left off on the PC at home... I am completely addicted :D
Last edited by tripflag on Tue Jan 27, 2015 8:21 am, edited 5 times in total.
tripflag
Posts: 20
Joined: Sun Dec 16, 2012 4:20 am

Re: libSunVox binding/wrapper for C#/.NET

Post by tripflag »

Posting an update, since we had another idea... What if stuff in the game could blink in beat with the music? Well we're all sure that would be brilliant, so i tried to extend the binding with a way to signal the game whenever the amplitude of a module would increase. So far I've basically just ported your scope_amp routine in Soul Resonance's sunvox_visual.pixi. Unfortunately, I can't get it as accurate as I had hoped...

If you launch the newest version (006 as of now) and click "Instrument Listener", it will show an amplitude meter monitoring the kick-drum in the song. This will be implemented as a proper signal once I have the idea working correctly. One problem is the latency (which is pretty annoying since it's for a game), but I'm more worried about the seemingly random amplitude levels read from the scope. I have absolutely no idea why it seems to miss the start of the drum-note sometimes, even though it polls every milisecond.

Does anyone have an idea on how to lower the latency, and how to improve the accuracy? It would be amazing if I could somehow read the amplitude half a second ahead in time so the game would have ample time to work out the response. I realize this could all be done currently with a ghost/dead-end generator playing the drum track a few rows early, but it feels kinda...hackish.
EDIT: example "fix" for clarity

Thank you in advance for any help :good:

As a fringe benefit, the C# binding is now a proper DLL file ready to be dropped in anywhere!
User avatar
NightRadio
Site Admin
Posts: 3941
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: libSunVox binding/wrapper for C#/.NET

Post by NightRadio »

What if stuff in the game could blink in beat with the music?
There are several ways to do this.

1) Use sv_get_current_line( slot ) to get current song playing position, and just sync some animation with this number.

2) Use sv_get_current_signal_level( int slot, int channel ).

3) Use sv_get_module_scope() like in sunvox_visual.pixi code. Audio data from this function will be synchronized with the main Audio output. But if it is not, be sure that you scope reading code is correct (like in sunvox_visual.pixi). Also if you use sv_audio_callback(), be sure that it gets correct latency and out_time parameters.
tripflag
Posts: 20
Joined: Sun Dec 16, 2012 4:20 am

Re: libSunVox binding/wrapper for C#/.NET

Post by tripflag »

Alright, thanks a lot man. Since the idea was to sync to specific modules, and get_module_scope is synced to output regardless, i suppose i'll use the ghost-generator-idea after all. I suppose it won't amount to more than .1% cpu overhead at any rate :roll:

I'll get back to this after a quick christmas vacation, posting updated source as soon as the signal stuff is in place!

EDIT: Alright there we go, proper signals are in place and everything seems to work well enough. There's three (technically 4) ways to hook into the module listener now; added some guidelines to the listener form to explain which you'd want to use when. Good luck devs.
AthenaOfDelphi
Posts: 1
Joined: Sun Nov 30, 2014 12:39 am

Re: libSunVox binding/wrapper for C#/.NET

Post by AthenaOfDelphi »

Is anyone aware of an actively developed C# wrapper for SunVox.dll?

I'm looking to use it for the upcoming Ludum Dare which, despite my nickname, I'm probably going to be using C# and XNA for so I'm on the hunt for up to date (and most importantly available - the links provided above are dead) bindings.

On a slightly different, but not unrelated subject... NightRadio... do you have any detailed information available about the usage of the parameters in the various functions that make up the SunVox library interface? At the moment, I'm interested mainly in the routines to initialise the library, open songs and play them. Do you have any place on the site here for documentation about how to use the library? I've been unable to find anything so my attempts to use it have been a bit hit and miss. If you've not got anywhere, I'll write up my notes on my own site and then link them here.
User avatar
NightRadio
Site Admin
Posts: 3941
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: libSunVox binding/wrapper for C#/.NET

Post by NightRadio »

do you have any detailed information available about the usage of the parameters in the various functions that make up the SunVox library interface?
There is some information in the sunvox.h, but i still have no time to make it better, sorry... Please ask any questions here, i will try to help you as soon as possible.
tripflag
Posts: 20
Joined: Sun Dec 16, 2012 4:20 am

Re: libSunVox binding/wrapper for C#/.NET

Post by tripflag »

Download link fixed. Sorry for the delay!

I'll try to update the binding so it supports the latest libSunVox one of the upcoming weeks.

EDIT: Version 2.0 uploaded! Changes:
  • added batch conversion to .wav
  • updated to latest libSunVox
  • improved accuracy of note events
  • demo is now a self-contained binary
MatthewLentz
Posts: 1
Joined: Thu Apr 23, 2015 10:57 am

Re: libSunVox binding/wrapper for C#/.NET

Post by MatthewLentz »

It would be amazing if I could somehow read the amplitude half a second ahead in time so the game would have ample time to work out the response.
tripflag
Posts: 20
Joined: Sun Dec 16, 2012 4:20 am

Re: libSunVox binding/wrapper for C#/.NET

Post by tripflag »

This can be done by putting a mono echo module right before the output module, with 0% dry/feedback and 100% wet. This way you can adjust the 4th controller (delay) from within your .NET program to adjust the audio latency. Check out the delay slider in the instrument listener example, and the gcc.sunvox file inside the SunVoxPlayerEX folder (autocreated when running sunvoxplayer.exe) if my explanation was difficult to follow :)

Although, I noticed that on some computers the instrument events don't seem to fire... I'll have a look at this and upload v2.1 as soon as I figure out why!

EDIT: Looks like depending on the module scopes for event info doesn't really work that well... Version 2.1 is tuned for instruments that are especially made to be detected by libSunVox, like the bottom left ones in gcc.sunvox (12 and 13). These don't have to be connected to an output chain, so just use a multisynth :roll: ...but for some reason, in particular on an old WinXP machine it misses events that are fired in quick succession.

Eventually I might redo the event stuff based on sv_get_pattern_data or something, but hopefully this is still useful as it is.
iaon
Posts: 236
Joined: Mon Jun 02, 2014 7:56 am

Re: libSunVox binding/wrapper for C#/.NET

Post by iaon »

Hi,

Is there a way to get SunVoxPlayer to work with the latest sunvox.dll?
Post Reply