Logo Search packages:      
Sourcecode: pwlib version File versions  Download package

PSoundChannel Class Reference

#include <sound.h>

Inheritance diagram for PSoundChannel:

PChannel PObject

List of all members.

Detailed Description

This class is both an abstract class for a generalised sound channel, and an implementation of PSoundChannel for old code that is not plugin-aware. When instantiated, it selects the first plugin of the base class "PSoundChannel"

As an abstract class, this represents a sound schannel. Drivers for real, platform dependent sound hardware will be ancestors of this class and can be found in the plugins section of PWLib.

A sound driver is either playing or recording. If simultaneous playing and recording is desired, two instances of PSoundChannel must be created.

The sound is buffered and the size and number of buffers should be set before playing/recording. Each call to Write() will use one buffer, so care needs to be taken not to use a large number of small writes but tailor the buffers to the size of each write you make.

Similarly for reading, an entire buffer must be read before any of it is available to a Read() call. Note that once a buffer is filled you can read it a byte at a time if desired, but as soon as all the data in the buffer is used returned, the next read will wait until the entire next buffer is read from the hardware. So again, tailor the number and size of buffers to the application. To avoid being blocked until the buffer fills, you can use the StartRecording() function to initiate the buffer filling, and the IsRecordingBufferFull() function to determine when the Read() function will no longer block.

Note that this sound channel is implicitly a linear PCM channel. No data conversion is performed on data to/from the channel.

Definition at line 344 of file sound.h.

Channel set up functions

enum  { MaxVolume = 100 }
virtual BOOL GetBuffers (PINDEX &size, PINDEX &count)
virtual unsigned GetChannels () const
 Get the number of channels (mono/stereo) in the sound.
virtual unsigned GetSampleRate () const
 Get the sample rate in samples per second.
virtual unsigned GetSampleSize () const
 Get the sample size in bits per sample.
virtual BOOL GetVolume (unsigned &volume)
virtual BOOL SetBuffers (PINDEX size, PINDEX count=2)
virtual BOOL SetFormat (unsigned numChannels=1, unsigned sampleRate=8000, unsigned bitsPerSample=16)
virtual BOOL SetVolume (unsigned volume)

Comparison functions

enum  Comparison { LessThan = -1, EqualTo = 0, GreaterThan = 1 }
virtual Comparison CompareObjectMemoryDirect (const PObject &obj) const
bool operator!= (const PObject &obj) const
bool operator< (const PObject &obj) const
bool operator<= (const PObject &obj) const
bool operator== (const PObject &obj) const
bool operator> (const PObject &obj) const
bool operator>= (const PObject &obj) const


enum  Directions { Recorder, Player }
 PSoundChannel (const PString &device, Directions dir, unsigned numChannels=1, unsigned sampleRate=8000, unsigned bitsPerSample=16)
 PSoundChannel ()
 Create a sound channel.
virtual ~PSoundChannel ()

Error functions

