BASIC

Author Topic: SunVox Engine DLL  (Read 10687 times)

Offline Ruidesco

  • Mr. Polyvector
  • ***
  • Posts: 236
    • View Profile
SunVox Engine DLL
« on: 2011-Sep-19 »
Hello GLBasic forums!

I'm a new user of GLBasic and have been fiddling with it about a couple of weeks, so it was about time I started participating in the community.
Since this is something I am going to use in my current project, and was a good exercise for learning to make a (simple) wrapper, I'm going to share it here.

SunVox is a recent synth-tracker in continual development, and its creator was generous enough to give a Win32/MacOSX/Linux player library to be used in other apps. You will need to download the library package and extract the one that matches your OS into the .app directory of the project for it to work (so far I could only test it in Windows).

So without further ado, I attach the SunVox Engine wrapper for GLBasic coupled with a very simple usage example.

Regards.

[attachment deleted by admin]

Offline Marmor

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 908
  • 96A285CC
    • View Profile
    • my youtube channel
Re: SunVox Engine DLL
« Reply #1 on: 2011-Sep-19 »
wow ! thanks a lot

Offline trucidare

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1377
  • Bachelor of Fail
    • View Profile
Re: SunVox Engine DLL
« Reply #2 on: 2011-Sep-19 »
i like the combination of type and methods used with inline - nice to see
MacBook Pro 2,2 GHz Core 2 Duo, 4 GB RAM, 160 GB HDD, 8600M GT
Core i3 - 3,07 GHz, 8 GB Ram, 2.5 TB HDD, Geforce GTX 260+ OC

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2621
    • View Profile
Re: SunVox Engine DLL
« Reply #3 on: 2011-Sep-19 »
Excellent stuff, thank you for sharing!  :good:
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

Offline Wampus

  • Prof. Inline
  • *****
  • Posts: 1004
    • View Profile
Re: SunVox Engine DLL
« Reply #4 on: 2011-Sep-22 »
Excellent. I love it.

I notice its possible to jump to any position of a playing song by using the Rewind command. The trouble is on my PC it will take anything from 90 to 180 milliseconds to execute. It would be great if it was possible to manipulate the pattern sequence while a song is playing. It could be as simple as telling the tracker routine to jump to a certain position after it reaches line n, either repeatedly or one time only. That way music could be created that seamlessly blended into different moods depending on what was happening in the app. For example, I imagine it being used to change music from calm to menacing if an enemy was encountered during a game.


Offline Ruidesco

  • Mr. Polyvector
  • ***
  • Posts: 236
    • View Profile
Re: SunVox Engine DLL
« Reply #5 on: 2011-Sep-22 »
Yes, I have something akin planned for my own project. Sadly, I have no access to the source code (probably no one besides the author does) so your best bet would be registering on their forum and reporting the laggy behavior.

Something that you could try is, so to speak, having "calm.sunvox" and "fight.sunvox" loaded from the start of a stage, the first in slot 0 and the second in slot 1. If an enemy appears then you could just tell the engine to Stop(0) and Play(1). Or, if the change might be less abrupt, having them crossfade during a little while using the Volume method, since it works by slots as well.
« Last Edit: 2011-Sep-22 by Ruidesco »

Offline Wampus

  • Prof. Inline
  • *****
  • Posts: 1004
    • View Profile
Re: SunVox Engine DLL
« Reply #6 on: 2011-Sep-22 »
Yes, I have something akin planned for my own project. Sadly, I have no access to the source code (probably no one besides the author does) so your best bet would be registering on their forum and reporting the laggy behavior.

I suspect the lag is due to some kind of re-initialisation of the player. A simple "position jump on x" kind of thing included in the sunvox.dll would probably allow seamless transitions without much trouble. I'll certain register and bring the subject up.

Ketil on the forum here has talked about this before. I realise Send Event could be used for various purposes too. Could solve issues such as needing to change pitch of a sound.

Something that you could try is, so to speak, having "calm.sunvox" and "fight.sunvox" loaded from the start of a stage, the first in slot 0 and the second in slot 1. If an enemy appears then you could just tell the engine to Stop(0) and Play(1). Or, if the change might be less abrupt, having them crossfade during a little while using the Volume method, since it works by slots as well.

I may be doing something wrong because I can't seem to get that to work. Trying to make two tracks play simultaneously then fade between them doesn't seem possible. The app crashes. Alternatively, trying to set things up so that one track can be stopped and another quickly started still creates a noticeable lag. Nice idea though.

Offline Ruidesco

  • Mr. Polyvector
  • ***
  • Posts: 236
    • View Profile
Re: SunVox Engine DLL
« Reply #7 on: 2011-Sep-22 »
I may be doing something wrong because I can't seem to get that to work. Trying to make two tracks play simultaneously then fade between them doesn't seem possible. The app crashes. Alternatively, trying to set things up so that one track can be stopped and another quickly started still creates a noticeable lag. Nice idea though.
A quick test adapting the usage example to crossfade two tracks seems to be working on this end. Here is the code for it:
Code: GLBasic [Select]
SETCURRENTDIR("Media")

