PSound Class Reference

#include <sound.h>

Inheritance diagram for PSound:

PBYTEArray PBaseArray< T > PAbstractArray PContainer PObject List of all members.

Construction

 PSound (unsigned numChannels=1, unsigned sampleRate=8000, unsigned bitsPerSample=16, PINDEX bufferSize=0, const BYTE *data=NULL)
 PSound (const PFilePath &filename)
PSoundoperator= (const PBYTEArray &data)

Public Member Functions

File functions
PBoolean Load (const PFilePath &filename)
PBoolean Save (const PFilePath &filename)
Access functions
PBoolean Play ()
 Play the sound on the default sound device.
PBoolean Play (const PString &device)
 Play the sound to the specified sound device.
void SetFormat (unsigned numChannels, unsigned sampleRate, unsigned bitsPerSample)
unsigned GetEncoding () const
unsigned GetChannels () const
 Get the number of channels (mono/stereo) in the sound.
unsigned GetSampleRate () const
 Get the sample rate in samples per second.
unsigned GetSampleSize () const
 Get the sample size in bits per sample.
DWORD GetErrorCode () const
 Get the platform dependent error code from the last file load.
PINDEX GetFormatInfoSize () const
 Get the size of the platform dependent format info.
const void * GetFormatInfoData () const
 Get pointer to the platform dependent format info.

Static Public Member Functions

Miscellaneous functions
static PBoolean PlayFile (const PFilePath &file, PBoolean wait=PTrue)
static void Beep ()
 Play the "standard" warning beep for the platform.

Protected Attributes

unsigned encoding
 Format code.
unsigned numChannels
 Number of channels eg mono/stereo.
unsigned sampleRate
 Samples per second.
unsigned sampleSize
 Number of bits per sample.
DWORD dwLastError
 Last error code for Load()/Save() functions.
PBYTEArray formatInfo
 Full info on the format (platform dependent).

Detailed Description

A class representing a sound. A sound is a highly platform dependent entity that is abstracted for use here. Very little manipulation of the sounds are possible.

The most common sound to use is the static function Beep()# which emits the system standard "warning" or "attention" sound.


Constructor & Destructor Documentation

PSound::PSound ( unsigned  numChannels = 1,
unsigned  sampleRate = 8000,
unsigned  bitsPerSample = 16,
PINDEX  bufferSize = 0,
const BYTE *  data = NULL 
)

Create a new sound, using the parameters provided. It is expected that the "lowest common denominator" encoding, linear PCM, is used.

All other values for the encoding are platform dependent.

Parameters:
numChannels  Number of channels eg mono/stereo
sampleRate  Samples per second
bitsPerSample  Number of bits per sample
bufferSize  Size of data
data  Pointer to initial data

PSound::PSound ( const PFilePath filename  ) 

Create a new sound, reading from a platform dependent file.

Parameters:
filename  Sound file to load.


Member Function Documentation

PSound& PSound::operator= ( const PBYTEArray data  ) 

Set new data bytes for the sound.

Parameters:
data  New data for sound

PBoolean PSound::Load ( const PFilePath filename  ) 

Load a platform dependent sound file (eg .WAV file for Win32) into the object. Note the whole file must able to be loaded into memory.

Also note that not all possible files are playable by this library. No format conversions between file and driver are performed.

Returns:
PTrue if the sound is loaded successfully.
Parameters:
filename  Sound file to load.

PBoolean PSound::Save ( const PFilePath filename  ) 

Save a platform dependent sound file (eg .WAV file for Win32) from the object.

Returns:
PTrue if the sound is saved successfully.
Parameters:
filename  Sound file to load.

PBoolean PSound::Play (  ) 

Play the sound on the default sound device.

PBoolean PSound::Play ( const PString device  ) 

Play the sound to the specified sound device.

void PSound::SetFormat ( unsigned  numChannels,
unsigned  sampleRate,
unsigned  bitsPerSample 
)

Set the internal sound format to linear PCM at the specification in the parameters.

Parameters:
numChannels  Number of channels eg mono/stereo
sampleRate  Samples per second
bitsPerSample  Number of bits per sample

unsigned PSound::GetEncoding (  )  const [inline]

Get the current encoding. A value of 0 indicates linear PCM, any other value is platform dependent.

unsigned PSound::GetChannels (  )  const [inline]

Get the number of channels (mono/stereo) in the sound.

unsigned PSound::GetSampleRate (  )  const [inline]

Get the sample rate in samples per second.

unsigned PSound::GetSampleSize (  )  const [inline]

Get the sample size in bits per sample.

DWORD PSound::GetErrorCode (  )  const [inline]

Get the platform dependent error code from the last file load.

PINDEX PSound::GetFormatInfoSize (  )  const [inline]

Get the size of the platform dependent format info.

const void* PSound::GetFormatInfoData (  )  const [inline]

Get pointer to the platform dependent format info.

static PBoolean PSound::PlayFile ( const PFilePath file,
PBoolean  wait = PTrue 
) [static]

Play a sound file to the default device. If the wait# parameter is PTrue then the function does not return until the file has been played. If PFalse then the sound play is begun asynchronously and the function returns immediately.

Returns:
PTrue if the sound is playing or has played.
Parameters:
file  Sound file to play.
wait  Flag to play sound synchronously.

static void PSound::Beep (  )  [static]

Play the "standard" warning beep for the platform.


Member Data Documentation

unsigned PSound::encoding [protected]

Format code.

unsigned PSound::numChannels [protected]

Number of channels eg mono/stereo.

unsigned PSound::sampleRate [protected]

Samples per second.

unsigned PSound::sampleSize [protected]

Number of bits per sample.

DWORD PSound::dwLastError [protected]

Last error code for Load()/Save() functions.

PBYTEArray PSound::formatInfo [protected]

Full info on the format (platform dependent).


The documentation for this class was generated from the following file:
Generated on Mon Sep 15 01:21:38 2008 for PTLib by  doxygen 1.5.1