Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Examples

WAVFile Class Reference

A wrapper for opening and playing a WAV file using SDL. More...

#include <sdlwavfile.h>

Collaboration diagram for WAVFile:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 WAVFile (const std::string &file, int volume=SDL_MIX_MAXVOLUME)
 Constructor will load the wav file from disk into sound and initialise the data members.

 ~WAVFile ()
 Destructor will free the memory used by the sound buffer.

void setVolume (int newVol=SDL_MIX_MAXVOLUME)
 Change the volume.

void play (bool repeat=false)
 Commence playing this WAV file on the audio stream.

void open ()
 Open a connection to the audio device - only one WAVFile can be connected at once (the most recent connection will preempt any others).

void stop ()
 Stop playing this WAVFile and close all connections to the audio device.

void pause ()
 Pause the playing of all WAVFile s (so that they may subsequently be resumed() d.

void resume ()
 Restart the playing of the WAVFile currently connected to the audio device.


Protected Member Functions

void fill (Uint8 *stream, int len)
 SDL will [indirectly] call this to fill its audio buffer, and this function will then fill it.

void lock ()
 Increment the synchronised function call depth, locking if it is the first.

void unlock ()
 Decrement the synchronised function call depth, unlocking if it is the last.


Protected Attributes

SDL_AudioSpec spec
 SDL Specification for the WAV.

Uint8 * sound
 The (entire) WAV file, buffered.

Uint32 slen
 The length of the WAV file buffer.

int spos
 The current pointer offset in sound.

bool once
 if false, the playing will repeat/loop

bool nomore
 if true, the next fill() will call stop()

int vol
 The current volume in [0, SDL_MIX_MAXVOLUME].

int locks
 The number of locks (synchronised fn call depth).


Private Member Functions

 WAVFile (const WAVFile &)
 No copying.


Friends

void fillerup (void *, Uint8 *, int)
 Callback for when the SDL Audio device needs more data.


Detailed Description

A wrapper for opening and playing a WAV file using SDL.

Any number of WAVFile s may be created, for any number (or the same) WAV files. However, only one can be playing at once (this is a limitation of SDL). When another file starts playing - playback of the other WAV will be stopped. To resume, it must be play() ed again.

Examples:

sdlplay.cc.

Definition at line 34 of file sdlwavfile.h.


Constructor & Destructor Documentation

WAVFile::WAVFile const WAVFile  )  [private]
 

No copying.

WAVFile::WAVFile const std::string &  file,
int  volume = SDL_MIX_MAXVOLUME
 

Constructor will load the wav file from disk into sound and initialise the data members.

Parameters:
file The wav file to load
volume The initial volume to use
Exceptions:
SoundException if SDL could not load the wav file

Definition at line 47 of file sdlwavfile.cc.

References SDL_AudioSpec::callback, fillerup(), lock(), SDL_LoadWAV, setVolume(), slen, sound, spec, unlock(), and SDL_AudioSpec::userdata.

Here is the call graph for this function:

WAVFile::~WAVFile  ) 
 

Destructor will free the memory used by the sound buffer.

Definition at line 106 of file sdlwavfile.cc.

References lock(), SDL_FreeWAV(), sound, and unlock().

Here is the call graph for this function:


Member Function Documentation

void WAVFile::fill Uint8 *  stream,
int  len
[protected]
 

SDL will [indirectly] call this to fill its audio buffer, and this function will then fill it.

Parameters:
stream SDL's audio buffer to fill
len the length of the buffer

Definition at line 76 of file sdlwavfile.cc.

References nomore, once, SDL_MixAudio(), slen, sound, spos, stop(), and vol.

Here is the call graph for this function:

void WAVFile::lock  )  [protected]
 

Increment the synchronised function call depth, locking if it is the first.

Definition at line 63 of file sdlwavfile.cc.

References locks, and SDL_LockAudio().

Referenced by open(), pause(), play(), resume(), stop(), WAVFile(), and ~WAVFile().

Here is the call graph for this function:

void WAVFile::open  ) 
 

Open a connection to the audio device - only one WAVFile can be connected at once (the most recent connection will preempt any others).

This can be used to resume a file, if it was interrupted by playing another wav, otherwise just play() works.

