Jump to content



Photo
- - - - -

Change volume audio in runtime

volume audio

  • Please log in to reply
12 replies to this topic

#1 boriskarloff

boriskarloff

    Enthusiast

  • Members
  • PipPipPip
  • 220 posts

  • Flag: Italy

  • Favorite Pinball: kenney station

Posted 16 December 2023 - 12:59 AM

Hi

I have a soundtrack in the game.

Is it possible to turn off the audio volume and turn on it when the jingle is over?

 

Thanks

 



#2 wiesshund

wiesshund

    VPF Legend

  • Members
  • PipPipPipPipPipPipPip
  • 11,859 posts

  • Flag: United States of America

  • Favorite Pinball: How many can i have?

Posted 16 December 2023 - 05:21 AM

Yes, if your sound track is internal files and not external

and run with the playsound command

 

look at playsound args, one of them is to use existing
which will play said sound from the last place it was at.

 

so you would

stop sound

playsound with lower volume and use the existing instance of it

then stop sound

and play it, again resuming, back to normal volume


If you feel the need to empty your wallet in my direction, i don't have any way to receive it anyways

Spend it on Hookers and Blow


#3 boriskarloff

boriskarloff

    Enthusiast

  • Members
  • PipPipPip
  • 220 posts

  • Flag: Italy

  • Favorite Pinball: kenney station

Posted 16 December 2023 - 02:20 PM

"use the existing instance"

how? because PlaySound is generic.

 

Thanks



#4 wiesshund

wiesshund

    VPF Legend

  • Members
  • PipPipPipPipPipPipPip
  • 11,859 posts

  • Flag: United States of America

  • Favorite Pinball: How many can i have?

Posted 16 December 2023 - 09:26 PM

"use the existing instance"

how? because PlaySound is generic.

 

Thanks

 

please read the info on playsound command, it explains it all


If you feel the need to empty your wallet in my direction, i don't have any way to receive it anyways

Spend it on Hookers and Blow


#5 boriskarloff

boriskarloff

    Enthusiast

  • Members
  • PipPipPip
  • 220 posts

  • Flag: Italy

  • Favorite Pinball: kenney station

Posted 17 December 2023 - 02:00 PM

I don't find this documentation, can you give me a link?

Thanks.



#6 hmueck

hmueck

    MaX

  • VIP
  • 2,190 posts
  • Location:Hamburg

  • Flag: ---------

  • Favorite Pinball: IPDB Top 300



Contributor

Posted 17 December 2023 - 02:16 PM

<your visual pinball installation folder> \docs\CommandReference.txt


VPX0beta tables: 29cff786951ed9c1a70fc1fa47f5e3c1.png 0cecd68ffa2537a7262337834a05bbbe.png Finish them if you like!

#7 boriskarloff

boriskarloff

    Enthusiast

  • Members
  • PipPipPip
  • 220 posts

  • Flag: Italy

  • Favorite Pinball: kenney station

Posted 17 December 2023 - 08:39 PM

There is nothing about that in CommandReference.txt

Some code of example?

Thanks.



#8 wiesshund

wiesshund

    VPF Legend

  • Members
  • PipPipPipPipPipPipPip
  • 11,859 posts

  • Flag: United States of America

  • Favorite Pinball: How many can i have?

Posted 17 December 2023 - 11:26 PM

There is nothing about that in CommandReference.txt

Some code of example?

Thanks.

 

Not correct

PlaySound(string, int loopcount, float volume, float pan, float randompitch, int pitch, bool useexisting, bool restart, float front_rear_fade)
 - also allows to increase/decrease the frequency of an already playing samples, and in general to apply all the settings to an already playing sample, and to choose if to restart this playing sample from the beginning or not
   loopcound chooses the amount of loops
   volume is in 0..1
   pan ranges from -1.0 (left) over 0.0 (both) to 1.0 (right)
   randompitch ranges from 0.0 (no randomization) to 1.0 (vary between half speed to double speed)
   pitch can be positive or negative and directly adds onto the standard sample frequency
   useexisting is 0 or 1 (if no existing/playing copy of the sound is found, then a new one is created)
   restart is 0 or 1 (only useful if useexisting is 1)
   front_rear_fade is similar to pan but fades between the front and rear speakers
 - so f.e. PlaySound "FlipperUp",0,0.5,-1.0,1.0,1,1,0.0 would play the sound not looped (0), at half the volume (0.5), only on left speaker (-1.0), with varying pitch (1.0), it would reuse the same channel if it is already playing (1), restarts the sample (1), and plays it on the front speakers only (0.0)
