SunVox for ZGE

Use of external libraries (DLLs) from ZGE.

Moderator: Moderators

airpas
Posts: 48
Joined: Wed Apr 18, 2012 11:50 am

Post by airpas »

it doesn't work , i don't know to what the error message refer to , but seems not compatible with WinXP
Attachments
error.JPG
error.JPG (69.43 KiB) Viewed 46998 times
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post by Rado1 »

I updated to the latest ZGE beta and got the same error message. The error appears when SunVox dll tries to load file from memory: sv_load_from_memory(0, SongFile.FileEmbedded, SongFile.Size);

Ville, could you please have a look at this? Thanks.
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post by Rado1 »

Ville has fixed the problem in ZGE, just download the latest beta.
airpas
Posts: 48
Joined: Wed Apr 18, 2012 11:50 am

Post by airpas »

thanks :) , its really awesome sound system
the only disadvantage i can see is the CPU usage which can effect on the smoothness of the game
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Post by jph_wacheski »

airpas- SunVox has a handy CPU meter that can be used when creating musics,. wise use of limited modules can provide some interesting interactive music with very little processor hit. (it is also easy to create CPU crippling tunes as well ;) )


Rado1- thanks for the update :) NightRadio added a suggestion I made for an effect implementation that will let me make some more dynamic tunes,. look forward to getting this setup,. thanks again!
iterationGAMES.com
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

Re: SunVox for ZGE

Post by rrTea »

Seems that trying to open more than 4 slots causes a crash. Using the latest library and just putting this in OnLoaded:

Code: Select all

sv_init("", 44100, 2, 0);

sv_open_slot(0);
sv_open_slot(1);
sv_open_slot(2);
sv_open_slot(3);
sv_open_slot(4);

sv_load_from_memory(0, mus_Opening.FileEmbedded, mus_Opening.Size);
sv_load_from_memory(1, mus_LevelSelect.FileEmbedded, mus_LevelSelect.Size);
sv_load_from_memory(2, mus_LevelClear.FileEmbedded, mus_LevelClear.Size);
sv_load_from_memory(3, mus_Credits.FileEmbedded, mus_Credits.Size);
sv_load_from_memory(4, mus_LevelLoop.FileEmbedded, mus_LevelLoop.Size);

sv_set_autostop(2, 1);

sv_volume(0, 213);
...and this in OnClose:

Code: Select all

sv_stop(0);
sv_close_slot(0);

sv_stop(1);
sv_close_slot(1);

sv_stop(2);
sv_close_slot(2);

sv_stop(3);
sv_close_slot(3);

sv_stop(4);
sv_close_slot(4);

sv_deinit();
will make it crash (the songs in question are very small and simple background tunes). Weird thing is that it works perfectly when there's one slot less... Or am I missing something?

