def disable_mixer(): global mixer_enabled if not mix_ok or not mixer_enabled: return if old_wave is not None: mix.set_wave(old_wave) if old_midi is not None: mix.set_midi(old_midi) mixer_enabled = False
def periodic(): """ The periodic sound callback. This is called at around 20hz, and is responsible for adjusting the volume of the playing music if necessary, and also for calling the periodic functions of midi and the various channels, which then may play music. """ global pcm_volume if not pcm_ok: return False try: for c in all_channels: c.periodic() pss.periodic() # Perform a synchro-start if necessary. need_ss = False for c in all_channels: if c.synchro_start and c.wait_stop: need_ss = False break if c.synchro_start and not c.wait_stop: need_ss = True if need_ss: pss.unpause_all() for c in all_channels: c.synchro_start = False # Now, consider adjusting the volume of the channel. max_volume = -1.0 volumes = renpy.game.preferences.volumes if mix_ok: anything_playing = False for c in channels: vol = c.chan_volume * volumes[c.mixer] max_volume = max(max_volume, vol) if vol != 0: anything_playing = True if max_volume == -1.0: return if not anything_playing: disable_mixer() pcm_volume = -1.0 else: enable_mixer() if max_volume != pcm_volume: mix.set_wave(max_volume) pcm_volume = max_volume for c in all_channels: vol = c.chan_volume * volumes[c.mixer] vol /= max_volume if c.actual_volume != vol: pss.set_volume(c.number, vol) c.actual_volume = vol else: for c in all_channels: vol = c.chan_volume * volumes[c.mixer] if vol != c.actual_volume: pss.set_volume(c.number, vol) c.actual_volume = vol except: if renpy.config.debug_sound: raise