How to add custom renpy audio channels

Sometimes in your game project, you can have use cases where you need to be able to play several sounds simultaneously.

By default, Ren’Py uses only one audio channel for each kind of sound.

It can be quickly limited for advanced games, relying on ambient background sound experiences.

That’s where defining new audio channels can help you in your project.

In this article, you’ll learn how to make new audio channels for your Ren’Py game project.

Why Do You Need More Audio Channels in Ren’Py

To make it simple, to play several sounds simultaneously without any interferences.

By default, Ren’Py uses only one audio channel for the following types:

  • music
  • sound effects
  • voices

With only one audio channel for each sound type, it’s easy to be limited.

Especially when you want to play the first sound, then play one or more sounds while the first one is still running.

Which is not possible with only one channel per type.

By defining more audio channels, you’ll be able to combine several sounds to create new ambient background sound experiences.

4 Easy Steps to Make New Renpy Audio Channels

Create a New .rpy File

So the first step to do is to create a new .rpy file for your audio channels.

You can use the same file as the one with all your music, sound effects, and voices declaration or make a new one.

For our example, we will create a new one called audio.rpy. 

As I described in my article about structuring your Ren’Py game project (WIP), we’ll put this file in “<game_root>/game/define/core/audio.rpy“.

Let’s open it in your favorite text editor and go forward.

Declare All Your Sounds Path

Now that we create a dedicated file, we’ll have to declare all our audio files (music, voices, and sound effects) and create new audio channels.

Our audio.rpy is perfect for our case because we will be able to declare all audio types into one single file, making programming easier later on as everything is centralized here.

We will use several free sounds to build a pirates pub ambiance experience for our examples.

Of course, these files should be edited and sometimes converted if they don’t fit properly into your project.

Let’s add some music files first:

define pirates_accordion = "assets/audio/musics/pirates_accordion.ogg" 
#https://freesound.org/people/alphatone/sounds/385876/

And some funny sounds along with that.

define tavern_ambiance = "assets/audio/sfx/tavern_ambiance.ogg"
#https://freesound.org/people/ivolipa/sounds/326313/
define glass_smash = "assets/audio/sfx/glass_smash.ogg"
#https://freesound.org/people/InspectorJ/sounds/344271/
define evil_laugh = "assets/audio/voices/evil_laugh.ogg"
#https://freesound.org/people/DevenGarber/sounds/236982/

It’s a tavern ambiance, after all!

With our defined sounds, we can now process to the next step.

Make New Renpy Audio Channels

To create other Renpy audio channels, we will have to use the function renpy.music.register_channel() with specific parameters.

As we are creating new audio channels, we need to give them names first.

Then we have to give them a mixer.

A mixer, in this case, refers to the sound type and should take one of these 3 default values:

  • music
  • sfx (sound effects)
  • voice

If you want to customize the mixers, you may have to edit some native Renpy screens.

But that could be something to do later, maybe for another tutorial.

So now that you know about the function and both required parameters let’s add them to your audio.rpy file.

Here’s how to do:

init:

    init python:
        renpy.music.register_channel("newMusicChannel", "music") #Extra music channel for my pirate accordion music
        renpy.music.register_channel("newVoiceChannel", "voice") #Extra voice channel for my evil laugh voice
        renpy.music.register_channel("newSoundChannel1", "sfx") #Extra sound effect for my tavern ambient sound
        renpy.music.register_channel("newSoundChannel2", "sfx") #Extra sound effect for my glass smash sound

If you are not yet familiar with how init works, I highly recommend adding this part of the code at the beginning of the file, just before your audio file path declarations.

You will have to adjust the names with yours, but the process is the same.

You can also create as many new audio channels as you want and custom them with other Ren’Py channel parameters.

Ok then, it’s time to use them!

Play Sounds On Your Custom Channels

And the last step to do is to play your sound on your dedicated audio channels.

The process is similar to adding and playing music in Renpy but slightly different.

As you previously defined channels with specific names, you will have to call them somewhere to use them.

We will use the Ren’Py Play clause alongside the audio channel name.

It should be something like Play + <your_audio_channel_name> + <your_sound_variable>.

Here is what it looks like with our examples:

play newMusicChannel pirates_accordion #We play our pirates accordion music in the newMusicChannel
play newVoiceChannel evil_laugh #We play our evil laugh voice in the newVoiceChannel
play newSoundChannel1 tavern_ambiance #We play our tavern ambiance sound in the newSoundChannel1
play newSoundChannel2 glass_smash #We play our glass smash sound in the newSoundChannel2

And with a bit of story, well, kind of:

label start:

    play newMusicChannel pirates_accordion fadein 2.0
    play newSoundChannel1 tavern_ambiance fadein 2.0
    "When Monokeke arrived at the pirate pub, he was immediately greeted by a group of drunken pirates."
    "They were so noisy, impossible to miss."
    "He had to be very cautious and quick."
    "Luckily for him, they were all busy drinking their liquor and didn't notice him."
    "Until one pirate saw Monokeke and asked what he wanted."
    monokeke "I'm looking for someone who knows where I can find an important secret map."
    play newVoiceChannel evil_laugh
    "The drunkards laughed so hard that they almost choked on their drinks!"
    pirate "Do you know how many people are trying to get that treasure? You'll never find it!"
    pirate2 "You're just like those guys from yesterday..."
    play newSoundChannel2 glass_smash
    pirate2 "yeah right! They came here too, asking for help!"


    return

And that’s it!

With these easy steps, you should now be able to define and custom audio channels for your own Ren’Py games.

By editing several sounds effects, music, and voices, you could even create new ambient sounds directly with Renpy.

I hope this article will help you a bit to manage these channels better.

Let me know in the comments if you have any questions, and feel free to share this article with your community.

Thanks for reading! 🙂

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *