Ren'Py Loop few sounds

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,578
2,210
Depends on how you want to use the sounds.

If it's two or three separate sounds to be played one after each other... then you could just use a sound editor to join each file to the next into a single file, then repeat that sound. is always the front runner when people suggest software like this.

Then it would be just a case of telling RenPy to loop the (now) single sound file.

Python:
    scene black with fade
    play sound "mysound.mp3" loop
    "The sound is playing."
    "The sound is still playing."

    scene red with fade
    "And still the sound continues."

    stop sound fadeout 1.5
    "... and no more."

...would start playing a sound on a loop. Then once, the player reaches a point in the dialogue where the sound is no longer needed, it slowly fades out over 1.5 seconds. In this case, my fictional sound is an .mp3 file.

You could avoid using a sound editor by having RenPy play each file for you. I've never tried this, but says it's possible.

Python:
    scene black with fade
    play sound [ "thissound1.wav", "thissound2.wav", "thissound3.wav" ]  loop
    pause
    stop sound fadeout 1.5

As I say, the manual says it should work... but you'd probably would need to try it.


Alternatively, perhaps you are wanting to play multiple sounds at the same time.
Usually that would be something like music + sound effects. But I suppose you could have something like a shower running (ambient) and a phone ringing (sound) at the same time.

For this you would need multiple sound channels.

RenPy gives you three by default... sound, music and voice. But you can create your own. You'd just use them by using play sound, play music, etc.

Each could be looped separately, and I suppose if you needed them to all line up... you could pad each sound channel with silence.

Suppose you had two sounds "mymusic.ogg" and "mysound.mp3". The music file is 6 seconds and the other sound file is 4 seconds.

Maybe, this would work...

Python:
    scene black with fade
    play music "mymusic.ogg" loop
    play sound [ "mysound.mp3", "<silence 2.0>"] loop
    pause
    stop music
    stop sound
Silence is also discussed .

I can't say this would work in the real world... in theory it should... but I can also imagine that over time, the playback would get out of sync either because the files aren't exactly the length you thought they were or because of some quirk about how RenPy is playing each sound.


If you do want to add your own sound channels, because you want to playing multiple sounds without using music or voice and without interrupting existing sounds that might be playing... you'd do that with register_channel.

Taking it to an extreme, it could looks like this...

Python:
init python:
    renpy.music.register_channel("ambient", mixer="sfx", loop=True, stop_on_mute=True, buffer_queue=True)
    renpy.music.register_channel("ambient2", mixer="sfx", loop=True, stop_on_mute=True, buffer_queue=True)
    renpy.music.register_channel("ambient3, mixer="sfx", loop=True, stop_on_mute=True, buffer_queue=True)
    renpy.music.register_channel("sound2", mixer="sfx", loop=False, stop_on_mute=True, buffer_queue=True)
    renpy.music.register_channel("sound3", mixer="sfx", loop=False, stop_on_mute=True, buffer_queue=True)
    renpy.music.register_channel("music2", mixer="music", loop=True, stop_on_mute=True, buffer_queue=True)

I presume each of these new music channels would need volume sliders on the preferences screen? Or at least have the preferences screen set the values for multiple channels at the same time... Hmm... not my problem.

Note: The music channel will loop by default, whereas the sound channel doesn't. I'm not sure about the voice channel, but common sense says it probably doesn't either.
 

Deleted member 2492533

Delicious
Donor
Game Developer
Jun 19, 2020
89
317
Depends on how you want to use the sounds.

If it's two or three separate sounds to be played one after each other... then you could just use a sound editor to join each file to the next into a single file, then repeat that sound. is always the front runner when people suggest software like this.

Then it would be just a case of telling RenPy to loop the (now) single sound file.

Python:
    scene black with fade
    play sound "mysound.mp3" loop
    "The sound is playing."
    "The sound is still playing."

    scene red with fade
    "And still the sound continues."

    stop sound fadeout 1.5
    "... and no more."

...would start playing a sound on a loop. Then once, the player reaches a point in the dialogue where the sound is no longer needed, it slowly fades out over 1.5 seconds. In this case, my fictional sound is an .mp3 file.

You could avoid using a sound editor by having RenPy play each file for you. I've never tried this, but says it's possible.

Python:
    scene black with fade
    play sound [ "thissound1.wav", "thissound2.wav", "thissound3.wav" ]  loop
    pause
    stop sound fadeout 1.5

As I say, the manual says it should work... but you'd probably would need to try it.


Alternatively, perhaps you are wanting to play multiple sounds at the same time.
Usually that would be something like music + sound effects. But I suppose you could have something like a shower running (ambient) and a phone ringing (sound) at the same time.

For this you would need multiple sound channels.

RenPy gives you three by default... sound, music and voice. But you can create your own. You'd just use them by using play sound, play music, etc.

Each could be looped separately, and I suppose if you needed them to all line up... you could pad each sound channel with silence.

Suppose you had two sounds "mymusic.ogg" and "mysound.mp3". The music file is 6 seconds and the other sound file is 4 seconds.

Maybe, this would work...

Python:
    scene black with fade
    play music "mymusic.ogg" loop
    play sound [ "mysound.mp3", "<silence 2.0>"] loop
    pause
    stop music
    stop sound
Silence is also discussed .

I can't say this would work in the real world... in theory it should... but I can also imagine that over time, the playback would get out of sync either because the files aren't exactly the length you thought they were or because of some quirk about how RenPy is playing each sound.


If you do want to add your own sound channels, because you want to playing multiple sounds without using music or voice and without interrupting existing sounds that might be playing... you'd do that with register_channel.

Taking it to an extreme, it could looks like this...

Python:
init python:
    renpy.music.register_channel("ambient", mixer="sfx", loop=True, stop_on_mute=True, buffer_queue=True)
    renpy.music.register_channel("ambient2", mixer="sfx", loop=True, stop_on_mute=True, buffer_queue=True)
    renpy.music.register_channel("ambient3, mixer="sfx", loop=True, stop_on_mute=True, buffer_queue=True)
    renpy.music.register_channel("sound2", mixer="sfx", loop=False, stop_on_mute=True, buffer_queue=True)
    renpy.music.register_channel("sound3", mixer="sfx", loop=False, stop_on_mute=True, buffer_queue=True)
    renpy.music.register_channel("music2", mixer="music", loop=True, stop_on_mute=True, buffer_queue=True)

I presume each of these new music channels would need volume sliders on the preferences screen? Or at least have the preferences screen set the values for multiple channels at the same time... Hmm... not my problem.

Note: The music channel will loop by default, whereas the sound channel doesn't. I'm not sure about the voice channel, but common sense says it probably doesn't either.
As always, thank you very much)