PTLib
Version 2.14.3
|
A class representing a sound. More...
#include <sound.h>
Public Member Functions | |
Construction | |
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. More... | |
PSound (const PFilePath &filename) | |
Create a new sound, reading from a platform dependent file. More... | |
PSound & | operator= (const PBYTEArray &data) |
Set new data bytes for the sound. More... | |
File functions | |
PBoolean | Load (const PFilePath &filename) |
Load a platform dependent sound file (eg .WAV file for Win32) into the object. More... | |
PBoolean | Save (const PFilePath &filename) |
Save a platform dependent sound file (eg .WAV file for Win32) from the object. More... | |
Access functions | |
PBoolean | Play () |
Play the sound on the default sound device. More... | |
PBoolean | Play (const PString &device) |
Play the sound to the specified sound device. More... | |
void | SetFormat (unsigned numChannels, unsigned sampleRate, unsigned bitsPerSample) |
Set the internal sound format to linear PCM at the specification in the parameters. More... | |
unsigned | GetEncoding () const |
Get the current encoding. More... | |
unsigned | GetChannels () const |
Get the number of channels (mono/stereo) in the sound. More... | |
unsigned | GetSampleRate () const |
Get the sample rate in samples per second. More... | |
unsigned | GetSampleSize () const |
Get the sample size in bits per sample. More... | |
DWORD | GetErrorCode () const |
Get the platform dependent error code from the last file load. More... | |
PINDEX | GetFormatInfoSize () const |
Get the size of the platform dependent format info. More... | |
const void * | GetFormatInfoData () const |
Get pointer to the platform dependent format info. More... | |
![]() | |
template<typename T > | |
const T & | GetAs (PINDEX offset=0) |
Function to cast block of memory in PBYTEArray to another structure. More... | |
PBYTEArray (PINDEX initialSize=0) | |
Construct a new dynamic array of unsigned chars. More... | |
PBYTEArray (BYTE const *buffer, PINDEX length, PBoolean dynamic=true) | |
Construct a new dynamic array of unsigned chars. More... | |
PBYTEArray (PContainerReference &reference_) | |
virtual void | PrintOn (ostream &strm) const |
Print the array. More... | |
virtual void | ReadFrom (istream &strm) |
Read the array. More... | |
virtual PObject * | Clone () const |
Clone the object. More... | |
![]() | |
PBaseArray (PINDEX initialSize=0) | |
Construct a new dynamic array of elements of the specified type. More... | |
PBaseArray (BYTEconst *buffer, PINDEX length, PBoolean dynamic=true) | |
Construct a new dynamic array of elements of the specified type. More... | |
PBoolean | SetAt (PINDEX index, BYTEval) |
Set the specific element in the array. More... | |
BYTE | GetAt (PINDEX index) const |
Get a value from the array. More... | |
void | Attach (const BYTE *buffer, PINDEX bufferSize) |
Attach a pointer to a static block to the base array type. More... | |
BYTE * | GetPointer (PINDEX minSize=0) |
Get a pointer to the internal array and assure that it is of at least the specified size. More... | |
BYTE | operator[] (PINDEX index) const |
Get a value from the array. More... | |
BYTE & | operator[] (PINDEX index) |
Get a reference to value from the array. More... | |
operator BYTEconst * () const | |
Get a pointer to the internal array. More... | |
PBoolean | Concatenate (const PBaseArray &array) |
Concatenate one array to the end of this array. More... | |
![]() | |
PAbstractArray (PINDEX elementSizeInBytes, PINDEX initialSize=0) | |
Create a new dynamic array of initalSize elements of elementSizeInBytes bytes each. More... | |
PAbstractArray (PINDEX elementSizeInBytes, const void *buffer, PINDEX bufferSizeInElements, PBoolean dynamicAllocation) | |
Create a new dynamic array of bufferSizeInElements elements of elementSizeInBytes bytes each. More... | |
virtual Comparison | Compare (const PObject &obj) const |
Get the relative rank of the two arrays. More... | |
virtual PBoolean | SetSize (PINDEX newSize) |
Set the size of the array in elements. More... | |
void | Attach (const void *buffer, PINDEX bufferSize) |
Attach a pointer to a static block to the base array type. More... | |
void * | GetPointer (PINDEX minSize=1) |
Get a pointer to the internal array and assure that it is of at least the specified size. More... | |
PBoolean | Concatenate (const PAbstractArray &array) |
Concatenate one array to the end of this array. More... | |
![]() | |
PContainer (PINDEX initialSize=0) | |
Create a new unique container. More... | |
PContainer (const PContainer &cont) | |
Create a new refernce to container. More... | |
PContainer & | operator= (const PContainer &cont) |
Assign one container reference to another. More... | |
virtual | ~PContainer () |
Destroy the container class. More... | |
virtual PINDEX | GetSize () const |
Get the current size of the container. More... | |
__inline size_t | size () const |
PBoolean | SetMinSize (PINDEX minSize) |
Set the minimum size of container. More... | |
virtual PBoolean | IsEmpty () const |
Determine if the container is empty. More... | |
__inline bool | empty () const |
PBoolean | IsUnique () const |
Determine if container is unique reference. More... | |
virtual PBoolean | MakeUnique () |
Make this instance to be the one and only reference to the container contents. More... | |
![]() | |
unsigned | GetTraceContextIdentifier () const |
Get PTRACE context identifier. More... | |
void | SetTraceContextIdentifier (unsigned id) |
void | GetTraceContextIdentifier (PObject &obj) |
void | GetTraceContextIdentifier (PObject *obj) |
void | SetTraceContextIdentifier (const PObject &obj) |
void | SetTraceContextIdentifier (const PObject *obj) |
virtual | ~PObject () |
template<class CLS > | |
CLS * | CloneAs () const |
As for Clone() but converts to specified type. More... | |
virtual PINDEX | HashFunction () const |
This function yields a hash value required by the PDictionary class. More... | |
virtual const char * | GetClass (unsigned ancestor=0) const |
Get the current dynamic type of the object instance. More... | |
PBoolean | IsClass (const char *cls) const |
virtual PBoolean | InternalIsDescendant (const char *clsName) const |
Determine if the dynamic type of the current instance is a descendent of the specified class. More... | |
__inline const PObject * | PTraceObjectInstance () const |
virtual Comparison | CompareObjectMemoryDirect (const PObject &obj) const |
Determine the byte wise comparison of two objects. More... | |
bool | operator== (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator!= (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator< (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator> (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator<= (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator>= (const PObject &obj) const |
Compare the two objects. More... | |
Static Public Member Functions | |
Miscellaneous functions | |
static PBoolean | PlayFile (const PFilePath &file, PBoolean wait=true) |
Play a sound file to the default device. More... | |
static void | Beep () |
Play the "standard" warning beep for the platform. More... | |
Protected Attributes | |
unsigned | encoding |
Format code. More... | |
unsigned | numChannels |
Number of channels eg mono/stereo. More... | |
unsigned | sampleRate |
Samples per second. More... | |
unsigned | sampleSize |
Number of bits per sample. More... | |
DWORD | dwLastError |
Last error code for Load()/Save() functions. More... | |
PBYTEArray | formatInfo |
Full info on the format (platform dependent) More... | |
Additional Inherited Members | |
![]() | |
enum | Comparison { LessThan = -1, EqualTo = 0, GreaterThan = 1 } |
Result of the comparison operation performed by the Compare() function. More... | |
![]() | |
PBaseArray (PContainerReference &reference_) | |
virtual void | PrintElementOn (ostream &stream, PINDEX index) const |
![]() |
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.
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.
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.
filename | Sound file to load. |
|
static |
Play the "standard" warning beep for the platform.
|
inline |
Get the number of channels (mono/stereo) in the sound.
References numChannels.
|
inline |
Get the current encoding.
A value of 0 indicates linear PCM, any other value is platform dependent.
References encoding.
|
inline |
Get the platform dependent error code from the last file load.
References dwLastError.
|
inline |
Get pointer to the platform dependent format info.
References formatInfo.
|
inline |
Get the size of the platform dependent format info.
References formatInfo, and PContainer::GetSize().
|
inline |
Get the sample rate in samples per second.
References sampleRate.
|
inline |
Get the sample size in bits per sample.
References sampleSize.
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.
filename | Sound file to load. |
PSound& PSound::operator= | ( | const PBYTEArray & | data | ) |
Set new data bytes for the sound.
data | New data for sound |
PBoolean PSound::Play | ( | ) |
Play the sound on the default sound device.
Play a sound file to the default device.
If the wait
parameter is true then the function does not return until the file has been played. If false then the sound play is begun asynchronously and the function returns immediately.
file | Sound file to play. |
wait | Flag to play sound synchronously. |
Save a platform dependent sound file (eg .WAV file for Win32) from the object.
filename | Sound file to load. |
void PSound::SetFormat | ( | unsigned | numChannels, |
unsigned | sampleRate, | ||
unsigned | bitsPerSample | ||
) |
Set the internal sound format to linear PCM at the specification in the parameters.
numChannels | Number of channels eg mono/stereo |
sampleRate | Samples per second |
bitsPerSample | Number of bits per sample |
|
protected |
Last error code for Load()/Save() functions.
Referenced by GetErrorCode().
|
protected |
Format code.
Referenced by GetEncoding().
|
protected |
Full info on the format (platform dependent)
Referenced by GetFormatInfoData(), and GetFormatInfoSize().
|
protected |
Number of channels eg mono/stereo.
Referenced by GetChannels().
|
protected |
Samples per second.
Referenced by GetSampleRate().
|
protected |
Number of bits per sample.
Referenced by GetSampleSize().