Audio.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System;
  4. using System.Runtime.CompilerServices;
  5. namespace BansheeEngine
  6. {
  7. /// <summary>
  8. /// Identifier for a device that can be used for playing audio.
  9. /// </summary>
  10. public class AudioDevice : ScriptObject
  11. {
  12. /// <summary>
  13. /// Constructor for internal use by the runtime only.
  14. /// </summary>
  15. private AudioDevice() { }
  16. /// <summary>
  17. /// Name of the audio device.
  18. /// </summary>
  19. public string Name
  20. {
  21. get { return Internal_GetName(mCachedPtr); }
  22. }
  23. [MethodImpl(MethodImplOptions.InternalCall)]
  24. private static extern string Internal_GetName(IntPtr thisPtr);
  25. }
  26. /// <summary>
  27. /// Provides global functionality relating to sounds and music.
  28. /// </summary>
  29. public static class Audio
  30. {
  31. /// <summary>
  32. /// Global audio volume. In range [0, 1].
  33. /// </summary>
  34. public static float Volume
  35. {
  36. get { return Internal_GetVolume(); }
  37. set { Internal_SetVolume(value); }
  38. }
  39. /// <summary>
  40. /// Device on which is the audio played back on.
  41. /// </summary>
  42. public static AudioDevice ActiveDevice
  43. {
  44. get { return Internal_GetActiveDevice(); }
  45. set
  46. {
  47. IntPtr devicePtr = IntPtr.Zero;
  48. if (value != null)
  49. devicePtr = value.GetCachedPtr();
  50. Internal_SetActiveDevice(devicePtr);
  51. }
  52. }
  53. /// <summary>
  54. /// Returns the default audio device identifier.
  55. /// </summary>
  56. public static AudioDevice DefaultDevice
  57. {
  58. get { return Internal_GetDefaultDevice(); }
  59. }
  60. /// <summary>
  61. /// Returns a list of all available audio devices
  62. /// </summary>
  63. public static AudioDevice[] AllDevices
  64. {
  65. get { return Internal_GetAllDevices(); }
  66. }
  67. [MethodImpl(MethodImplOptions.InternalCall)]
  68. private static extern void Internal_SetVolume(float volume);
  69. [MethodImpl(MethodImplOptions.InternalCall)]
  70. private static extern float Internal_GetVolume();
  71. [MethodImpl(MethodImplOptions.InternalCall)]
  72. private static extern void Internal_SetActiveDevice(IntPtr device);
  73. [MethodImpl(MethodImplOptions.InternalCall)]
  74. private static extern AudioDevice Internal_GetActiveDevice();
  75. [MethodImpl(MethodImplOptions.InternalCall)]
  76. private static extern AudioDevice Internal_GetDefaultDevice();
  77. [MethodImpl(MethodImplOptions.InternalCall)]
  78. private static extern AudioDevice[] Internal_GetAllDevices();
  79. }
  80. }