sfxResource.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _SFXRESOURCE_H_
  23. #define _SFXRESOURCE_H_
  24. #ifndef _SFXCOMMON_H_
  25. #include "sfx/sfxCommon.h"
  26. #endif
  27. #ifndef __RESOURCE_H__
  28. #include "core/resource.h"
  29. #endif
  30. class SFXStream;
  31. /// This is the base class for all sound file resources including
  32. /// streamed sound files. It acts much like an always in-core
  33. /// header to the actual sound data which is read through an SFXStream.
  34. ///
  35. /// The first step occurs at ResourceManager::load() time at which
  36. /// only the header information, the format, size frequency, and
  37. /// looping flag, are loaded from the sound file. This provides
  38. /// just the nessasary information to simulate sound playback for
  39. /// sounds playing just out of the users hearing range.
  40. ///
  41. /// The second step loads the actual sound data or begins filling
  42. /// the stream buffer. This is triggered by a call to openStream().
  43. /// SFXProfile, for example, does this when mPreload is enabled.
  44. ///
  45. class SFXResource
  46. {
  47. public:
  48. typedef void Parent;
  49. protected:
  50. /// The constructor is protected.
  51. /// @see SFXResource::load()
  52. SFXResource();
  53. /// Path to the sound file.
  54. String mFileName;
  55. /// The format of the sample data.
  56. SFXFormat mFormat;
  57. /// The length of the sample in milliseconds.
  58. U32 mDuration;
  59. /// Construct a resource instance for the given file. Format and duration
  60. /// are read from the given stream.
  61. SFXResource( String fileName, SFXStream* stream );
  62. public:
  63. /// The destructor.
  64. virtual ~SFXResource() {}
  65. /// This is a helper function used by SFXProfile for load
  66. /// a sound resource. It takes care of trying different
  67. /// types for extension-less filenames.
  68. ///
  69. /// @param filename The sound file path with or without extension.
  70. ///
  71. static Resource< SFXResource > load( String filename );
  72. /// A helper function which returns true if the
  73. /// sound resource exists.
  74. ///
  75. /// @param filename The sound file path with or without extension.
  76. ///
  77. static bool exists( String filename );
  78. /// Return the path to the sound file.
  79. const String& getFileName() { return mFileName; }
  80. /// Returns the total playback time milliseconds.
  81. U32 getDuration() const { return mDuration; }
  82. /// The format of the data in the resource.
  83. const SFXFormat& getFormat() const { return mFormat; }
  84. /// Open a stream for reading the resource's sample data.
  85. SFXStream* openStream();
  86. // Internal.
  87. struct _NewHelper;
  88. friend struct _NewHelper;
  89. };
  90. #endif // _SFXRESOURCE_H_