Exceptions:
SoundException if the connection failed

Definition at line 124 of file sdlwavfile.cc.

References lock(), SDL_OpenAudio(), spec, stop(), and unlock().

Referenced by play().

Here is the call graph for this function:

void WAVFile::pause  ) 
 

Pause the playing of all WAVFile s (so that they may subsequently be resumed() d.

Examples:
sdlplay.cc.

Definition at line 142 of file sdlwavfile.cc.

References lock(), SDL_PauseAudio(), and unlock().

Here is the call graph for this function:

void WAVFile::play bool  repeat = false  ) 
 

Commence playing this WAV file on the audio stream.

Parameters:
repeat if true, the playing will loop indefinitely until a stop() [or pause()]
Examples:
sdlplay.cc.

Definition at line 116 of file sdlwavfile.cc.

References lock(), once, open(), resume(), and unlock().

Here is the call graph for this function:

void WAVFile::resume  ) 
 

Restart the playing of the WAVFile currently connected to the audio device.

Examples:
sdlplay.cc.

Definition at line 148 of file sdlwavfile.cc.

References lock(), SDL_PauseAudio(), and unlock().

Referenced by play().

Here is the call graph for this function:

void WAVFile::setVolume int  newVol = SDL_MIX_MAXVOLUME  ) 
 

Change the volume.

Parameters:
newVol the new volume - will be clipped to the range [0, SDL_MIX_MAXVOLUME]
Examples:
sdlplay.cc.

Definition at line 112 of file sdlwavfile.cc.

References SDL_MIX_MAXVOLUME, and vol.

Referenced by WAVFile().

void WAVFile::stop  ) 
 

Stop playing this WAVFile and close all connections to the audio device.

Examples:
sdlplay.cc.

Definition at line 134 of file sdlwavfile.cc.

References lock(), nomore, SDL_CloseAudio(), spos, and unlock().

Referenced by fill(), and open().

Here is the call graph for this function:

void WAVFile::unlock  )  [protected]
 

Decrement the synchronised function call depth, unlocking if it is the last.

Definition at line 69 of file sdlwavfile.cc.

References locks, and SDL_UnlockAudio().

Referenced by open(), pause(), play(), resume(), stop(), WAVFile(), and ~WAVFile().

Here is the call graph for this function:


Friends And Related Function Documentation

void fillerup void *  wavfile,
Uint8 *  stream,
int  len
[friend]
 

Callback for when the SDL Audio device needs more data.

This is called by SDL automatically.

Definition at line 43 of file sdlwavfile.cc.


Member Data Documentation

int WAVFile::locks [protected]
 

The number of locks (synchronised fn call depth).

Definition at line 46 of file sdlwavfile.h.

Referenced by lock(), and unlock().

bool WAVFile::nomore [protected]
 

if true, the next fill() will call stop()

Definition at line 44 of file sdlwavfile.h.

Referenced by fill(), and stop().

bool WAVFile::once [protected]
 

if false, the playing will repeat/loop

Definition at line 43 of file sdlwavfile.h.

Referenced by fill(), and play().

Uint32 WAVFile::slen [protected]
 

The length of the WAV file buffer.

Definition at line 41 of file sdlwavfile.h.

Referenced by fill(), and WAVFile().

Uint8* WAVFile::sound [protected]
 

The (entire) WAV file, buffered.

Definition at line 40 of file sdlwavfile.h.

Referenced by fill(), WAVFile(), and ~WAVFile().

SDL_AudioSpec WAVFile::spec [protected]
 

SDL Specification for the WAV.

Definition at line 39 of file sdlwavfile.h.

Referenced by open(), and WAVFile().

int WAVFile::spos [protected]
 

The current pointer offset in sound.

Definition at line 42 of file sdlwavfile.h.

Referenced by fill(), and stop().

int WAVFile::vol [protected]
 

The current volume in [0, SDL_MIX_MAXVOLUME].

Definition at line 45 of file sdlwavfile.h.

Referenced by fill(), and setVolume().


The documentation for this class was generated from the following files:
Generated on Fri Oct 3 18:41:22 2003 for taptedDevTools by doxygen 1.3.4