/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
- namespace Delta.ContentSystem.Multimedia
- {
- /// <summary>
- /// Abstract base sound class. Needs to be implemented in the platform
- /// multimedia module. Native data and properties are set in the derived
- /// classes.
- /// </summary>
- public class SoundData : Content
- {
- #region Get (Static)
- /// <summary>
- /// Get and load content based on the content name. This method makes sure
- /// we do not load the same content twice (the constructor is protected).
- /// </summary>
- /// <param name="contentName">Content name we want to load, this is
- /// passed onto the Content System, which will do the actual loading with
- /// help of the Load method in this class.</param>
- /// <returns>The loaded Content object, always unique for the same
- /// name, this helps comparing data.</returns>
- public static SoundData Get(string contentName)
- {
- return Get<SoundData>(contentName, ContentType.Sound);
- }
- #endregion
-
- #region TimeLength (Public)
- /// <summary>
- /// The length in seconds this sound data plays.
- /// </summary>
- public float TimeLength
- {
- get
- {
- // Otherwise: (float)Samples / (float)SampleRate
- return data.TimeLength;
- }
- }
- #endregion
-
- #region Pitch (Public)
- /// <summary>
- /// The pitch (speed) of the sound.
- /// </summary>
- public float Pitch
- {
- get
- {
- return data.SoundPitch;
- }
- }
- #endregion
-
- #region Volume (Public)
- /// <summary>
- /// The volume of the sound.
- /// </summary>
- public float Volume
- {
- get
- {
- return data.SoundVolume;
- }
- }
- #endregion
-
- #region Pan (Public)
- /// <summary>
- /// For sound we can specify a panning value which is the balance between
- /// left and right speaker.
- /// 0.0f = center (default)
- /// -1.0f = full left
- /// 1.0f = full right
- /// </summary>
- public float Pan
- {
- get
- {
- return data.SoundPan;
- }
- }
- #endregion
-
- #region Constructors
- /// <summary>
- /// Create base sound class.
- /// </summary>
- /// <param name="contentName">Name of the content.</param>
- public SoundData(string contentName)
- : base(contentName, ContentType.Sound)
- {
- }
- #endregion
-
- #region ToString (Public)
- /// <summary>
- /// Return an information string about this SoundData instance.
- /// </summary>
- /// <returns>String containing information about the sound data.</returns>
- public override string ToString()
- {
- return "SoundData(Name=" + Name + " TimeLength=" + TimeLength +
- " Pitch=" + Pitch + " Volume=" + Volume + " Pan=" + Pan +
- " FailedToLoad=" + FailedToLoad + ")";
- }
- #endregion
-
- #region Methods (Private)
-
- #region Load
- /// <summary>
- /// Load sound content data, does nothing. Only properties are assigned.
- /// No loading happens here (it all happens in Sound), we can obviously
- /// clone all SoundDatas with the same name as they are not loaded here.
- /// Note: If a class is interested in the content reload functionality,
- /// it can just attach itself to the ContentChanged event.
- /// </summary>
- /// <param name="alreadyLoadedNativeData">If we already have native data
- /// loaded, clone it from this instance. Only used if not null. Please
- /// note that this is only used for other objects that had the same
- /// RawFileId and are already loaded and returned true for this method.
- /// </param>
- protected override void Load(Content alreadyLoadedNativeData)
- {
- }
- #endregion
-
- #endregion
- }
- }