Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. #===
  2. #Audio (FmodEx)
  3. # A rewrite of Audio module to integrate FmodEx
  4. #---
  5. #© 2015 - Nuri Yuri (塗 ゆり)
  6. #© 2015 - GiraPrimal : Concept of LOOP_TABLE
  7. #---
  8. #Script written by the menbers of the Community Script Project
  9. #===
  10. module Audio
  11. LOOP_TABLE = [
  12. # [ "Audio/xxx/File_name", begin, end ]
  13. # Add here
  14. # Note : Renember to add a comma after each ]
  15. # (except for the last line and the below ]).
  16. ]
  17. #---
  18. #>Puts the file names in lowercase to improve the search
  19. #---
  20. LOOP_TABLE.each do |i| i[0].downcase! end
  21. unless @bgm_play #>To avoid the RGSSReset problem
  22. #===
  23. #>Load and initialize FmodEx
  24. #===
  25. Kernel.load_module("RGSS FmodEx.dll","Init_FmodEx")
  26. ::FmodEx.init(32)
  27. #---
  28. #>Indication of the default lib'
  29. #---
  30. @library = ::FmodEx
  31. #---
  32. #>Saving the RGSS functions
  33. #---
  34. @bgm_play = method(:bgm_play)
  35. @bgm_fade = method(:bgm_fade)
  36. @bgm_stop = method(:bgm_stop)
  37. @bgs_play = method(:bgs_play)
  38. @bgs_fade = method(:bgs_fade)
  39. @bgs_stop = method(:bgs_stop)
  40. @me_play = method(:me_play)
  41. @me_fade = method(:me_fade)
  42. @me_stop = method(:me_stop)
  43. @se_play = method(:se_play)
  44. @se_stop = method(:se_stop)
  45. #---
  46. #>Volumes definition
  47. #---
  48. @master_volume = 100
  49. @sfx_volume = 100
  50. #===
  51. #>Extensions supported by FmodEx
  52. #===
  53. EXT = ['.ogg', '.mp3', '.wav', '.mid', '.aac', '.wma', '.it', '.xm', '.mod', '.s3m', '.midi']
  54. #===
  55. #>Creation/definition of the functions
  56. #===
  57. module_function
  58. def bgm_play(file_name, volume = 100, pitch = 100)
  59. volume = volume * @master_volume / 100
  60. return @bgm_play.call(file_name, volume, pitch) if(@library != ::FmodEx)
  61. filename = check_file(file_name)
  62. bgm = ::FmodEx.bgm_play(filename, volume, pitch)
  63. loop_audio(bgm, file_name)
  64. end
  65. def bgm_fade(time)
  66. return @bgm_fade.call(time) if(@library != ::FmodEx)
  67. ::FmodEx.bgm_fade(time)
  68. end
  69. def bgm_stop
  70. return @bgm_stop.call if(@library != ::FmodEx)
  71. ::FmodEx.bgm_stop
  72. end
  73. def bgs_play(file_name, volume = 100, pitch = 100)
  74. volume = volume * @sfx_volume / 100
  75. return @bgs_play.call(file_name, volume, pitch) if(@library != ::FmodEx)
  76. filename = check_file(file_name)
  77. bgs = ::FmodEx.bgs_play(filename, volume, pitch)
  78. loop_audio(bgs, file_name)
  79. end
  80. def bgs_fade(time)
  81. return @bgs_fade.call(time) if(@library != ::FmodEx)
  82. ::FmodEx.bgs_fade(time)
  83. end
  84. def bgs_stop
  85. return @bgs_stop.call if(@library != ::FmodEx)
  86. ::FmodEx.bgs_stop
  87. end
  88. def me_play(file_name, volume = 100, pitch = 100)
  89. volume = volume * @master_volume / 100
  90. return @me_play.call(file_name, volume, pitch) if(@library != ::FmodEx)
  91. file_name = check_file(file_name)
  92. ::FmodEx.me_play(file_name, volume, pitch)
  93. end
  94. def me_fade(time)
  95. return @me_fade.call(time) if(@library != ::FmodEx)
  96. ::FmodEx.me_fade(time)
  97. end
  98. def me_stop
  99. return @me_stop.call if(@library != ::FmodEx)
  100. ::FmodEx.me_stop
  101. end
  102. def se_play(file_name, volume = 100, pitch = 100)
  103. volume = volume * @sfx_volume / 100
  104. return @se_play.call(file_name, volume, pitch) if(@library != ::FmodEx)
  105. file_name = check_file(file_name)
  106. ::FmodEx.se_play(file_name, volume, pitch)
  107. end
  108. def se_stop
  109. return @se_stop.call if(@library != ::FmodEx)
  110. ::FmodEx.se_stop
  111. end
  112. #===
  113. #>check_file
  114. # Check the presence of the file and return the filename
  115. # /!\ Doesn't correct the mistake
  116. #====
  117. def check_file(file_name)
  118. return file_name if File.exist?(file_name)
  119. EXT.each do |ext|
  120. filename = file_name+ext
  121. return filename if File.exist?(filename)
  122. end
  123. return file_name
  124. end
  125. #===
  126. #>loop_audio
  127. # Function that automatically call the set_loop_points
  128. #===
  129. def loop_audio(sound, file_name)
  130. filename = file_name.downcase
  131. LOOP_TABLE.each do |i|
  132. if(i[0] == filename)
  133. return sound.set_loop_points(i[1], i[2])
  134. end
  135. end
  136. end
  137. end
  138. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement