sfxStream.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 _SFXSTREAM_H_
  23. #define _SFXSTREAM_H_
  24. #ifndef _THREADSAFEREFCOUNT_H_
  25. # include "platform/threads/threadSafeRefCount.h"
  26. #endif
  27. #ifndef _SFXCOMMON_H_
  28. # include "sfx/sfxCommon.h"
  29. #endif
  30. #ifndef _TSTREAM_H_
  31. # include "core/stream/tStream.h"
  32. #endif
  33. /// The base sound data streaming interface.
  34. ///
  35. /// @note Streams that support seeking should implement the IPositionable<U32> interface.
  36. /// @note Since SFXStreams are byte streams, all offset/size information is in bytes and
  37. /// not in number of samples.
  38. class SFXStream : public ThreadSafeRefCount< SFXStream >,
  39. public IInputStream< U8 >,
  40. public IResettable
  41. {
  42. public:
  43. typedef void Parent;
  44. /// Destructor.
  45. virtual ~SFXStream() {}
  46. /// Make a copy of this stream with its own private state, so
  47. /// new independent read() operations can be issued on the same
  48. /// data stream.
  49. ///
  50. /// @return Returns a copy of the stream or NULL.
  51. virtual SFXStream* clone() const { return NULL; }
  52. /// The format of the data in the stream.
  53. virtual const SFXFormat& getFormat() const = 0;
  54. /// The number of samples in the data stream.
  55. virtual U32 getSampleCount() const = 0;
  56. /// The data size in bytes of the decompressed PCM data.
  57. virtual U32 getDataLength() const = 0;
  58. /// The length of the sound in milliseconds.
  59. virtual U32 getDuration() const = 0;
  60. /// Returns true if we've reached the end of the stream.
  61. virtual bool isEOS() const = 0;
  62. /// Resets the stream to restart reading data from the begining.
  63. virtual void reset() = 0;
  64. /// Reads data from the stream and decompresses it into PCM samples.
  65. ///
  66. /// @param length Number of bytes to read.
  67. virtual U32 read( U8 *buffer, U32 length ) = 0;
  68. };
  69. typedef ThreadSafeRef< SFXStream > SFXStreamRef;
  70. #endif // _SFXSTREAM_H_