Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Audio::SimpleSound Class Reference

#include <SimpleSound.h>

Inheritance diagram for Audio::SimpleSound:
Audio::Sound Audio::OpenALSimpleSound Audio::OpenALStreamingSound

Public Member Functions

virtual ~SimpleSound ()
 
VSFileSystem::VSFileType getType () const
 
- Public Member Functions inherited from Audio::Sound
virtual ~Sound ()
 
const std::string & getName () const throw ()
 
const FormatgetFormat () const throw ()
 
bool isLoaded () const throw ()
 
bool isLoading () const throw ()
 
bool isStreaming () const throw ()
 
void load (bool wait=true) throw (Exception)
 
void unload () throw ()
 

Protected Member Functions

 SimpleSound (const std::string &name, VSFileSystem::VSFileType type=VSFileSystem::UnknownFile, bool streaming=false) throw ()
 
bool isStreamLoaded () const
 
void loadStream () throw (Exception)
 
void closeStream () throw (ResourceNotLoadedException)
 
SharedPtr< StreamgetStream () const throw (ResourceNotLoadedException)
 
void readBuffer (SoundBuffer &buffer) throw (Exception)
 
virtual void abortLoad () throw ()
 
- Protected Member Functions inherited from Audio::Sound
 Sound (const std::string &name, bool streaming) throw ()
 
FormatgetFormat () throw ()
 
virtual void onLoaded (bool success) throw ()
 
virtual void waitLoad () throw (Exception)
 
virtual void loadImpl (bool wait)=0 throw (Exception)
 
virtual void unloadImpl ()=0 throw ()
 

Additional Inherited Members

- Protected Attributes inherited from Audio::Sound
struct Audio::Sound::Flags flags
 

Detailed Description

Simple Sound abstract class

Remarks
This partial implementation implements foreground loading of files using the codec registry.
No background loading is implemented, meaning all requests for load,
even with wait=false, are processed in the foreground.
There's a possibility for streaming given the packetized pulling
architecture. Renderers are not required to pull all packets from the stream, and access to the Stream object is also provided for seeking back and forth.
Renderers still have to override (un)loadImpl() and abortLoad().
This refinement merely adds supporting methods for implementing them.
See Also
Sound, BackgroundLoadingSound

Definition at line 35 of file SimpleSound.h.

Constructor & Destructor Documentation

Audio::SimpleSound::SimpleSound ( const std::string &  name,
VSFileSystem::VSFileType  type = VSFileSystem::UnknownFile,
bool  streaming = false 
)
throw (
)
protected

Internal constructor used by derived classes

Definition at line 13 of file SimpleSound.cpp.

15  : Sound(name, streaming),
16  type(_type)
17  {
18  }
Audio::SimpleSound::~SimpleSound ( )
virtual

Definition at line 20 of file SimpleSound.cpp.

21  {
22  }

Member Function Documentation

void Audio::SimpleSound::abortLoad ( )
throw (
)
protectedvirtual

Abort an in-progress background load procedure

Note
Although no exceptions should be risen, the abort request may not be carried out for various reasons. The caller should check that on return by calling isLoaded() / isLoading().

Implements Audio::Sound.

Definition at line 83 of file SimpleSound.cpp.

85  {
86  // Intentionally blank
87  }
void Audio::SimpleSound::closeStream ( )
throw (ResourceNotLoadedException
)
protected

Uninitialize the stream

Remarks
Calling this when isStreamLoaded() returns false will raise an ResourceNotLoadedException.

Definition at line 42 of file SimpleSound.cpp.

References isStreamLoaded().

44  {
45  if (!isStreamLoaded())
46  throw(ResourceNotLoadedException());
47  stream.reset();
48  }
SharedPtr< Stream > Audio::SimpleSound::getStream ( ) const
throw (ResourceNotLoadedException
)
protected

Get a pointer to the stream

Remarks
Calling this when isStreamLoaded() returns false will raise an ResourceNotLoadedException.

Definition at line 50 of file SimpleSound.cpp.

References isStreamLoaded().

Referenced by loadStream().

52  {
53  if (!isStreamLoaded())
54  throw(ResourceNotLoadedException());
55  return stream;
56  }
VSFileSystem::VSFileType Audio::SimpleSound::getType ( ) const
inline

VSFileSystem File type

Definition at line 49 of file SimpleSound.h.

Referenced by loadStream().

49 { return type; }
bool Audio::SimpleSound::isStreamLoaded ( ) const
inlineprotected

Do we have an open stream?

Definition at line 57 of file SimpleSound.h.

Referenced by closeStream(), getStream(), and loadStream().

57 { return stream.get() != 0; }
void Audio::SimpleSound::loadStream ( )
throw (Exception
)
protected

Initialize the stream.

Remarks
Calling this when the stream has already been initialized will raise an ReasourceAlreadyLoadedException.

Definition at line 24 of file SimpleSound.cpp.

References Audio::Sound::getFormat(), Audio::Sound::getName(), Singleton< CodecRegistry >::getSingleton(), getStream(), getType(), and isStreamLoaded().

26  {
27  if (isStreamLoaded())
28  throw(ResourceAlreadyLoadedException());
29 
30  // Open stream and initialize shared pointer
31  stream.reset(
33  getName(),
34  getType()
35  )
36  );
37 
38  // Copy format
39  getFormat() = getStream()->getFormat();
40  }
void Audio::SimpleSound::readBuffer ( SoundBuffer buffer)
throw (Exception
)
protected

Read from the stream into the buffer

Remarks
Will throw EndOfStreamException when the end of the stream is reached. Any other exception is probably fatal.

Definition at line 58 of file SimpleSound.cpp.

References buffer.

60  {
61  if (buffer.getFormat() == getFormat()) {
62  // Same formats, so all we have to do is read bytes ;)
63  buffer.setUsedBytes(
64  getStream()->read( buffer.getBuffer(), buffer.getByteCapacity() )
65  );
66  } else {
67  // Save the buffer format, we'll have to reformat to this format
68  Format targetFormat = buffer.getFormat();
69 
70  // Set buffer format to stream format
71  buffer.setFormat(getFormat());
72 
73  // Now read bytes from the stream
74  buffer.setUsedBytes(
75  getStream()->read( buffer.getBuffer(), buffer.getByteCapacity() )
76  );
77 
78  // Finally we have to reformat the buffer back to the original format
79  buffer.reformat(targetFormat);
80  }
81  }

The documentation for this class was generated from the following files: