newSource.lua 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. return {
  2. tag = 'sources',
  3. summary = 'Create a new Source.',
  4. description = 'Creates a new Source from an ogg, wav, or mp3 file.',
  5. arguments = {
  6. filename = {
  7. type = 'string',
  8. description = 'The filename of the sound to load.'
  9. },
  10. blob = {
  11. type = 'Blob',
  12. description = 'The Blob containing the Source data.'
  13. },
  14. sound = {
  15. type = 'Sound',
  16. description = 'The Sound containing raw audio samples to play.'
  17. },
  18. options = {
  19. type = 'table',
  20. description = 'Optional options.',
  21. table = {
  22. {
  23. name = 'decode',
  24. type = 'boolean',
  25. default = 'false',
  26. description = [[
  27. Whether to immediately decode compressed sounds, instead of progressively decoding as
  28. the Source plays. Enabling this will use more memory but reduce CPU overhead during
  29. playback. Recommended for short sound effects.
  30. ]]
  31. },
  32. {
  33. name = 'pitchable',
  34. type = 'boolean',
  35. default = 'true',
  36. description = [[
  37. Whether the pitch of the Source can be changed with `Source:setPitch`. Setting this to
  38. false will improve performance slightly.
  39. ]]
  40. },
  41. {
  42. name = 'spatial',
  43. type = 'boolean',
  44. default = 'true',
  45. description = [[
  46. Whether the Source should use spatial effects. Non-spatial sources will get routed
  47. directly to the speakers without further processing. Enabling an effect on a
  48. non-spatial source will raise an error.
  49. ]]
  50. },
  51. {
  52. name = 'effects',
  53. type = 'table',
  54. default = 'nil',
  55. description = [[
  56. A table of `Effect`s to enable on the Source. This can be a list (numeric keys, effect
  57. name values) or a map (effect name keys, boolean values) or a mix of the two. Effects
  58. can also be enabled later using `Source:setEffectEnabled`. If nil, all effects will be
  59. enabled. Ignored if the `spatial` flag is false.
  60. ]]
  61. }
  62. }
  63. }
  64. },
  65. returns = {
  66. source = {
  67. type = 'Source',
  68. description = 'The new Source.'
  69. }
  70. },
  71. variants = {
  72. {
  73. arguments = { 'filename', 'options' },
  74. returns = { 'source' }
  75. },
  76. {
  77. arguments = { 'blob', 'options' },
  78. returns = { 'source' }
  79. },
  80. {
  81. arguments = { 'sound', 'options' },
  82. returns = { 'source' }
  83. }
  84. },
  85. example = [[
  86. function lovr.load()
  87. sandstorm = lovr.audio.newSource('darude.ogg', {
  88. decode = false,
  89. effects = { 'spatialization', attenuation = false, reverb = true }
  90. })
  91. sandstorm:play()
  92. end
  93. ]],
  94. related = {
  95. 'Source:clone'
  96. }
  97. }