PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/ContentSystem/Multimedia/SoundData.cs

#
C# | 129 lines | 69 code | 9 blank | 51 comment | 0 complexity | 4045b644588cab116a67b417108d25b4 MD5 | raw file
Possible License(s): Apache-2.0
  1. namespace Delta.ContentSystem.Multimedia
  2. {
  3. /// <summary>
  4. /// Abstract base sound class. Needs to be implemented in the platform
  5. /// multimedia module. Native data and properties are set in the derived
  6. /// classes.
  7. /// </summary>
  8. public class SoundData : Content
  9. {
  10. #region Get (Static)
  11. /// <summary>
  12. /// Get and load content based on the content name. This method makes sure
  13. /// we do not load the same content twice (the constructor is protected).
  14. /// </summary>
  15. /// <param name="contentName">Content name we want to load, this is
  16. /// passed onto the Content System, which will do the actual loading with
  17. /// help of the Load method in this class.</param>
  18. /// <returns>The loaded Content object, always unique for the same
  19. /// name, this helps comparing data.</returns>
  20. public static SoundData Get(string contentName)
  21. {
  22. return Get<SoundData>(contentName, ContentType.Sound);
  23. }
  24. #endregion
  25. #region TimeLength (Public)
  26. /// <summary>
  27. /// The length in seconds this sound data plays.
  28. /// </summary>
  29. public float TimeLength
  30. {
  31. get
  32. {
  33. // Otherwise: (float)Samples / (float)SampleRate
  34. return data.TimeLength;
  35. }
  36. }
  37. #endregion
  38. #region Pitch (Public)
  39. /// <summary>
  40. /// The pitch (speed) of the sound.
  41. /// </summary>
  42. public float Pitch
  43. {
  44. get
  45. {
  46. return data.SoundPitch;
  47. }
  48. }
  49. #endregion
  50. #region Volume (Public)
  51. /// <summary>
  52. /// The volume of the sound.
  53. /// </summary>
  54. public float Volume
  55. {
  56. get
  57. {
  58. return data.SoundVolume;
  59. }
  60. }
  61. #endregion
  62. #region Pan (Public)
  63. /// <summary>
  64. /// For sound we can specify a panning value which is the balance between
  65. /// left and right speaker.
  66. /// 0.0f = center (default)
  67. /// -1.0f = full left
  68. /// 1.0f = full right
  69. /// </summary>
  70. public float Pan
  71. {
  72. get
  73. {
  74. return data.SoundPan;
  75. }
  76. }
  77. #endregion
  78. #region Constructors
  79. /// <summary>
  80. /// Create base sound class.
  81. /// </summary>
  82. /// <param name="contentName">Name of the content.</param>
  83. public SoundData(string contentName)
  84. : base(contentName, ContentType.Sound)
  85. {
  86. }
  87. #endregion
  88. #region ToString (Public)
  89. /// <summary>
  90. /// Return an information string about this SoundData instance.
  91. /// </summary>
  92. /// <returns>String containing information about the sound data.</returns>
  93. public override string ToString()
  94. {
  95. return "SoundData(Name=" + Name + " TimeLength=" + TimeLength +
  96. " Pitch=" + Pitch + " Volume=" + Volume + " Pan=" + Pan +
  97. " FailedToLoad=" + FailedToLoad + ")";
  98. }
  99. #endregion
  100. #region Methods (Private)
  101. #region Load
  102. /// <summary>
  103. /// Load sound content data, does nothing. Only properties are assigned.
  104. /// No loading happens here (it all happens in Sound), we can obviously
  105. /// clone all SoundDatas with the same name as they are not loaded here.
  106. /// Note: If a class is interested in the content reload functionality,
  107. /// it can just attach itself to the ContentChanged event.
  108. /// </summary>
  109. /// <param name="alreadyLoadedNativeData">If we already have native data
  110. /// loaded, clone it from this instance. Only used if not null. Please
  111. /// note that this is only used for other objects that had the same
  112. /// RawFileId and are already loaded and returned true for this method.
  113. /// </param>
  114. protected override void Load(Content alreadyLoadedNativeData)
  115. {
  116. }
  117. #endregion
  118. #endregion
  119. }
  120. }