setDevice.lua 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. return {
  2. tag = 'devices',
  3. summary = 'Switch audio devices.',
  4. description = [[
  5. Switches either the playback or capture device to a new one.
  6. If a device for the given type is already active, it will be stopped and destroyed. The new
  7. device will not be started automatically, use `lovr.audio.start` to start it.
  8. A device id (previously retrieved using `lovr.audio.getDevices`) can be given to use a specific
  9. audio device, or `nil` can be used for the id to use the default audio device.
  10. A sink can be also be provided when changing the device. A sink is an audio stream (`Sound`
  11. object with a `stream` type) that will receive all audio samples played (for playback) or all
  12. audio samples captured (for capture). When an audio device with a sink is started, be sure to
  13. periodically call `Sound:read` on the sink to read audio samples from it, otherwise it will
  14. overflow and discard old data. The sink can have any format, data will be converted as needed.
  15. Using a sink for the playback device will reduce performance, but this isn't the case for
  16. capture devices.
  17. Audio devices can be started in `shared` or `exclusive` mode. Exclusive devices may have lower
  18. latency than shared devices, but there's a higher chance that requesting exclusive access to an
  19. audio device will fail (either because it isn't supported or allowed). One strategy is to first
  20. try the device in exclusive mode, switching to shared if it doesn't work.
  21. ]],
  22. arguments = {
  23. type = {
  24. type = 'AudioType',
  25. default = [['playback']],
  26. description = 'The device to switch.'
  27. },
  28. id = {
  29. type = 'userdata',
  30. default = 'nil',
  31. description = 'The id of the device to use, or `nil` to use the default device.'
  32. },
  33. sink = {
  34. type = 'Sound',
  35. default = 'nil',
  36. description = 'An optional audio stream to use as a sink for the device.'
  37. },
  38. mode = {
  39. type = 'AudioShareMode',
  40. default = 'shared',
  41. description = 'The sharing mode for the device.'
  42. }
  43. },
  44. returns = {
  45. success = {
  46. type = 'boolean',
  47. description = 'Whether creating the audio device succeeded.'
  48. }
  49. },
  50. variants = {
  51. {
  52. arguments = { 'type', 'id', 'sink', 'mode' },
  53. returns = { 'success' }
  54. }
  55. },
  56. related = {
  57. 'lovr.audio.getDevice',
  58. 'lovr.audio.getDevices',
  59. 'lovr.audio.start',
  60. 'lovr.audio.stop'
  61. }
  62. }