sfxMemoryStream.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 _SFXMEMORYSTREAM_H_
  23. #define _SFXMEMORYSTREAM_H_
  24. #ifndef _SFXSTREAM_H_
  25. #include "sfx/sfxStream.h"
  26. #endif
  27. #ifndef _TSTREAM_H_
  28. #include "core/stream/tStream.h"
  29. #endif
  30. #ifndef _RAWDATA_H_
  31. #include "core/util/rawData.h"
  32. #endif
  33. /// A stream filter that converts sample packets from its source stream
  34. /// to a continuous sample stream. Useful for feeding sound from a source
  35. /// that pushes sample data in discrete packets.
  36. ///
  37. /// @note For the SFXMemoryStream to allow a reset(), the source input
  38. /// stream must implement IResettable.
  39. class SFXMemoryStream : public SFXStream,
  40. public IInputStreamFilter< U8, IInputStream< RawData* >* >
  41. {
  42. public:
  43. typedef SFXStream Parent;
  44. protected:
  45. ///
  46. SFXFormat mFormat;
  47. /// Total number of samples in the stream. If this is U32_MAX, the stream
  48. /// is considered to be of indefinite size.
  49. U32 mNumSamplesTotal;
  50. /// Number of samples left to be read from stream. Locked to U32_MAX for
  51. /// stream of indefinite size.
  52. U32 mNumSamplesLeft;
  53. /// The current sample data packet.
  54. RawData* mCurrentPacket;
  55. /// Read offset in the current sample data packet.
  56. U32 mCurrentPacketOffset;
  57. public:
  58. ///
  59. SFXMemoryStream( const SFXFormat& format, SourceStreamType* stream, U32 numSamples = U32_MAX );
  60. // SFXStream.
  61. const SFXFormat& getFormat() const { return mFormat; }
  62. U32 getSampleCount() const { return mNumSamplesTotal; }
  63. U32 getDataLength() const { return ( mNumSamplesTotal == U32_MAX ? U32_MAX : mFormat.getDataLength( getDuration() ) ); }
  64. U32 getDuration() const { return ( mNumSamplesTotal == U32_MAX ? U32_MAX : mFormat.getDuration( mNumSamplesTotal ) ); }
  65. bool isEOS() const { return ( mNumSamplesLeft != 0 ); }
  66. void reset();
  67. U32 read( U8 *buffer, U32 length );
  68. };
  69. #endif // !_SFXMEMORYSTREAM_H_