Torque3D Documentation / _generateds / sfxMemoryStream.h

sfxMemoryStream.h

Engine/source/sfx/sfxMemoryStream.h

More...

Classes:

class

A stream filter that converts sample packets from its source stream to a continuous sample stream.

Detailed Description

 1
 2//-----------------------------------------------------------------------------
 3// Copyright (c) 2012 GarageGames, LLC
 4//
 5// Permission is hereby granted, free of charge, to any person obtaining a copy
 6// of this software and associated documentation files (the "Software"), to
 7// deal in the Software without restriction, including without limitation the
 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 9// sell copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21// IN THE SOFTWARE.
22//-----------------------------------------------------------------------------
23
24#ifndef _SFXMEMORYSTREAM_H_
25#define _SFXMEMORYSTREAM_H_
26
27#ifndef _SFXSTREAM_H_
28   #include "sfx/sfxStream.h"
29#endif
30#ifndef _TSTREAM_H_
31   #include "core/stream/tStream.h"
32#endif
33#ifndef _RAWDATA_H_
34   #include "core/util/rawData.h"
35#endif
36
37
38/// A stream filter that converts sample packets from its source stream
39/// to a continuous sample stream.  Useful for feeding sound from a source
40/// that pushes sample data in discrete packets.
41///
42/// @note For the SFXMemoryStream to allow a reset(), the source input
43///   stream must implement IResettable.
44class SFXMemoryStream : public SFXStream,
45                        public IInputStreamFilter< U8, IInputStream< RawData* >* >
46{
47   public:
48   
49      typedef SFXStream Parent;
50      
51   protected:
52   
53      ///
54      SFXFormat mFormat;
55   
56      /// Total number of samples in the stream.  If this is U32_MAX, the stream
57      /// is considered to be of indefinite size.
58      U32 mNumSamplesTotal;
59      
60      /// Number of samples left to be read from stream.  Locked to U32_MAX for
61      /// stream of indefinite size.
62      U32 mNumSamplesLeft;
63      
64      /// The current sample data packet.
65      RawData* mCurrentPacket;
66      
67      /// Read offset in the current sample data packet.
68      U32 mCurrentPacketOffset;
69         
70   public:
71   
72      ///
73      SFXMemoryStream( const SFXFormat& format, SourceStreamType* stream, U32 numSamples = U32_MAX );
74      
75      // SFXStream.
76      const SFXFormat& getFormat() const { return mFormat; }
77      U32 getSampleCount() const { return mNumSamplesTotal; }
78      U32 getDataLength() const { return ( mNumSamplesTotal == U32_MAX ? U32_MAX : mFormat.getDataLength( getDuration() ) ); }
79      U32 getDuration() const { return ( mNumSamplesTotal == U32_MAX ? U32_MAX : mFormat.getDuration( mNumSamplesTotal ) ); }
80      bool isEOS() const { return ( mNumSamplesLeft != 0 ); }
81      void reset();
82      U32 read( U8 *buffer, U32 length );      
83};
84
85#endif // !_SFXMEMORYSTREAM_H_
86