modloader.bmx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. ' Copyright (c) 2016-2022 Bruce A Henderson
  2. '
  3. ' This software is provided 'as-is', without any express or implied
  4. ' warranty. In no event will the authors be held liable for any damages
  5. ' arising from the use of this software.
  6. '
  7. ' Permission is granted to anyone to use this software for any purpose,
  8. ' including commercial applications, and to alter it and redistribute it
  9. ' freely, subject to the following restrictions:
  10. '
  11. ' 1. The origin of this software must not be misrepresented; you must not
  12. ' claim that you wrote the original software. If you use this software
  13. ' in a product, an acknowledgment in the product documentation would be
  14. ' appreciated but is not required.
  15. '
  16. ' 2. Altered source versions must be plainly marked as such, and must not be
  17. ' misrepresented as being the original software.
  18. '
  19. ' 3. This notice may not be removed or altered from any source
  20. ' distribution.
  21. '
  22. SuperStrict
  23. Rem
  24. bbdoc: Mod music loader.
  25. End Rem
  26. Module Audio.ModLoader
  27. Import Audio.SoloudAudio
  28. Import "common.bmx"
  29. Rem
  30. bbdoc: Audio source for Openmpt supported music.
  31. about: Formats include 669, amf, ams, dbm, digi, dmf, dsm, far, gdm, ice, imf, it, itp, j2b, m15,
  32. mdl, med, mid, mo3, mod, mptm, mt2, mtm, okt, plm, psm, ptm, s3m, stm, ult, umx, wow and xm.
  33. End Rem
  34. Type TSLOpenmpt Extends TSLLoadableAudioSource
  35. Method New()
  36. asPtr = Openmpt_create()
  37. End Method
  38. Rem
  39. bbdoc:
  40. End Rem
  41. Method Load:Int(filename:String) Override
  42. Local s:Byte Ptr = filename.ToUTF8String()
  43. Local res:Int = Openmpt_load(asPtr, s)
  44. MemFree(s)
  45. Return res
  46. End Method
  47. Rem
  48. bbdoc:
  49. End Rem
  50. Method loadMem:Int(data:Byte Ptr, dataLen:Int, copy:Int = False, takeOwnership:Int = True) Override
  51. Return Openmpt_loadMemEx(asPtr, data, dataLen, copy, takeOwnership)
  52. End Method
  53. Rem
  54. bbdoc:
  55. End Rem
  56. Method loadStream:Int(stream:TStream) Override
  57. Local sf:TStreamFile = New TStreamFile.Create(stream)
  58. Return Openmpt_LoadFile(asPtr, sf.filePtr)
  59. End Method
  60. Rem
  61. bbdoc: Sets default volume for instances.
  62. End Rem
  63. Method setVolume(volume:Float) Override
  64. Openmpt_setVolume(asPtr, volume)
  65. End Method
  66. Rem
  67. bbdoc: Sets the looping of the instances created from this audio source.
  68. End Rem
  69. Method setLooping(loop:Int) Override
  70. Openmpt_setLooping(asPtr, loop)
  71. End Method
  72. Rem
  73. bbdoc: Set whether audio should auto-stop when it ends or not.
  74. End Rem
  75. Method setAutoStop(autoStop:Int) Override
  76. Openmpt_setAutoStop(asPtr, autoStop)
  77. End Method
  78. Rem
  79. bbdoc: Sets the minimum and maximum distances for 3d audio source (closer to min distance = max vol)
  80. End Rem
  81. Method set3dMinMaxDistance(minDistance:Float, maxDistance:Float) Override
  82. Openmpt_set3dMinMaxDistance(asPtr, minDistance, maxDistance)
  83. End Method
  84. Rem
  85. bbdoc: Sets attenuation model and rolloff factor for 3d audio source.
  86. End Rem
  87. Method set3dAttenuation(attenuationModel:Int, attenuationRolloffFactor:Float) Override
  88. Openmpt_set3dAttenuation(asPtr, attenuationModel, attenuationRolloffFactor)
  89. End Method
  90. Rem
  91. bbdoc: Sets doppler factor to reduce or enhance doppler effect, default = 1.0
  92. End Rem
  93. Method set3dDopplerFactor(dopplerFactor:Float) Override
  94. Openmpt_set3dDopplerFactor(asPtr, dopplerFactor)
  95. End Method
  96. Rem
  97. bbdoc: Enables 3d processing.
  98. about: Implicitly set by play3d calls.
  99. End Rem
  100. Method set3dListenerRelative(listenerRelative:Int) Override
  101. Openmpt_set3dListenerRelative(asPtr, listenerRelative)
  102. End Method
  103. Rem
  104. bbdoc: Sets the coordinates for this audio source to be relative to listener's coordinates.
  105. End Rem
  106. Method set3dDistanceDelay(distanceDelay:Int) Override
  107. Openmpt_set3dListenerRelative(asPtr, distanceDelay)
  108. End Method
  109. Rem
  110. bbdoc: Enables delaying the start of the sound based on the distance.
  111. End Rem
  112. Method set3dCollider(collider:TSLAudioCollider) Override
  113. ' TODO
  114. End Method
  115. Rem
  116. bbdoc: Sets a custom 3d audio collider.
  117. about: Set to Null to disable.
  118. End Rem
  119. Method set3dColliderEx(collider:TSLAudioCollider, userData:Int) Override
  120. ' TODO
  121. End Method
  122. Rem
  123. bbdoc: Sets a custom attenuator.
  124. about: Set to Null to disable.
  125. End Rem
  126. Method set3dAttenuator(attenuator:TSLAudioAttenuator) Override
  127. ' TODO
  128. End Method
  129. Rem
  130. bbdoc: Sets behavior for inaudible sounds.
  131. End Rem
  132. Method setInaudibleBehavior(mustTick:Int, kill:Int) Override
  133. Openmpt_setInaudibleBehavior(asPtr, mustTick, kill)
  134. End Method
  135. Rem
  136. bbdoc: Sets filter.
  137. about: Set to NULL to clear the filter.
  138. End Rem
  139. Method setFilter(filterId:Int, filter:TSLFilter) Override
  140. ' TODO
  141. End Method
  142. Rem
  143. bbdoc: Stops all instances of this audio source.
  144. End Rem
  145. Method stop() Override
  146. Openmpt_stop(asPtr)
  147. End Method
  148. Rem
  149. bbdoc: Returns the length of the audio source, in seconds.
  150. End Rem
  151. Method getLength:Double() Override
  152. Return Openmpt_getLength(asPtr)
  153. End Method
  154. Method destroy() Override
  155. If asPtr Then
  156. Openmpt_destroy(asPtr)
  157. asPtr = Null
  158. End If
  159. End Method
  160. Method Delete()
  161. destroy()
  162. End Method
  163. End Type
  164. New TSoloudModLoader(1)
  165. Type TSoloudModLoader Extends TAudioSourceLoader
  166. Method LoadAudioSource:TSLLoadableAudioSource( stream:TStream, flags:Int ) Override
  167. Local sound:TSLLoadableAudioSource = New TSLOpenmpt
  168. If sound.loadStream(stream) = SO_NO_ERROR Then
  169. Return sound
  170. End If
  171. sound.destroy()
  172. End Method
  173. End Type