Sound.lua 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. class "Sound"
  2. function Sound:Sound(...)
  3. for k,v in pairs(arg) do
  4. if type(v) == "table" then
  5. if v.__ptr ~= nil then
  6. arg[k] = v.__ptr
  7. end
  8. end
  9. end
  10. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  11. self.__ptr = Polycore.Sound(unpack(arg))
  12. Polycore.__ptr_lookup[self.__ptr] = self
  13. end
  14. end
  15. function Sound:Play(loop)
  16. local retVal = Polycore.Sound_Play(self.__ptr, loop)
  17. end
  18. function Sound:Stop()
  19. local retVal = Polycore.Sound_Stop(self.__ptr)
  20. end
  21. function Sound:setVolume(newVolume)
  22. local retVal = Polycore.Sound_setVolume(self.__ptr, newVolume)
  23. end
  24. function Sound:setPitch(newPitch)
  25. local retVal = Polycore.Sound_setPitch(self.__ptr, newPitch)
  26. end
  27. function Sound:setIsPositional(isPositional)
  28. local retVal = Polycore.Sound_setIsPositional(self.__ptr, isPositional)
  29. end
  30. function Sound:setSoundPosition(position)
  31. local retVal = Polycore.Sound_setSoundPosition(self.__ptr, position.__ptr)
  32. end
  33. function Sound:setSoundVelocity(velocity)
  34. local retVal = Polycore.Sound_setSoundVelocity(self.__ptr, velocity.__ptr)
  35. end
  36. function Sound:setSoundDirection(direction)
  37. local retVal = Polycore.Sound_setSoundDirection(self.__ptr, direction.__ptr)
  38. end
  39. function Sound:setPositionalProperties(referenceDistance, maxDistance)
  40. local retVal = Polycore.Sound_setPositionalProperties(self.__ptr, referenceDistance, maxDistance)
  41. end
  42. function Sound:loadWAV(fileName)
  43. local retVal = Polycore.Sound_loadWAV(self.__ptr, fileName)
  44. if retVal == nil then return nil end
  45. if Polycore.__ptr_lookup[retVal] ~= nil then
  46. return Polycore.__ptr_lookup[retVal]
  47. else
  48. Polycore.__ptr_lookup[retVal] = ALuint("__skip_ptr__")
  49. Polycore.__ptr_lookup[retVal].__ptr = retVal
  50. return Polycore.__ptr_lookup[retVal]
  51. end
  52. end
  53. function Sound:loadOGG(fileName)
  54. local retVal = Polycore.Sound_loadOGG(self.__ptr, fileName)
  55. if retVal == nil then return nil end
  56. if Polycore.__ptr_lookup[retVal] ~= nil then
  57. return Polycore.__ptr_lookup[retVal]
  58. else
  59. Polycore.__ptr_lookup[retVal] = ALuint("__skip_ptr__")
  60. Polycore.__ptr_lookup[retVal].__ptr = retVal
  61. return Polycore.__ptr_lookup[retVal]
  62. end
  63. end
  64. function Sound:GenSource(buffer)
  65. local retVal = Polycore.Sound_GenSource(self.__ptr, buffer.__ptr)
  66. if retVal == nil then return nil end
  67. if Polycore.__ptr_lookup[retVal] ~= nil then
  68. return Polycore.__ptr_lookup[retVal]
  69. else
  70. Polycore.__ptr_lookup[retVal] = ALuint("__skip_ptr__")
  71. Polycore.__ptr_lookup[retVal].__ptr = retVal
  72. return Polycore.__ptr_lookup[retVal]
  73. end
  74. end
  75. function Sound:checkALError(operation)
  76. local retVal = Polycore.Sound_checkALError(self.__ptr, operation)
  77. end
  78. function Sound:soundError(err)
  79. local retVal = Polycore.Sound_soundError(self.__ptr, err)
  80. end
  81. function Sound:soundCheck(result, err)
  82. local retVal = Polycore.Sound_soundCheck(self.__ptr, result, err)
  83. end
  84. function Sound:__delete()
  85. Polycore.__ptr_lookup[self.__ptr] = nil
  86. Polycore.delete_Sound(self.__ptr)
  87. end