PRINT "CLICK / PRESS ESC TO EXIT THE TEST", 5, 5
SHOWSCREEN

GLOBAL sv AS SUNVOX

sv.Init(0, 44100, 2, 0)
sv.OpenSlot(0)
sv.OpenSlot(1)
sv.Load(0, "slot_0_music.sunvox")
sv.Load(1, "slot_1_music.sunvox")
sv.Volume(1, 0)
sv.Play(0)
sv.Play(1)
MOUSEWAIT

default_max_volume = 64
FOR i = 1 TO default_max_volume
        sv.Volume(0, default_max_volume - i)
        sv.Volume(1, i)
        SLEEP 50
NEXT
MOUSEWAIT

END

SUB GLB_ON_QUIT:
        sv.Stop(0)
        sv.Stop(1)
        sv.CloseSlot(0)
        sv.CloseSlot(1)
        sv.DeInit()
ENDSUB

Offline Wampus

  • Prof. Inline
  • *****
  • Posts: 1004
    • View Profile
Re: SunVox Engine DLL
« Reply #8 on: 2011-Sep-22 »
Thanks  :)

I thought I needed to call sv.Init(0, 44100, 2, 0) twice.

Offline Ruidesco

  • Mr. Polyvector
  • ***
  • Posts: 236
    • View Profile
Re: SunVox Engine DLL
« Reply #9 on: 2011-Sep-22 »
You're welcome. We're here to try and help each other.
I realise Send Event could be used for various purposes too. Could solve issues such as needing to change pitch of a sound.
Yes, preparing a separate sunvox project to handle SFX in that fashion can prove very useful. You would just have to set up the modules that create the different sounds and then send the events from your code. Things like wind, seashores, car engines and such would sound much more dynamic.
By the way, NightRadio (SunVox's author) has "Ability to load sunvox project as module" in his to-do list, which can prove interesting in terms of dynamic music when it is finally implemented.

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2621
    • View Profile
Re: SunVox Engine DLL
« Reply #10 on: 2011-Sep-30 »
BTW I posted a request for a static Lib for iOS and the author said he would stick it in the next release.
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

Offline Ruidesco

  • Mr. Polyvector
  • ***
  • Posts: 236
    • View Profile
Re: SunVox Engine DLL
« Reply #11 on: 2011-Sep-30 »
Yup, saw that. :) NightRadio does really seem to want people to use SunVox for something else than rendering WAVs.
Ideally it should just mean adding another ?IFDEF inside the TYPE to specify the library name, but things are seldom that easy.

Offline ketil

  • Mr. Polyvector
  • ***
  • Posts: 117
    • View Profile
Re: SunVox Engine DLL
« Reply #12 on: 2011-Oct-01 »
Yes, I have something akin planned for my own project. Sadly, I have no access to the source code (probably no one besides the author does) so your best bet would be registering on their forum and reporting the laggy behavior.

Something that you could try is, so to speak, having "calm.sunvox" and "fight.sunvox" loaded from the start of a stage, the first in slot 0 and the second in slot 1. If an enemy appears then you could just tell the engine to Stop(0) and Play(1). Or, if the change might be less abrupt, having them crossfade during a little while using the Volume method, since it works by slots as well.

If you can track down an earlier version of sunvox tracker, i think the sourcecode are included under an BSD like license.
I might have it on one of my older computers.
"Sugar makes the world go 'round. Caffeine makes it spin faster."

Offline spicypixel

  • Prof. Inline
  • *****
  • Posts: 646
  • Pixel Artist
    • View Profile
    • SpicyPixel.net
Re: SunVox Engine DLL
« Reply #13 on: 2012-Nov-18 »
I downloaded this before and could not get it to play the test.sunvox file. I simply have no audio whatsoever. I ignored it at the time but would now like to use this wrapper and I'm curious as to everyone saying "wow" and "thank you" when I get a black screen with click to exit and no sound.

Any idea what I'm doing wrong? Is test.sunvox a blank tracked file?

I'm using this to test...
Code: GLBasic [Select]
// Project: SunVoxWrapper
// Start: Saturday, September 10, 2011
// IDE Version: 10.106

SETCURRENTDIR("Media")

GLOBAL sv AS SUNVOX

sv.Init(0, 44100, 2, 0)
sv.OpenSlot(0)
sv.Load(0, "8bit_tales.sunvox")
sv.Volume(0, 64)
sv.Play(0)

REPEAT
        PRINT "ESC TO EXIT THE TEST", 8, RND(2)+5
        SHOWSCREEN
UNTIL FALSE

SUB GLB_ON_QUIT:
        sv.Stop(0)
        sv.CloseSlot(0)
        sv.DeInit()
ENDSUB
 

My structure is 8bit_tales.sunvox within my Media directory and sunvox.dll next to my exe file in the .app directory.
« Last Edit: 2012-Nov-18 by spicypixel »
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

Offline Ruidesco

  • Mr. Polyvector
  • ***
  • Posts: 236
    • View Profile
Re: SunVox Engine DLL
« Reply #14 on: 2012-Nov-18 »
It would seem that the current SunVox library has changed, so its previously existing functions have different names besides there being more in number. If you use the SunVox library from last year this example works.