enum  ErrorGroup { LastReadError, LastWriteError, LastGeneralError, NumErrorGroups }
enum  Errors {
  NoError, NotFound, FileExists, DiskFull,
  AccessDenied, DeviceInUse, BadParameter, NoMemory,
  NotOpen, Timeout, Interrupted, BufferTooSmall,
  Miscellaneous, ProtocolFailure, NumNormalisedErrors
Errors GetErrorCode (ErrorGroup group=NumErrorGroups) const
int GetErrorNumber (ErrorGroup group=NumErrorGroups) const
virtual PString GetErrorText (ErrorGroup group=NumErrorGroups) const
static PString GetErrorText (Errors lastError, int osError=0)

Miscellaneous functions

enum  ShutdownValue { ShutdownRead = 0, ShutdownWrite = 1, ShutdownReadAndWrite = 2 }
void AbortCommandString ()
virtual BOOL Close ()
BOOL SendCommandString (const PString &command)
BOOL SetBufferSize (PINDEX newSize)
virtual BOOL Shutdown (ShutdownValue option)

Scattered read/write functions

typedef std::vector< SliceVectorOfSlice
virtual BOOL Read (const VectorOfSlice &slices)
virtual BOOL Write (const VectorOfSlice &slices)

Open functions

virtual BOOL Abort ()
virtual int GetHandle () const
virtual BOOL IsOpen () const
virtual BOOL Open (const PString &device, Directions dir, unsigned numChannels=1, unsigned sampleRate=8000, unsigned bitsPerSample=16)
static PSoundChannelCreateChannel (const PString &driverName, PPluginManager *pluginMgr=NULL)
static PSoundChannelCreateChannelByName (const PString &deviceName, Directions direction, PPluginManager *pluginMgr=NULL)
static PSoundChannelCreateOpenedChannel (const PString &driverName, const PString &deviceName, Directions direction, unsigned numChannels=1, unsigned sampleRate=8000, unsigned bitsPerSample=16, PPluginManager *pluginMgr=NULL)
static PString GetDefaultDevice (Directions dir)
static PStringList GetDeviceNames (Directions direction, PPluginManager *pluginMgr=NULL)
static PStringList GetDeviceNames (const PString &driverName, Directions direction, PPluginManager *pluginMgr=NULL)
static PStringList GetDriverNames (PPluginManager *pluginMgr=NULL)
static PStringList GetDriversDeviceNames (const PString &driverName, Directions direction, PPluginManager *pluginMgr=NULL)

Run Time Type functions

virtual const char * GetClass (unsigned=0) const
virtual BOOL InternalIsDescendant (const char *clsName) const
BOOL IsClass (const char *cls) const
static const char * Class ()

I/O functions

virtual void PrintOn (ostream &strm) const
virtual void ReadFrom (istream &strm)
ostream & operator<< (ostream &strm, const PObject &obj)
istream & operator>> (istream &strm, PObject &obj)

Public Types

enum  PXBlockType { PXReadBlock, PXWriteBlock, PXAcceptBlock, PXConnectBlock }

Public Member Functions

Record functions
virtual BOOL AreAllRecordBuffersFull ()
PINDEX GetLastReadCount () const
virtual BOOL IsRecordBufferFull ()
virtual BOOL Read (void *buf, PINDEX len)
virtual BOOL RecordFile (const PFilePath &file)
virtual BOOL RecordSound (PSound &sound)
virtual BOOL StartRecording ()
virtual BOOL WaitForAllRecordBuffersFull ()
virtual BOOL WaitForRecordBufferFull ()
Miscellaneous functions
virtual PObjectClone () const
Overrides from class PObject
virtual Comparison Compare (const PObject &obj) const
virtual PINDEX HashFunction () const
Information functions
virtual PChannelGetBaseReadChannel () const
virtual PChannelGetBaseWriteChannel () const
virtual PString GetName () const
Play functions
PINDEX GetLastWriteCount () const
virtual BOOL HasPlayCompleted ()
virtual BOOL PlayFile (const PFilePath &file, BOOL wait=TRUE)
virtual BOOL PlaySound (const PSound &sound, BOOL wait=TRUE)
virtual BOOL WaitForPlayCompletion ()
virtual BOOL Write (const void *buf, PINDEX len)
Reading functions
PTimeInterval GetReadTimeout () const
virtual void OnReadComplete (void *buf, PINDEX len)
virtual BOOL ReadAsync (void *buf, PINDEX len)
BOOL ReadBlock (void *buf, PINDEX len)
virtual int ReadChar ()
PString ReadString (PINDEX len)
void SetReadTimeout (const PTimeInterval &time)
Writing functions
PTimeInterval GetWriteTimeout () const
virtual void OnWriteComplete (const void *buf, PINDEX len)
void SetWriteTimeout (const PTimeInterval &time)
virtual BOOL WriteAsync (const void *buf, PINDEX len)
BOOL WriteChar (int c)
BOOL WriteString (const PString &str)

Static Public Member Functions

static BOOL ConvertOSError (int libcReturnValue, Errors &lastError, int &osError)

Protected Member Functions

virtual BOOL ConvertOSError (int libcReturnValue, ErrorGroup group=LastGeneralError)
int PXClose ()
BOOL PXSetIOBlock (PXBlockType type, const PTimeInterval &timeout)
int ReadCharWithTimeout (PTimeInterval &timeout)
BOOL ReceiveCommandString (int nextChar, const PString &reply, PINDEX &pos, PINDEX start)
BOOL SetErrorValues (Errors errorCode, int osError, ErrorGroup group=LastGeneralError)

Protected Attributes

PString channelName
Errors lastErrorCode [NumErrorGroups+1]
 The platform independant error code.
int lastErrorNumber [NumErrorGroups+1]
 The operating system error number (eg as returned by errno).
PINDEX lastReadCount
 Number of byte last read by the Read() function.
PINDEX lastWriteCount
 Number of byte last written by the Write() function.
int os_handle
 The operating system file handle return by standard open() function.
PXBlockType px_lastBlockType
PMutex px_selectMutex
PMutex px_threadMutex
PMutex px_writeMutex
PTimeInterval readTimeout
 Timeout for read operations.
PTimeInterval writeTimeout
 Timeout for write operations.

Private Member Functions

 PCLASSINFO (PSoundChannel, PChannel)

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

Generated by  Doxygen 1.6.0   Back to index