(http://www.warmplace.ru/soft/sunvox/sunvox_dll.zip)
Last edited by rrTea on Fri Sep 25, 2015 10:29 am, edited 2 times in total.
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

Re: SunVox for ZGE

Post by rrTea »

Or am I using it wrongly? Maybe a slot is meant to be reused and I shouldn't open more than one at any given moment? So for example there's just a slot for "Music" and I'm supposed to load / unload a song on changing the AppState?
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Re: SunVox for ZGE

Post by Rado1 »

rrTea wrote:Or am I using it wrongly? Maybe a slot is meant to be reused and I shouldn't open more than one at any given moment?
I do not think you are doing it wrongly; simply ,the bug (or restriction) is in sunvox dll itself. Slot represent a separate stream of sounds with own properties and controls. Certainly, it can/should be reused for several sounds. Try to put, e.g., background music to one slot and sound effects to another one.
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

Re: SunVox for ZGE

Post by rrTea »

Hi Rado1, I'd like to make a song stop after it plays once. I thought I'd just deal with it by having two slots, one for looping background tunes and one for tunes that should stop automatically. This is how I set it up:

Code: Select all

sv_init("", 22050, 2, 0);

int Slot;

Slot = 0; //Looping music
sv_open_slot(Slot);
sv_set_autostop(Slot, No);
sv_volume(Slot, 213);

Slot = 1; //Play-once music
sv_open_slot(Slot);
sv_set_autostop(Slot, Yes);
sv_volume(Slot, 213);
(and of course I close the slots and deinitialize it all OnLeave)

...but this doesn't seem to work... When I play a song through slot one it just behaves the same like in slot 0 (loops). What am I missing?
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Re: SunVox for ZGE

Post by Rado1 »

It's been long time ago I played with SunVox, but I did some experiments today. To take effect, the sv_set_autostop() should be called after sv_load() or sv_load_from_memory(), the same as sv_volume(), etc. So first open the slot, then load file (from file system or memory), then set slot/playing properties and then play... See the attached testing file for inspiration.

Advice: for sound effects (shooting, jumping, ...) I would recommend to use sv_send_event() and a sunvox file with several modules producing various sound effects.

Note: I used the latest SunVox lib 1.9.2. ... it works fine with the original ZExternalLibrary component from 2014.
Attachments
x.zip
(3.11 KiB) Downloaded 603 times
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

Re: SunVox for ZGE

Post by rrTea »

Setting it after loading works! (I'm planning to use it for opening, intro and similar situations.) I thought it has to be set per channel, not per song. I also managed to implement a basic send_event for sound effects etc.

Oh and I tried updating to the newest sunvox.dll, but that actually prevents the program from running ("sunvox.dll not found" message in the ZGE console when launching it in the Preview). Replacing the new dll (633 kb) with the old one again (555 kb) makes it work again (note I didn't move the file, just replaced it and then reverted it, all in the same directory).
Last edited by rrTea on Sun Nov 19, 2017 3:51 am, edited 1 time in total.
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Re: SunVox for ZGE

Post by Rado1 »

rrTea wrote:Oh and I tried updating to the newest sunvox.dll, but that actually prevents the program from running ("sunvox.dll not found" message in the ZGE console when launching it in the Preview).
Hmm, that's strange. I tried my old demos and some new experiments with 1.9.2 and all work fine. Could you please try this version of library:

Code: Select all

ZZDC<?xml version="1.0" encoding="iso-8859-1" ?>
<ZExternalLibrary Comment="SunVox music library" ModuleName="sunvox.dll" BeforeInitExp="if(ANDROID) this.ModuleName = "./libsunvox.so";">
  <Source>
<![CDATA[/*
  Adapter to the SunVox Library.
  http://www.warmplace.ru/soft/sunvox

  Created by Rado1(c)2012-2017

  Download the library from the URL above.
  More info: http://www.emix8.org/forum/viewtopic.php?p=5446

*/

// Constants

const int SV_NOTECMD_NOTE_OFF = 128;
const int SV_NOTECMD_ALL_NOTES_OFF = 129; // notes of all synths off
const int SV_NOTECMD_CLEAN_SYNTHS = 130; // stop and clean all synths
const int SV_NOTECMD_STOP = 131;
const int SV_NOTECMD_PLAY = 132;

const int SV_INIT_FLAG_NO_DEBUG_OUTPUT = 1 << 0;
const int SV_INIT_FLAG_USER_AUDIO_CALLBACK = 1 << 1;
const int SV_INIT_FLAG_AUDIO_INT16 = 1 << 2;
const int SV_INIT_FLAG_AUDIO_FLOAT32 = 1 << 3;
const int SV_INIT_FLAG_ONE_THREAD = 1 << 4;

const int SV_MODULE_FLAG_EXISTS = 1;
const int SV_MODULE_FLAG_EFFECT = 2;
const int SV_MODULE_INPUTS_OFF = 16;
const int SV_MODULE_INPUTS_MASK = ( 255 << SV_MODULE_INPUTS_OFF );
const int SV_MODULE_OUTPUTS_OFF = ( 16 + 8 );
const int SV_MODULE_OUTPUTS_MASK = ( 255 << SV_MODULE_OUTPUTS_OFF );

const int SV_STYPE_INT16 = 0;
const int SV_STYPE_INT32 = 1;
const int SV_STYPE_FLOAT32 = 2;
const int SV_STYPE_FLOAT64 = 3;

// Initialization

int sv_init(string dev, int freq, int channels, int flags) {}
int sv_deinit() {}
int sv_open_slot(int slot) {}
int sv_close_slot(int slot) {}
int sv_lock_slot(int slot ) {}
int sv_unlock_slot(int slot) {}
int sv_load(int slot, string name) {}
int sv_load_from_memory(int slot, xptr data, int data_size) {}

// Song playing control

int sv_play(int slot) {}
int sv_play_from_beginning(int slot) {}
int sv_stop(int slot) {}
int sv_set_autostop(int slot, int autostop) {}
  // autostop values: 0 - disable autostop; 1 - enable autostop.
  // When disabled, song is playing infinitely in the loop.
int sv_rewind(int slot, int line_num) {}
int sv_volume(int slot, int vol) {}
int sv_send_event(int slot, int channel_num, int note, int vel, int module, int ctl, int ctl_val) {}
  //  channel_num: from 0 to 15;
  //  note: 0 - nothing; 1..127 - note num; 128 - note off; 129, 130... - see NOTECMD_xxx defines;
  //  vel: velocity 1..129; 0 - default;
  //  module: 0 - nothing; 1..255 - module number;
  //ctl - 0xCCEE. CC - number of a controller (1..255). EE - std effect
  //ctl_val - value of controller/effect

// Getting info about the engine, song and its playing

int sv_audio_callback(xptr buf, int frames, int latency, int out_time) {}
  // Get the next piece of SunVox audio.
  // buf - destination buffer of type signed short (if SV_INIT_FLAG_AUDIO_INT16 used in sv_init())
  //       or float (if SV_INIT_FLAG_AUDIO_FLOAT32 used in sv_init());
  //       stereo data will be interleaved in this buffer: LRLR... ; where the LR is the one frame;
  // frames - number of frames in destination buffer;
  // latency - audio latency (in frames);
  // out_time - output time (in ticks).
int sv_get_sample_type() {}
  // Get internal sample type of the SunVox engine.
  // Return value: one of the SV_STYPE_xxx defines.
  // Use it to get the scope buffer type from get_module_scope() function.
int sv_end_of_song(int slot) {}
  // Return values: 0 - song is playing now; 1 - stopped.
int sv_get_current_line(int slot) {}
int sv_get_current_signal_level(int slot, int channel) {}
string sv_get_song_name(int slot) {}
int sv_get_song_bpm(int slot) {}
int sv_get_song_tpl(int slot) {}
int sv_get_song_length_lines(int slot) {}
int sv_get_song_length_frames(int slot) {}
  // Frame is one discrete of the sound. Sampling frequency 44100 Hz
  // means, that you hear 44100 frames per second.
int sv_get_ticks() {}
  // Returns the current tick counter (from 0 to 0xFFFFFFFF).
  // SunVox engine uses its own time space, measured in ticks.
int sv_get_ticks_per_second() {}
  // Returns the number of SunVox ticks per second.

// Module management

int sv_new_module(int slot, string type, string name, int x, int y, int z) {}
  // Use it between sv_lock_slot() and sv_unlock_slot()
int sv_remove_module(int slot, int mod_num) {}
  // Use it between sv_lock_slot() and sv_unlock_slot()
int sv_connect_module(int slot, int source, int destination) {}
  // Use it between sv_lock_slot() and sv_unlock_slot()
int sv_disconnect_module(int slot, int source, int destination) {}
  // Use it between sv_lock_slot() and sv_unlock_slot()
int sv_load_module(int slot, string file_name, int x, int y, int z) {}
int sv_sampler_load(int slot, int sampler_module, string file_name, int sample_slot) {}
int sv_get_number_of_modules(int slot) {}
int sv_get_module_flags(int slot, int mod_num) {}
string sv_get_module_name(int slot, int mod_num) {}
int sv_get_module_xy(int slot, int mod_num) {}
int sv_get_module_color(int slot, int mod_num) {}
int sv_get_number_of_module_ctls(int slot, int mod_num) {}
string sv_get_module_ctl_name(int slot, int mod_num, int ctl_num) {}
int sv_get_module_ctl_value(int slot, int mod_num, int ctl_num, int scaled) {}
int sv_get_number_of_patterns(int slot) {}
int sv_get_pattern_x(int slot, int pat_num) {}
int sv_get_pattern_y(int slot, int pat_num) {}
int sv_get_pattern_tracks(int slot, int pat_num) {}
int sv_get_pattern_lines(int slot, int pat_num) {}
int sv_pattern_mute(int slot, int pat_num, int mute) {}
  // Use it between sv_lock_slot() and sv_unlock_slot()]]>
  </Source>
</ZExternalLibrary>
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

Re: SunVox for ZGE

Post by rrTea »

I tried it - no luck, must be something on my end. This is the project is I tested it on:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
  <OnLoaded>
    <ZExternalLibrary Comment="SunVox music library" ModuleName="sunvox.dll" BeforeInitExp="if(ANDROID) this.ModuleName = "./libsunvox.so";">
      <Source>
<![CDATA[/*
  Adapter to the SunVox Library.
  http://www.warmplace.ru/soft/sunvox

  Created by Rado1(c)2012-2017

  Download the library from the URL above.
  More info: http://www.emix8.org/forum/viewtopic.php?p=5446

*/

// Constants

const int SV_NOTECMD_NOTE_OFF = 128;
const int SV_NOTECMD_ALL_NOTES_OFF = 129; // notes of all synths off
const int SV_NOTECMD_CLEAN_SYNTHS = 130; // stop and clean all synths
const int SV_NOTECMD_STOP = 131;
const int SV_NOTECMD_PLAY = 132;

const int SV_INIT_FLAG_NO_DEBUG_OUTPUT = 1 << 0;
const int SV_INIT_FLAG_USER_AUDIO_CALLBACK = 1 << 1;
const int SV_INIT_FLAG_AUDIO_INT16 = 1 << 2;
const int SV_INIT_FLAG_AUDIO_FLOAT32 = 1 << 3;
const int SV_INIT_FLAG_ONE_THREAD = 1 << 4;

const int SV_MODULE_FLAG_EXISTS = 1;
const int SV_MODULE_FLAG_EFFECT = 2;
const int SV_MODULE_INPUTS_OFF = 16;
const int SV_MODULE_INPUTS_MASK = ( 255 << SV_MODULE_INPUTS_OFF );
const int SV_MODULE_OUTPUTS_OFF = ( 16 + 8 );
const int SV_MODULE_OUTPUTS_MASK = ( 255 << SV_MODULE_OUTPUTS_OFF );

const int SV_STYPE_INT16 = 0;
const int SV_STYPE_INT32 = 1;
const int SV_STYPE_FLOAT32 = 2;
const int SV_STYPE_FLOAT64 = 3;

// Initialization

int sv_init(string dev, int freq, int channels, int flags) {}
int sv_deinit() {}
int sv_open_slot(int slot) {}
int sv_close_slot(int slot) {}
int sv_lock_slot(int slot ) {}
int sv_unlock_slot(int slot) {}
int sv_load(int slot, string name) {}
int sv_load_from_memory(int slot, xptr data, int data_size) {}

// Song playing control

int sv_play(int slot) {}
int sv_play_from_beginning(int slot) {}
int sv_stop(int slot) {}
int sv_set_autostop(int slot, int autostop) {}
  // autostop values: 0 - disable autostop; 1 - enable autostop.
  // When disabled, song is playing infinitely in the loop.
int sv_rewind(int slot, int line_num) {}
int sv_volume(int slot, int vol) {}
int sv_send_event(int slot, int channel_num, int note, int vel, int module, int ctl, int ctl_val) {}
  //  channel_num: from 0 to 15;
  //  note: 0 - nothing; 1..127 - note num; 128 - note off; 129, 130... - see NOTECMD_xxx defines;
  //  vel: velocity 1..129; 0 - default;
  //  module: 0 - nothing; 1..255 - module number;
  //ctl - 0xCCEE. CC - number of a controller (1..255). EE - std effect
  //ctl_val - value of controller/effect

// Getting info about the engine, song and its playing

int sv_audio_callback(xptr buf, int frames, int latency, int out_time) {}
  // Get the next piece of SunVox audio.
  // buf - destination buffer of type signed short (if SV_INIT_FLAG_AUDIO_INT16 used in sv_init())
  //       or float (if SV_INIT_FLAG_AUDIO_FLOAT32 used in sv_init());
  //       stereo data will be interleaved in this buffer: LRLR... ; where the LR is the one frame;
  // frames - number of frames in destination buffer;
  // latency - audio latency (in frames);
  // out_time - output time (in ticks).
int sv_get_sample_type() {}
  // Get internal sample type of the SunVox engine.
  // Return value: one of the SV_STYPE_xxx defines.
  // Use it to get the scope buffer type from get_module_scope() function.
int sv_end_of_song(int slot) {}
  // Return values: 0 - song is playing now; 1 - stopped.
int sv_get_current_line(int slot) {}
int sv_get_current_signal_level(int slot, int channel) {}
string sv_get_song_name(int slot) {}
int sv_get_song_bpm(int slot) {}
int sv_get_song_tpl(int slot) {}
int sv_get_song_length_lines(int slot) {}
int sv_get_song_length_frames(int slot) {}
  // Frame is one discrete of the sound. Sampling frequency 44100 Hz
  // means, that you hear 44100 frames per second.
int sv_get_ticks() {}
  // Returns the current tick counter (from 0 to 0xFFFFFFFF).
  // SunVox engine uses its own time space, measured in ticks.
int sv_get_ticks_per_second() {}
  // Returns the number of SunVox ticks per second.

// Module management

int sv_new_module(int slot, string type, string name, int x, int y, int z) {}
  // Use it between sv_lock_slot() and sv_unlock_slot()
int sv_remove_module(int slot, int mod_num) {}
  // Use it between sv_lock_slot() and sv_unlock_slot()
int sv_connect_module(int slot, int source, int destination) {}
  // Use it between sv_lock_slot() and sv_unlock_slot()
int sv_disconnect_module(int slot, int source, int destination) {}
  // Use it between sv_lock_slot() and sv_unlock_slot()
int sv_load_module(int slot, string file_name, int x, int y, int z) {}
int sv_sampler_load(int slot, int sampler_module, string file_name, int sample_slot) {}
int sv_get_number_of_modules(int slot) {}
int sv_get_module_flags(int slot, int mod_num) {}
string sv_get_module_name(int slot, int mod_num) {}
int sv_get_module_xy(int slot, int mod_num) {}
int sv_get_module_color(int slot, int mod_num) {}
int sv_get_number_of_module_ctls(int slot, int mod_num) {}
string sv_get_module_ctl_name(int slot, int mod_num, int ctl_num) {}
int sv_get_module_ctl_value(int slot, int mod_num, int ctl_num, int scaled) {}
int sv_get_number_of_patterns(int slot) {}
int sv_get_pattern_x(int slot, int pat_num) {}
int sv_get_pattern_y(int slot, int pat_num) {}
int sv_get_pattern_tracks(int slot, int pat_num) {}
int sv_get_pattern_lines(int slot, int pat_num) {}
int sv_pattern_mute(int slot, int pat_num, int mute) {}
  // Use it between sv_lock_slot() and sv_unlock_slot()]]>
      </Source>
    </ZExternalLibrary>
    <ZExpression>
      <Expression>
<![CDATA[sv_init("SunVOX audio", 22050, 2, SV_INIT_FLAG_NO_DEBUG_OUTPUT);

int Slot;

Slot = 1; //Sound effects
sv_open_slot(Slot);
sv_volume(Slot, 213);

File f;
f = file_SoundEffects;
sv_load_from_memory(Slot, f.FileEmbedded, f.Size);]]>
      </Expression>
    </ZExpression>
  </OnLoaded>
  <OnUpdate>
    <KeyPress Keys="{ " RepeatDelay="0.1">
      <OnPressed>
        <ZExpression>
          <Expression>
<![CDATA[int slot, channel_num, note, vel, module, ctl, ctl_val;
slot = 1;
channel_num = 2;
note = 13;
vel = 0;
module = 2;
ctl = 0;
ctl_val = 0;


sv_send_event(slot, channel_num, note, vel, module, ctl, ctl_val);]]>
          </Expression>
        </ZExpression>
      </OnPressed>
    </KeyPress>
  </OnUpdate>
  <OnClose>
    <ZExpression Comment="Release SunVox stuff">
      <Expression>
<![CDATA[sv_stop(1);
sv_close_slot(1);
sv_deinit();]]>
      </Expression>
    </ZExpression>
  </OnClose>
  <Content>
    <File Name="file_SoundEffects" Comment="Imported from sfx.sunvox" Encoding="1">
      <FileEmbedded>
<![CDATA[78DACD96CF8BD34014C72769BBECBA0BD61FAC7ACB9F5004D1D3623749DBB0F9B59D189222B20B96BA509BA5EDDED46EC58307411004BDF50F10F14FF0B2270F0B1E146FFE0B5E058933933479ADC936D9457160984F869797796FDEF7B5D8361C44862D377191AC3CBFC26D9287884D4DA0FC984C6CCA12E52532AD7A93319D75DB50E9FA944CBDAAC99471CD411A16D93EE210D25A8611B163D428AFFBBEAFB901BF2453D5F016B32143BCD354A76C29814F3AB0ACB27372D4BE2EEB5336AB963EB5216C01667ECEB333D5D8B744CAE4A002598D83E1FEC110A50E5C5322BFB8294767C28EE3503E2C10765D97EDF3845BAD566413C6CF910362DB6C06BC86B068A8E43544C2C79A2246E69AB2590CB6E9BE19B1AA6F950997C250FD7060599710084B016155EB027EE0A5C7852DD7BC40ED7ABB5DAF2374DABD767F77E8F517C62BF0205E941C2F4A89F7BD8FB2C6CB4AC0AE32775F0117001F0286F65F52F639C0AB7CCCB4E692EC7756623EE693FDAC03FE91F2DD52CAFE06654D91DEC4D7E2FF6FABD8D0992469FD11D6A2181A9245EBECDACDBB8F463BFAE54FAF9E8DDF7EBEB8D11D75DB95EFE3F1E4E8E85BF9FABD276223A8CDE09D1A2B09E95DEC8B0B7DDD46671F49DF0A5AC6AC4EB6814EA4BD01A9FAE19ED74BD7C9EAACDD22859481424C2E9F4246FEF3AC0A590ED5409F931401ABF406E025C06B57626E87D558394535CE67D80519AE47AD253DC3E766EC162578C2C509FE90B305954ED78260628B195AD07DC0CB19DAD10BC03FB9E022CCBFD016FE9082105F94E83DDCEFB70783B49B9A4A01D82DBAA98F400A939C37E557501E29F07352A06EA73C01D9ED00BE04F82A977C4B2894C5AD33DCC6490D48DE3EB9A9D1AC1702BB853FCDE0AF48396FE3F9E5E7C976712EDBAF41F60A808F13322964C86494B17FBCFE0649F7B00B]]>
      </FileEmbedded>
    </File>
  </Content>
</ZApplication>
Last edited by rrTea on Tue Nov 21, 2017 5:19 am, edited 1 time in total.
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Re: SunVox for ZGE

Post by Rado1 »

I just open your project and it runs without problems with the latest sunvox.dll. No error and by pressing LMB it plays a shooting sound. BTW I'm running the latest ZGE beta version. Have you tried this as well?
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

Re: SunVox for ZGE

Post by rrTea »

Just to make sure I redownloaded the newest ZGE but still no luck. I must be doing something stupid (I bet I'll bang my head against the desk when I realize what)... Never mind, I'll just use the old library for now.
Post Reply