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

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
dragonsmidst
Newbie
Posts: 10
Joined: Mon Nov 02, 2020 2:49 pm
itch: Rollback
Contact:

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

#1 Post 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 :)
Last edited by dragonsmidst on Wed Mar 13, 2024 2:38 pm, edited 1 time in total.

jeffster
Veteran
Posts: 409
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

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

#2 Post 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"])

dragonsmidst
Newbie
Posts: 10
Joined: Mon Nov 02, 2020 2:49 pm
itch: Rollback
Contact:

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

#3 Post 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

Post Reply

Who is online

Users browsing this forum: Bing [Bot], decocloud, Google [Bot], Li yuanlin