sfxResource.h

Engine/source/sfx/sfxResource.h

More...

Classes:

class

This is the base class for all sound file resources including streamed sound files.

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 _SFXRESOURCE_H_
 25#define _SFXRESOURCE_H_
 26
 27#ifndef _SFXCOMMON_H_
 28   #include "sfx/sfxCommon.h"
 29#endif
 30#ifndef __RESOURCE_H__
 31   #include "core/resource.h"
 32#endif
 33
 34
 35class SFXStream;
 36
 37
 38/// This is the base class for all sound file resources including
 39/// streamed sound files.  It acts much like an always in-core
 40/// header to the actual sound data which is read through an SFXStream.
 41///
 42/// The first step occurs at ResourceManager::load() time at which
 43/// only the header information, the format, size frequency, and 
 44/// looping flag, are loaded from the sound file.  This provides 
 45/// just the nessasary information to simulate sound playback for
 46/// sounds playing just out of the users hearing range.
 47/// 
 48/// The second step loads the actual sound data or begins filling
 49/// the stream buffer.  This is triggered by a call to openStream().
 50/// SFXProfile, for example, does this when mPreload is enabled.
 51///
 52class SFXResource
 53{
 54   public:
 55   
 56      typedef void Parent;
 57      
 58   protected:
 59
 60      /// The constructor is protected. 
 61      /// @see SFXResource::load()
 62      SFXResource();
 63
 64      /// Path to the sound file.
 65      String mFileName;
 66
 67      /// The format of the sample data.
 68      SFXFormat mFormat;
 69
 70      /// The length of the sample in milliseconds.
 71      U32 mDuration;
 72      
 73      /// Construct a resource instance for the given file.  Format and duration
 74      /// are read from the given stream.
 75      SFXResource( String fileName, SFXStream* stream );
 76      
 77   public:
 78
 79      /// The destructor.
 80      virtual ~SFXResource() {}
 81
 82      /// This is a helper function used by SFXProfile for load
 83      /// a sound resource.  It takes care of trying different 
 84      /// types for extension-less filenames.
 85      ///
 86      /// @param filename The sound file path with or without extension.
 87      ///
 88      static Resource< SFXResource> load( String filename );
 89
 90      /// A helper function which returns true if the 
 91      /// sound resource exists.
 92      ///
 93      /// @param filename The sound file path with or without extension.
 94      ///
 95      static bool exists( String filename );
 96
 97      /// Return the path to the sound file.
 98      const String& getFileName() { return mFileName; }
 99
100      /// Returns the total playback time milliseconds.
101      U32 getDuration() const { return mDuration; }
102
103      /// The format of the data in the resource.
104      const SFXFormat& getFormat() const { return mFormat; }
105
106      /// Open a stream for reading the resource's sample data.
107      SFXStream* openStream();
108
109      // Internal.
110      struct _NewHelper;
111      friend struct _NewHelper;
112};
113
114
115#endif  // _SFXRESOURCE_H_
116