[Solved] Help to get Sunvox module volume (maybe using json?)
Posted: Mon Aug 18, 2025 1:35 pm
Hello.
I found someone to make the music for my game. He’s excellent at composing, but not so good at naming the tracks and instrument modules...
Tracks and instruments have all the same 2 letters and the number 1 as a name. It’s a nightmare to read and debug...
So I’m programming a little ZGE app to read the SunVox file and get the module names, so I don't have to do it manually:
which returns:
I realize now that it doesn’t even correspond to the JSON. It might not be the right version of the song... 
Anyway, with the correct version of the song, the module names should correspond to the ones listed in the JSON.
So I was wondering if the JSON can be read by ZGE, so I can get the base volume for each module.
I wrote a function to convert those numbers to something that sv_send_event understands:
So if I shut down the volume of the bass (module 7+1) using:
sv_send_event(0, 1, 0, 0, 8, 0x0100, 0);
Then I can restore it to its original level afterward:
sv_send_event(0, 1, 0, 0, 8, 0x0100, GetSunvoxVolumeHex(bass_volume)); // bass volume from the JSON file
Unless there’s a simpler way to get the volume directly from the module, but I don’t think the SunVox wrapper provides that option.
I found someone to make the music for my game. He’s excellent at composing, but not so good at naming the tracks and instrument modules...
Code: Select all
{
"gc1": {
"sunsynth": "gc1.sunsynth",
"volume": 400,
"transpose": 24
},
"cc1": {
"sunsynth": "cc1.sunsynth",
"volume": 310,
"transpose": 16
},
"hh1": {
"sunsynth": "hh1.sunsynth",
"volume": 115,
"transpose": 24
},
"cr1": {
"sunsynth": "cr1.sunsynth",
"volume": 310,
"transpose": 2
},
"gt1": {
"sunsynth": "gt1.sunsynth",
"volume": 200,
"transpose": -4
},
...
}
So I’m programming a little ZGE app to read the SunVox file and get the module names, so I don't have to do it manually:
Code: Select all
void ListMusicModules()
{
// Get the total number of modules
int num_modules = sv_get_number_of_modules(0);
// Loop through each module and print its name
for (int i = 0; i < num_modules; i++) {
string module_name = sv_get_module_name(0, i);
trace("Module " + intToStr(i) + ": " + module_name);
}
}
Code: Select all
Module 0: Output
Module 1:
Module 2: Amplifier
Module 3: Noise
Module 4: cr
Module 5: cc2
Module 6: syn2
Module 7: bass2
Module 8: gt2
Module 9: vib
Module 10: guit1
Module 11: pad
Module 12: Echo
Module 13: gc2
Module 14:
Module 15: hh2
Module 16: syn1
Module 17:
Module 18:
Module 19:

Anyway, with the correct version of the song, the module names should correspond to the ones listed in the JSON.
So I was wondering if the JSON can be read by ZGE, so I can get the base volume for each module.
I wrote a function to convert those numbers to something that sv_send_event understands:
Code: Select all
/*
Convert a linear volume (0?512) to SunVox hex format.
Example: 242 -> '0x1E40'
*/
int GetSunvoxVolumeHex(int volume)
{
if (volume < 0 || volume > 512)
{
trace("Volume must be between 0 and 512");
return 0;
}
int sunvox_vol = volume * 0x4000 / 512;
return sunvox_vol;
}
sv_send_event(0, 1, 0, 0, 8, 0x0100, 0);
Then I can restore it to its original level afterward:
sv_send_event(0, 1, 0, 0, 8, 0x0100, GetSunvoxVolumeHex(bass_volume)); // bass volume from the JSON file
Unless there’s a simpler way to get the volume directly from the module, but I don’t think the SunVox wrapper provides that option.