AudioClip.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. /** @addtogroup Audio
  8. * @{
  9. */
  10. /// <summary>
  11. /// Valid internal engine audio formats.
  12. /// </summary>
  13. public enum AudioFormat // Note: Must match C++ enum AudioFormat
  14. {
  15. /// <summary>Pulse code modulation audio ("raw" uncompressed audio).</summary>
  16. PCM,
  17. /// <summary>Vorbis compressed audio.</summary>
  18. VORBIS
  19. }
  20. /// <summary>
  21. /// Modes that determine how and when is audio data read.
  22. /// </summary>
  23. public enum AudioReadMode // Note: Must match C++ enum AudioReadMode
  24. {
  25. /// <summary>
  26. /// Entire audio clip will be loaded and decompressed. Uses most memory but has lowest CPU impact.
  27. /// </summary>
  28. LoadDecompressed,
  29. /// <summary>
  30. /// Entire audio clip will be loaded, but will be decompressed while playing. Uses medium amount of memory and has
  31. /// the highest CPU impact.
  32. /// </summary>
  33. LoadCompressed,
  34. /// <summary>
  35. /// Audio will be slowly streamed from the disk, and decompressed if needed. Uses very little memory, and has either
  36. /// low or high CPU impact depending if the audio is in a compressed format. Since data is streamed from the disk,
  37. /// read speeds could also be a bottleneck.
  38. /// </summary>
  39. Stream
  40. }
  41. /// <summary>
  42. /// Numbers of bits per audio sample.
  43. /// </summary>
  44. public enum AudioBitDepth
  45. {
  46. Bits8 = 8,
  47. Bits16 = 16,
  48. Bits24 = 24,
  49. Bits32 = 32
  50. }
  51. /// <summary>
  52. /// Audio clip stores audio data in a compressed or uncompressed format. Clips can be provided to audio sources or
  53. /// other audio methods to be played.
  54. /// </summary>
  55. public class AudioClip : Resource
  56. {
  57. /// <summary>
  58. /// Constructor for internal use by the runtime.
  59. /// </summary>
  60. private AudioClip()
  61. { }
  62. /// <summary>
  63. /// Returns the size of a single sample, in bits.
  64. /// </summary>
  65. public int BitDepth
  66. {
  67. get { return Internal_GetBitDepth(mCachedPtr); }
  68. }
  69. /// <summary>
  70. /// Returns how many samples per second is the audio encoded in.
  71. /// </summary>
  72. public int SampleRate
  73. {
  74. get { return Internal_GetSampleRate(mCachedPtr); }
  75. }
  76. /// <summary>
  77. /// Returns the number of channels provided by the clip.
  78. /// </summary>
  79. public int NumChannels
  80. {
  81. get { return Internal_GetNumChannels(mCachedPtr); }
  82. }
  83. /// <summary>
  84. /// Returns in which format is audio data stored in.
  85. /// </summary>
  86. public AudioFormat Format
  87. {
  88. get { return Internal_GetAudioFormat(mCachedPtr); }
  89. }
  90. /// <summary>
  91. /// Returns how is the audio data read/decoded.
  92. /// </summary>
  93. public AudioReadMode ReadMode
  94. {
  95. get { return Internal_GetReadMode(mCachedPtr); }
  96. }
  97. /// <summary>
  98. /// Returns the total number of samples in the clip (includes all channels).
  99. /// </summary>
  100. public int NumSamples
  101. {
  102. get { return Internal_GetNumSamples(mCachedPtr); }
  103. }
  104. /// <summary>
  105. /// Returns the length of the audio clip, in seconds.
  106. /// </summary>
  107. public float Duration
  108. {
  109. get { return Internal_GetDuration(mCachedPtr); }
  110. }
  111. /// <summary>
  112. /// Determines will the clip be played a spatial 3D sound, or as a normal sound (for example music).
  113. /// </summary>
  114. public bool Is3D
  115. {
  116. get { return Internal_GetIs3D(mCachedPtr); }
  117. }
  118. [MethodImpl(MethodImplOptions.InternalCall)]
  119. private static extern int Internal_GetBitDepth(IntPtr thisPtr);
  120. [MethodImpl(MethodImplOptions.InternalCall)]
  121. private static extern int Internal_GetSampleRate(IntPtr thisPtr);
  122. [MethodImpl(MethodImplOptions.InternalCall)]
  123. private static extern int Internal_GetNumChannels(IntPtr thisPtr);
  124. [MethodImpl(MethodImplOptions.InternalCall)]
  125. private static extern AudioFormat Internal_GetAudioFormat(IntPtr thisPtr);
  126. [MethodImpl(MethodImplOptions.InternalCall)]
  127. private static extern AudioReadMode Internal_GetReadMode(IntPtr thisPtr);
  128. [MethodImpl(MethodImplOptions.InternalCall)]
  129. private static extern int Internal_GetNumSamples(IntPtr thisPtr);
  130. [MethodImpl(MethodImplOptions.InternalCall)]
  131. private static extern float Internal_GetDuration(IntPtr thisPtr);
  132. [MethodImpl(MethodImplOptions.InternalCall)]
  133. private static extern bool Internal_GetIs3D(IntPtr thisPtr);
  134. }
  135. /** @} */
  136. }