StopSound(string)

If you feel the need to empty your wallet in my direction, i don't have any way to receive it anyways

Spend it on Hookers and Blow


#9 boriskarloff

boriskarloff

    Enthusiast

  • Members
  • PipPipPip
  • 220 posts

  • Flag: Italy

  • Favorite Pinball: kenney station

Posted 18 December 2023 - 02:47 PM

And where is the option to change the volume runtime?



#10 jpsalas

jpsalas

    Grand Schtroumpf

  • VIP
  • 7,300 posts
  • Location:I'm Spanish, but I live in Oslo (Norway)

  • Flag: Norway

  • Favorite Pinball: I like both new and old, but I guess I prefer modern tables with some rules and goals to achieve.



Posted 18 December 2023 - 02:52 PM

I do that in my rolling ball routine, just check any of my tables. The code I use is this:

 

            PlaySound("fx_ballrolling" & b), -1, ballvol, Pan(BOT(b) ), 0, ballpitch, 1, 0, AudioFade(BOT(b) )

 

ballvol is the volume of the sound calculated by the balls speed (speed x and speed y), so the sound is higher when the ball moves at high speed and it is lower when it is moving slower.

And it is calculated in real time :)


If you want to check my latest uploads then click on the image below:

 

vp.jpg

 

Next table? A tribute table to Stern's Foo Fighters


#11 boriskarloff

boriskarloff

    Enthusiast

  • Members
  • PipPipPip
  • 220 posts

  • Flag: Italy

  • Favorite Pinball: kenney station

Posted 18 December 2023 - 03:29 PM

Yes I was thinking about somethiing like that, but with the soundtrack, the track re-start every time.



#12 jpsalas

jpsalas

    Grand Schtroumpf

  • VIP
  • 7,300 posts
  • Location:I'm Spanish, but I live in Oslo (Norway)

  • Flag: Norway

  • Favorite Pinball: I like both new and old, but I guess I prefer modern tables with some rules and goals to achieve.



Posted 18 December 2023 - 03:38 PM

Because you are not giving the command to use the same sound/music that it is already playing:

 

PlaySound(string, int loopcount, float volume, float pan, float randompitch, int pitch, bool useexisting, bool restart, float front_rear_fade)

 

In red are the commands you need.

 

In my case I use the usexisting too:

 

 

PlaySound("fx_ballrolling" & b), -1, ballvol, Pan(BOT(b) ), 0, ballpitch, 1, 0, AudioFade(BOT(b) )

 

If you want to change the volume of an already playing sound you need to use the useexisting, otherwise it will start a new sound. And do not use the StopSound, otherwise it will start again from the beginning.

 

PlaySound"Mymusic",0,myvolume,0,0,0,1,0,0


If you want to check my latest uploads then click on the image below:

 

vp.jpg

 

Next table? A tribute table to Stern's Foo Fighters


#13 boriskarloff

boriskarloff

    Enthusiast

  • Members
  • PipPipPip
  • 220 posts

  • Flag: Italy

  • Favorite Pinball: kenney station

Posted 18 December 2023 - 03:44 PM

Perfetc. Thanks, now I've understood.

:db:  

 

Edit:

if someone needs:

 

'********************************************
'turn off the volume and play jingle
Sub VolumeDownWithJingle (jingle, setTime)
PlaySound SoundTrackArray(CurrentTrack),0,0.00,0,0,0,1,0,0
PlaySound jingle
TimerBackToTheVolume.Interval = setTime
TimerBackToTheVolume.Enabled = True
End Sub
 
Sub TimerBackToTheVolume_Timer()
PlaySound SoundTrackArray(CurrentTrack),0,SongVolume,0,0,0,1,0,0
TimerBackToTheVolume.Enabled = False
End Sub
'******** the end **********

Edited by boriskarloff, 18 December 2023 - 08:20 PM.






Also tagged with one or more of these keywords: volume, audio