Random sounds at random intervals and volumes?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
kahmehkahzeh
Regular
Posts: 62
Joined: Thu Apr 13, 2017 6:47 am
Contact:

Random sounds at random intervals and volumes?

#1 Post by kahmehkahzeh » Wed May 03, 2017 1:40 am

is it possible to set up sound lists that play at random intervals and volumes?

My next project will depend on it... and I could not find anyone else who has asked such a question.

And thank you all again for helping me finish my last small project! "If One Thing Changed"

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 2983
Joined: Mon Dec 14, 2015 5:05 am
Location: Your monitor
Contact:

Re: Random sounds at random intervals and volumes?

#2 Post by Imperf3kt » Wed May 03, 2017 3:59 am

As far as I am aware, there is currently no 'good' way to achieve this. You may be able to do it using a random number generator, but it'll be very finicky code and would probably break easily.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py
Free Android GUI - Updated occasionally

User avatar
Ocelot
Miko-Class Veteran
Posts: 849
Joined: Tue Aug 23, 2016 10:35 am
Skype: miinipaa
Contact:

Re: Random sounds at random intervals and volumes?

#3 Post by Ocelot » Wed May 03, 2017 1:34 pm

I am not going to write any code right now, but I will point to functions you can use to accomplish what you want:

1) renpy.music.set_queue_empty_callback can be used to constantly queue new sounds.
2) renpy.music.queue to add sounds to play next.
3) renpy.music.set_volume to change sound volume before you queue it
4) A pseudo filename <silence x.x> to play silence (aka pause between sounds). Note that you can dynamically generate this string (probably in your callback function)
< < insert Rick Cook quote here > >

kahmehkahzeh
Regular
Posts: 62
Joined: Thu Apr 13, 2017 6:47 am
Contact:

Re: Random sounds at random intervals and volumes?

#4 Post by kahmehkahzeh » Wed May 03, 2017 3:37 pm

Thank you much for the responses, I will look into this to see if I can understand it, @_@

kahmehkahzeh
Regular
Posts: 62
Joined: Thu Apr 13, 2017 6:47 am
Contact:

Re: Random sounds at random intervals and volumes?

#5 Post by kahmehkahzeh » Thu May 04, 2017 3:02 am

the queue allows me to place them to play in order, but I am trying to create an atmosphere where random things play at different volumes.

is it possible to have a variable that continuously runs and changes volume constantly, playing a sound, that has a varible that changes the next in que,

so when called it picks the random volume and the current queue song?
vol = Rand 0.2-0.4
VAriaable sound volume = volume set "vol"
loop

sound = queue list
VAriaable sound queue = change next song in queue
loop

Label play
vol - calls current volume
play song - plays current on queue.

I can't write code from scratch...

User avatar
Ocelot
Miko-Class Veteran
Posts: 849
Joined: Tue Aug 23, 2016 10:35 am
Skype: miinipaa
Contact:

Re: Random sounds at random intervals and volumes?

#6 Post by Ocelot » Thu May 04, 2017 12:46 pm

Here is a basic example of how you can achieve this:
1) Create a new project and replace content of script.rpy with this:

Code: Select all

define sounds = ['sounds/explosion.wav', 'sounds/glass.wav', 'sounds/shot.wav']

init python:
    def s_callback():
        if s_callback.queue_silence:
            silence = "<silence {0}>".format(renpy.random.random() * 2 + 0.5)
            renpy.sound.queue(silence)
        else:
            renpy.sound.set_volume(renpy.random.random())
            renpy.sound.queue(renpy.random.choice(sounds))
        s_callback.queue_silence = not s_callback.queue_silence
        
    s_callback.queue_silence = False
    
    renpy.sound.set_queue_empty_callback(s_callback)
    

label start:
    "Just sit here and listen to the sounds"
    return
2) Download
sounds.zip
Sounds for testing
(1.27 MiB) Downloaded 13 times
and extract it in the game directory.
3) Launch the game and listen to the sounds.
< < insert Rick Cook quote here > >

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Karrion, Shocking Alberto