# PSound Class Reference

A class representing a sound. More...

`#include <sound.h>`

Inheritance diagram for PSound:

List of all members.

## 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.
| PSound (const PFilePath &filename)
| Create a new sound, reading from a platform dependent file.
PSound & | operator= (const PBYTEArray &data)
| Set new data bytes for the sound.
File functions
PBoolean | Load (const PFilePath &filename)
| Load a platform dependent sound file (eg .WAV file for Win32) into the object.
PBoolean | Save (const PFilePath &filename)
| Save a platform dependent sound file (eg .WAV file for Win32) from the object.
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)
| Set the internal sound format to linear PCM at the specification in the parameters.
unsigned | GetEncoding () const
| Get the current encoding.
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=true)
| Play a sound file to the default device.
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

static void PSound::Beep | ( |  | ) | `[static]`

Play the "standard" warning beep for the platform.

unsigned PSound::GetChannels | ( |  | ) | const`[inline]`

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

unsigned PSound::GetEncoding | ( |  | ) | const`[inline]`

Get the current encoding.

A value of 0 indicates linear PCM, any other value is platform dependent.

DWORD PSound::GetErrorCode | ( |  | ) | const`[inline]`

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

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

Get pointer to the platform dependent format info.

PINDEX PSound::GetFormatInfoSize | ( |  | ) | const`[inline]`

Get the size of the platform dependent format info.

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.

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:
  true if the sound is loaded successfully.

Parameters:

  filename | Sound file to load.

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

Set new data bytes for the sound.

Parameters:

  data | New data for sound

PBoolean PSound::Play | ( | const PString & | device | ) |

Play the sound to the specified sound device.

PBoolean PSound::Play | ( |  | ) |

Play the sound on the default sound device.

static PBoolean PSound::PlayFile | ( | const PFilePath & | file,
|  | PBoolean | wait = `true` |
| ) |  |  | `[static]`

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.

Returns:
  true if the sound is playing or has played.

Parameters:

  file | Sound file to play.
  wait | Flag to play sound synchronously.

PBoolean PSound::Save | ( | const PFilePath & | filename | ) |

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

Returns:
  true if the sound is saved successfully.

Parameters:

  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.

Parameters:

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

## Member Data Documentation

DWORD PSound::dwLastError `[protected]`

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

unsigned PSound::encoding `[protected]`

Format code.

PBYTEArray PSound::formatInfo `[protected]`

Full info on the format (platform dependent).

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.

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

- sound.h