Heirukichi

HAF-VXAce

Jun 27th, 2018
501
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.07 KB | None | 0 0
  1. #===========================================================================
  2. # HEIRUKICHI AUDIO FIX
  3. #===========================================================================
  4. # - Version 1.0
  5. # Last update: 06-15-2018 [M-D-Y]
  6. #===========================================================================
  7. # TERMS OF USE
  8. #---------------------------------------------------------------------------
  9. # You are free to use this script for both commercial and non commercial
  10. # games as long as you give proper credit to me (Heirukichi).
  11. # I would like to be notified in case you decide to use this script for
  12. # commercial purposes and it would be nice if you could provide me a link to
  13. # the selling page (not a free copy of your game, just a link to its page).
  14. # It would be very appreciated if you could do the same for non-commercial
  15. # games too but that is not mandatory.
  16. #===========================================================================
  17. # DESCRIPTION
  18. #---------------------------------------------------------------------------
  19. # This script is meant to fix your game volume when using custom audio files
  20. # with different loudness levels. Using this you can fix volume for every
  21. # kind of sound without the player noticing it.
  22. #===========================================================================
  23. # INSTRUCTIONS
  24. #---------------------------------------------------------------------------
  25. # The HAF_Config module contains two different arrays: FLAG_SWITCH_ID and
  26. # AUDIO_MULT. The first one is used to store IDs of switches you want to use
  27. # as flags, the other one is used to store your volume multiplier.
  28. #
  29. # The 1st value in each array is related to BGM, the 2nd to BGS, the 3rd to
  30. # SE and the 4th to ME.
  31. #
  32. # The audio fix is applied when those switches are false ("OFF") so that the
  33. # reduction is applied at the beginning of the game and you can increase it
  34. # later without the player noticing a sudden reduction to all sounds except
  35. # the quieter one. If there is any kind of audio file you don't want to be
  36. # reduced just set its AUDIO_MULT value to be 1.0.
  37. #===========================================================================
  38. # COMPATIBILITY
  39. #---------------------------------------------------------------------------
  40. # This script aliases a few methods so it should work with any other script
  41. # that aliases those. If you are using any script to modify audio settings
  42. # which aliases/overwrites those methods I would recommend you to place this
  43. # BELOW those.
  44. #---------------------------------------------------------------------------
  45. # METHODS:
  46. #---------------------------------------------------------------------------
  47. # Audio
  48. #   * bgm_play (aliased method)
  49. #   * bgs_play (aliased method)
  50. #   * se_play (aliased method)
  51. #   * me_play (aliased method)
  52. #   * haf_new_volume (new method)
  53. #===========================================================================
  54.  
  55. module HAF_Config
  56.    
  57.     #=======================================================================
  58.     # Change the following values to be IDs of the switches you want to use
  59.     # as a flag. Default is [1, 2, 3, 4].
  60.     # They are respectively used for BGM, BGS, SE and ME.
  61.     #=======================================================================
  62.    
  63.     FLAG_SWITCH_ID = [1, 2, 3, 4]
  64.    
  65.     #=======================================================================
  66.     # Change following values to be your audio multiplier. Default is 0.8
  67.     # which means your audio plays at 80% its total volume.
  68.     # These values refer respectively to BGM, BGS, SE and ME.
  69.     #=======================================================================
  70.    
  71.     AUDIO_MULT = [0.8, 0.8, 0.8, 0.8]
  72.    
  73. end
  74.  
  75. #===========================================================================
  76. # End of script configuration. Do not modify what follows unless you know
  77. # exactly what you are doing. Any modification to what's written below this
  78. # point might prevent the script from working.
  79. #===========================================================================
  80.  
  81. class << Audio
  82.  
  83.     alias_method 'haf_seplay_old',  'se_play'
  84.     alias_method 'haf_meplay_old',  'me_play'
  85.     alias_method 'haf_bgmplay_old', 'bgm_play'
  86.     alias_method 'haf_bgsplay_old', 'bgs_play'
  87.        
  88.     def bgm_play(filename, volume, pitch, position = nil)
  89.         volume = haf_new_volume(volume, 0)
  90.         unless (position == nil)
  91.             haf_bgmplay_old(filename, volume, pitch, position)
  92.         else
  93.             haf_bgmplay_old(filename, volume, pitch)
  94.         end
  95.     end
  96.        
  97.     def bgs_play(filename, volume, pitch, position = nil)
  98.         volume = haf_new_volume(volume, 1)
  99.         unless (position == nil)
  100.             haf_bgsplay_old(filename, volume, pitch, position)
  101.         else
  102.             haf_bgsplay_old(filename, volume, pitch)
  103.         end
  104.     end
  105.        
  106.     def se_play(filename, volume, pitch)
  107.         volume = haf_new_volume(volume, 2)
  108.         haf_seplay_old(filename, volume, pitch)
  109.     end
  110.    
  111.     def me_play(filename, volume, pitch)
  112.         volume = haf_new_volume(volume, 3)
  113.         haf_meplay_old(filename, volume, pitch)
  114.     end
  115.    
  116.     def haf_new_volume(volume, i)
  117.         return volume if $game_switches[HAF_Config::FLAG_SWITCH_ID[i]]
  118.         return (volume * HAF_Config::AUDIO_MULT[i]).to_i
  119.     end
  120.    
  121. end
Advertisement
Add Comment
Please, Sign In to add comment