Questions regarding looping sounds using ZGE Sound
Posted: Tue Oct 21, 2025 2:38 pm
Since the very beginning of my project, I set up some kind of noise as a motor sound and then triggered it repeatedly using something like:
It worked fine until I realized it didn’t sound the same at all on different devices, and I had to admit how bad I am with the ZGE Sound component.
First off, do I really need to switch channels every time I play a sound?
Now that I’m using Sunvox for music and SFXR for sound effects, I’m not sure if that’s still relevant.
As for the motor sound (the classic ZGE Sound), I guess it plays whenever it can: on each frame, at whatever framerate the device is running, and only if a sound channel is free. So how can I make sure it sounds consistent across all devices?
Should I use some kind of App.DeltaTime timer to control when the sound is played? And then tweak its duration so it loops smoothly, without overlapping or blowing out the speakers on small Android devices?
Code: Select all
int Sound_Channel = 0;
void ChangeSoundChannel()
{
Sound_Channel++;
if (Sound_Channel > 3) Sound_Channel = 0;
}
void PlaySound(Sound snd, vec3 pos, float vmax, float note)
{
snd.Pan = clamp(0.5 + (pos.X - CameraGame.Position.X) * 0.04, 0.0, 1.0);
snd.Volume = clamp(vmax - abs(pos.Z - CameraGame.Position.Z) / 600, 0.0, vmax);
ChangeSoundChannel();
if (note) @PlaySound(Sound:snd, NoteNr: note + (pos.Z - CameraGame.Position.Z) / 3, Channel: Sound_Channel);
else @PlaySound(Sound:snd, Channel: Sound_Channel);
}First off, do I really need to switch channels every time I play a sound?
Now that I’m using Sunvox for music and SFXR for sound effects, I’m not sure if that’s still relevant.
As for the motor sound (the classic ZGE Sound), I guess it plays whenever it can: on each frame, at whatever framerate the device is running, and only if a sound channel is free. So how can I make sure it sounds consistent across all devices?
Should I use some kind of App.DeltaTime timer to control when the sound is played? And then tweak its duration so it loops smoothly, without overlapping or blowing out the speakers on small Android devices?