Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #===========================================================================
- # HEIRUKICHI AUDIO FIX
- #===========================================================================
- # - Version 1.0
- # Last update: 06-15-2018 [M-D-Y]
- #===========================================================================
- # TERMS OF USE
- #---------------------------------------------------------------------------
- # You are free to use this script for both commercial and non commercial
- # games as long as you give proper credit to me (Heirukichi).
- # I would like to be notified in case you decide to use this script for
- # commercial purposes and it would be nice if you could provide me a link to
- # the selling page (not a free copy of your game, just a link to its page).
- # It would be very appreciated if you could do the same for non-commercial
- # games too but that is not mandatory.
- #===========================================================================
- # DESCRIPTION
- #---------------------------------------------------------------------------
- # This script is meant to fix your game volume when using custom audio files
- # with different loudness levels. Using this you can fix volume for every
- # kind of sound without the player noticing it.
- #===========================================================================
- # INSTRUCTIONS
- #---------------------------------------------------------------------------
- # The HAF_Config module contains two different arrays: FLAG_SWITCH_ID and
- # AUDIO_MULT. The first one is used to store IDs of switches you want to use
- # as flags, the other one is used to store your volume multiplier.
- #
- # The 1st value in each array is related to BGM, the 2nd to BGS, the 3rd to
- # SE and the 4th to ME.
- #
- # The audio fix is applied when those switches are false ("OFF") so that the
- # reduction is applied at the beginning of the game and you can increase it
- # later without the player noticing a sudden reduction to all sounds except
- # the quieter one. If there is any kind of audio file you don't want to be
- # reduced just set its AUDIO_MULT value to be 1.0.
- #===========================================================================
- # COMPATIBILITY
- #---------------------------------------------------------------------------
- # This script aliases a few methods so it should work with any other script
- # that aliases those. If you are using any script to modify audio settings
- # which aliases/overwrites those methods I would recommend you to place this
- # BELOW those.
- #---------------------------------------------------------------------------
- # METHODS:
- #---------------------------------------------------------------------------
- # Audio
- # * bgm_play (aliased method)
- # * bgs_play (aliased method)
- # * se_play (aliased method)
- # * me_play (aliased method)
- # * haf_new_volume (new method)
- #===========================================================================
- module HAF_Config
- #=======================================================================
- # Change the following values to be IDs of the switches you want to use
- # as a flag. Default is [1, 2, 3, 4].
- # They are respectively used for BGM, BGS, SE and ME.
- #=======================================================================
- FLAG_SWITCH_ID = [1, 2, 3, 4]
- #=======================================================================
- # Change following values to be your audio multiplier. Default is 0.8
- # which means your audio plays at 80% its total volume.
- # These values refer respectively to BGM, BGS, SE and ME.
- #=======================================================================
- AUDIO_MULT = [0.8, 0.8, 0.8, 0.8]
- end
- #===========================================================================
- # End of script configuration. Do not modify what follows unless you know
- # exactly what you are doing. Any modification to what's written below this
- # point might prevent the script from working.
- #===========================================================================
- class << Audio
- alias_method 'haf_seplay_old', 'se_play'
- alias_method 'haf_meplay_old', 'me_play'
- alias_method 'haf_bgmplay_old', 'bgm_play'
- alias_method 'haf_bgsplay_old', 'bgs_play'
- def bgm_play(filename, volume, pitch, position = nil)
- volume = haf_new_volume(volume, 0)
- unless (position == nil)
- haf_bgmplay_old(filename, volume, pitch, position)
- else
- haf_bgmplay_old(filename, volume, pitch)
- end
- end
- def bgs_play(filename, volume, pitch, position = nil)
- volume = haf_new_volume(volume, 1)
- unless (position == nil)
- haf_bgsplay_old(filename, volume, pitch, position)
- else
- haf_bgsplay_old(filename, volume, pitch)
- end
- end
- def se_play(filename, volume, pitch)
- volume = haf_new_volume(volume, 2)
- haf_seplay_old(filename, volume, pitch)
- end
- def me_play(filename, volume, pitch)
- volume = haf_new_volume(volume, 3)
- haf_meplay_old(filename, volume, pitch)
- end
- def haf_new_volume(volume, i)
- return volume if $game_switches[HAF_Config::FLAG_SWITCH_ID[i]]
- return (volume * HAF_Config::AUDIO_MULT[i]).to_i
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment