Torque3D Documentation / _generateds / sfxFileStream.h

sfxFileStream.h

Engine/source/sfx/sfxFileStream.h

More...

Classes:

class

An SFXStream that streams from a file.

Public Typedefs

SFXFILESTREAM_CREATE_FN )(Stream *stream)

Detailed Description

Public Typedefs

typedef SFXFileStream *(* SFXFILESTREAM_CREATE_FN )(Stream *stream)
  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 _SFXFILESTREAM_H_
 25#define _SFXFILESTREAM_H_
 26
 27#ifndef _SFXSTREAM_H_
 28#  include "sfx/sfxStream.h"
 29#endif
 30#ifndef _TVECTOR_H_
 31#  include "core/util/tVector.h"
 32#endif
 33#ifndef _TORQUE_STRING_H_
 34#  include "core/util/str.h"
 35#endif
 36
 37
 38class Stream;
 39class SFXFileStream;
 40
 41///
 42typedef SFXFileStream* ( *SFXFILESTREAM_CREATE_FN )( Stream *stream );
 43
 44/// An SFXStream that streams from a file.
 45class SFXFileStream : public SFXStream
 46{
 47   protected:
 48      typedef Vector< String> ExtensionsVector;
 49      typedef Vector< SFXFILESTREAM_CREATE_FN> CreateFnsVector;
 50
 51      static ExtensionsVector smExtensions;
 52      static CreateFnsVector smCreateFns;
 53
 54      /// The file stream we're reading from.
 55      Stream *mStream;
 56
 57      /// If true then we're responsible for closing the stream.
 58      bool mOwnStream;
 59
 60      /// The format of the data in the stream.
 61      SFXFormat mFormat;    
 62
 63      /// The number of samples in the data stream.
 64      U32 mSamples;
 65
 66      /// Constructs the stream in an uninitilized state.
 67      SFXFileStream();
 68
 69      ///
 70      SFXFileStream( const SFXFileStream& cloneFrom );
 71
 72      /// Overloaded in the derived classes to read 
 73      /// the file header.  It should initialize 
 74      /// mFormat and mSamples.
 75      virtual bool _readHeader() = 0;
 76
 77      /// Overloaded for cleanup of file format 
 78      /// specific structures.
 79      virtual void _close() = 0;
 80
 81   public:
 82
 83      ///
 84      static void registerExtension( String ext, SFXFILESTREAM_CREATE_FN create_fn );
 85
 86      ///
 87      static void unregisterExtension( String ext );
 88   
 89      /// This is a helper function used to create an appropriate SFXStream
 90      /// for the requested sound file.
 91      ///
 92      /// @param filename The sound file path with or without extension.
 93      ///
 94      static SFXFileStream* create( String filename );
 95
 96      ///
 97      static bool exists( String filename );
 98
 99      /// Destructor.
100      virtual ~SFXFileStream();
101
102      /// Opens and optionally takes ownership of the stream.
103      bool open( Stream *stream, bool ownStream = false );
104
105      /// Closes the stream.
106      void close();
107
108      // SFXStream.
109      const SFXFormat& getFormat() const { return mFormat; }
110      U32 getSampleCount() const { return mSamples; }
111      U32 getDataLength() const { return mSamples * mFormat.getBytesPerSample(); }
112      U32 getDuration() const { return mFormat.getDuration( mSamples ); }
113      bool isEOS() const;
114};
115
116#endif // _SFXFILESTREAM_H_
117