Page 1 of 1

Set fadein/fadeout for custom looped audio channel? [SOLVED]

Posted: Tue Mar 12, 2024 11:53 pm
by dragonsmidst
Hello,
I was wondering, is there a way to set a custom looped audio channel to automatically fadin and fadeout when using the channel rather than having to specify it when using the play statement?

I tried to take the example in the documentation for play:

Code: Select all

renpy.music.play(filenames, channel='music', loop=None, fadeout=None, synchro_start=False, fadein=0, tight=None, if_changed=False, relative_volume=1.0)
and adapt it for my purpose to:

Code: Select all

init python:
    renpy.music.register_channel("ambient","sfx",loop=True,stop_on_mute=True, tight=True, fadein=1.0, fadeout=2.0)
and I get this error:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/inits.rpy", line 6, in script
    init python:
  File "game/inits.rpy", line 7, in <module>
    renpy.music.register_channel("ambient","sfx",loop=True,stop_on_mute=True, tight=True, fadein=1.0, fadeout=2.0)
TypeError: register_channel() got an unexpected keyword argument 'fadein'

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/inits.rpy", line 6, in script
    init python:
  File "C:\Users\mmay3\Documents\Renpy\renpy-7.4.11-sdk\renpy\ast.py", line 823, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "C:\Users\mmay3\Documents\Renpy\renpy-7.4.11-sdk\renpy\python.py", line 1178, in py_exec_bytecode
    exec(bytecode, globals, locals)
  File "game/inits.rpy", line 7, in <module>
    renpy.music.register_channel("ambient","sfx",loop=True,stop_on_mute=True, tight=True, fadein=1.0, fadeout=2.0)
TypeError: register_channel() got an unexpected keyword argument 'fadein'

Windows-10-10.0.19045 AMD64
Ren'Py 8.2.1.24030407
Tue Mar 12 20:48:39 2024
I'm not sure if I have the syntax wrong or if it's just not possible or if it needs to be done in a different way. Any help would be appreciated. Thank you :)

Re: Set fadein/fadeout for custom looped audio channel?

Posted: Wed Mar 13, 2024 5:09 am
by jeffster
dragonsmidst wrote: Tue Mar 12, 2024 11:53 pm I'm not sure if I have the syntax wrong or if it's just not possible or if it needs to be done in a different way. Any help would be appreciated. Thank you :)
The documentation of "register_channel" says that you can use parameters:
name, mixer, loop, stop_on_mute, tight, file_prefix, file_suffix, buffer_queue, movie, framedrop

For this function, there are no parameters related to fading.

You can use fading parameters with "play".

To use shorter syntax, it's possible to wrap functions with constant parameters like this:

Code: Select all

init python:
    renpy.music.register_channel("ambient","sfx",loop=True,stop_on_mute=True, tight=True)

    def ambience(filenames):
        renpy.music.play(filenames, 'ambient', fadein=1.0, fadeout=2.0)

label start:
    $ ambience("wind.opus")
    raj "It's windy outside. Does it start raining?"
    $ ambience(["rain1.opus", "rain2.ogg", "thunderstorm1.mp3"])

Re: Set fadein/fadeout for custom looped audio channel?

Posted: Wed Mar 13, 2024 2:37 pm
by dragonsmidst
jeffster wrote: Wed Mar 13, 2024 5:09 am
dragonsmidst wrote: Tue Mar 12, 2024 11:53 pm I'm not sure if I have the syntax wrong or if it's just not possible or if it needs to be done in a different way. Any help would be appreciated. Thank you :)
The documentation of "register_channel" says that you can use parameters:
name, mixer, loop, stop_on_mute, tight, file_prefix, file_suffix, buffer_queue, movie, framedrop

For this function, there are no parameters related to fading.

You can use fading parameters with "play".

To use shorter syntax, it's possible to wrap functions with constant parameters like this:

Code: Select all

init python:
    renpy.music.register_channel("ambient","sfx",loop=True,stop_on_mute=True, tight=True)

    def ambience(filenames):
        renpy.music.play(filenames, 'ambient', fadein=1.0, fadeout=2.0)

label start:
    $ ambience("wind.opus")
    raj "It's windy outside. Does it start raining?"
    $ ambience(["rain1.opus", "rain2.ogg", "thunderstorm1.mp3"])
This is very helpful, thank you! :D