SoundSequence volume control

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
Caleb377
Posts: 53
Joined: Tue Jan 28, 2020 2:54 pm

SoundSequence volume control

Post by Caleb377 »

Hello! I'm trying to create a radio that will keep playing so that if you turn it on you'll get the same "live" transmission,
not a restart of the whole song.

I can get it to do it fine, if I use "PlaySound" and then change the state of the sound with "SoundVolume",
when the radio is turned on the volume goes up to 1.0, and when it's turned off it goes back to 0.0 .
Creating the effect that the transmission doesn't stop.

Here's some of the code, to makes this mess more clear... :

script "Radio Play" OPEN
{
Playsound(7, "Radio");
SoundVolume(7, 3, 0.0);
}

int rdoctrl;
script "Radio Control" (void)
{
if(rdoctrl == 0) // radio is off
{
delay(30);
Playsound(0,"click");
Soundvolume(7, 3, 1.0);
rdoctrl = 1; // turns radio variable on
}
else
{
delay(30);
Playsound(0,"click");
Soundvolume(7, 3, 0.0);
rdoctrl = 0; // turns radio variable off
Terminate;
}
}

That works but I need the random track playing property with looping (without playing the same track over and over again) that you can only get with a sound sequence.
but if I change the first part to:

script "Radio Play" OPEN
{
SoundSequenceOnActor(7, "seq15radio");
SoundVolume(7, 3, 0.0);
}

It doesn't work, I guess "SoudVolume" does not affect sound sequences but only individual sounds.

Is there no other way to stop the sound? I managed to move the map spot with "SetActorPosition" and that kind of mutes the sound, but it's VERY unreliable,
and in my testing the sound can be sent to another spot, but it doesn't move back again (not to mention this is not an ideal solution).

As always any help is much appreciated,
Cheers.
Blue Shadow
Posts: 5046
Joined: Sun Nov 14, 2010 12:59 am

Re: SoundSequence volume control

Post by Blue Shadow »

Caleb377 wrote:It doesn't work, I guess "SoudVolume" does not affect sound sequences but only individual sounds.
You're using the wrong sound channel there. It should be CHAN_BODY, not CHAN_ITEM.

Regardless, the sound volume approach won't solve the issue; because each time a sound is played in the sequence, it's played at default volume level.
I managed to move the map spot with "SetActorPosition" and that kind of mutes the sound, but it's VERY unreliable
If by "unreliable" you mean the sound could still be heard, then what you can do is make the sector the map spot is moved to silent, either by placing a [wiki=Classes:SectorSilencer]SectorSilencer[/wiki] thing in said sector, or if you're mapping in UDMF, set it directly from the sector's properties.
User avatar
Caleb377
Posts: 53
Joined: Tue Jan 28, 2020 2:54 pm

Re: SoundSequence volume control

Post by Caleb377 »

Thanks for the quick response, I'll try to clarify what I meant with saying that the "SetActorPosition" was unreliable:

With further testing I can confirm that on a UDMF map if you use "SetActorPosition" to move a map spot it will always move it to
X:0 Y:0 no matter what you input there. (at least the sound does, the map spot is invisible in game of course)

I tried with:
SetActorPosition(7,-1361,10156,0,0);

and the music can be heard at the begining of the level at the X:0 Y:0 coordinates.

I then tried with:
SetActorPosition(7,10,10,0,0);

and nothing, it still places the sound at the zero coordinates of the map.

I don't know if this is a bug or simply that the engine was clearly not meant to move a map spot with a sound sequence attached to it.
Either way I keep looking for a solution.
User avatar
Caleb377
Posts: 53
Joined: Tue Jan 28, 2020 2:54 pm

Re: SoundSequence volume control

Post by Caleb377 »

Ok, I now think I definetly found a bug.

If you set any new coordinates using "SetActorPosition" on monsters, lightsources, etc
it will send them to the X:0 Y:0 coordinates. no matter what other options you pick.

If anyone managed to use that command successfully, to move anything around please let me know.
User avatar
SanyaWaffles
Posts: 891
Joined: Thu Apr 25, 2013 12:21 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Windows 11 for the Motorola Powerstack II
Graphics Processor: nVidia with Vulkan support
Location: The Corn Fields
Contact:

Re: SoundSequence volume control

Post by SanyaWaffles »

Specify them with a decimal point and try it.
User avatar
Caleb377
Posts: 53
Joined: Tue Jan 28, 2020 2:54 pm

Re: SoundSequence volume control

Post by Caleb377 »

Specify them with a decimal point and try it.
Some more precise data about what I tried:
I'm using GZDoom 4.7.1

The object I'm trying to move sits in coordinates:
X:-1361
Y:10156
Z:0 (40 Absolute)

Just to see if it would go somewhere else I tried:
SetActorPosition(7,4.0,4.0,0,0);

I created a map spot placed it nearby in the map, gave it a tid of "8" and then tried this:
SetActorPosition(7,GetActorX(8),GetActorY(8),GetActorZ(8),0);

I also tried and converted the map coordinates to a fixed point number by making it times 65536.

And in every single instance the monster, decoration, map spot, or whatever I use gets teleported to exactly:

X: 0
Y: 0
Z: 0

Why? I can't say.
User avatar
SanyaWaffles
Posts: 891
Joined: Thu Apr 25, 2013 12:21 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Windows 11 for the Motorola Powerstack II
Graphics Processor: nVidia with Vulkan support
Location: The Corn Fields
Contact:

Re: SoundSequence volume control

Post by SanyaWaffles »

Make a runnable example and post it. We can't troubleshoot these bits of code.
User avatar
Caleb377
Posts: 53
Joined: Tue Jan 28, 2020 2:54 pm

Re: SoundSequence volume control

Post by Caleb377 »

I thought I found a solution but the way sounds are implemented does not allow for exactly what I wanted to do.

As far as I know the best way to simulate a radio station is to mix all tracks into a single file and modify the volume.
Using "PlaySound" (with looping) and "SoundVolume". Like 3D era GTA games used to do it.

Sound sequences can't change the looping sound unless you fire the sequence over and over again.
Ambient Sounds will change the tracks, but only at fixed intervals, not when the sound finishes, therefore cutting some songs halfway.
Post Reply

Return to “Scripting”