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

Public Types | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions

PSoundChannel Class Reference

#include <sound.h>

Inheritance diagram for PSoundChannel:
Inheritance graph
[legend]
Collaboration diagram for PSoundChannel:
Collaboration graph
[legend]

List of all members.

Public Types

enum  PXBlockType { PXReadBlock, PXWriteBlock, PXAcceptBlock, PXConnectBlock }

Public Member Functions

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

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

PSoundChannelbaseChannel
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
PThreadpx_readThread
PMutex px_selectMutex
PThreadpx_selectThread
PMutex px_threadMutex
PMutex px_writeMutex
PThreadpx_writeThread
PTimeInterval readTimeout
 Timeout for read operations.
PTimeInterval writeTimeout
 Timeout for write operations.

Private Member Functions

 PCLASSINFO (PSoundChannel, PChannel)

Construction

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

Channel set up functions

enum  { MaxVolume = 100 }
virtual BOOL SetFormat (unsigned numChannels=1, unsigned sampleRate=8000, unsigned bitsPerSample=16)
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 SetBuffers (PINDEX size, PINDEX count=2)
virtual BOOL GetBuffers (PINDEX &size, PINDEX &count)
virtual BOOL SetVolume (unsigned volume)
virtual BOOL GetVolume (unsigned &volume)

Miscellaneous functions

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

Error functions

enum  Errors {
  NoError, NotFound, FileExists, DiskFull,
  AccessDenied, DeviceInUse, BadParameter, NoMemory,
  NotOpen, Timeout, Interrupted, BufferTooSmall,
  Miscellaneous, ProtocolFailure, NumNormalisedErrors
}
enum  ErrorGroup { LastReadError, LastWriteError, LastGeneralError, NumErrorGroups }
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)

Scattered read/write functions

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

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

Open functions

virtual BOOL Open (const PString &device, Directions dir, unsigned numChannels=1, unsigned sampleRate=8000, unsigned bitsPerSample=16)
virtual BOOL IsOpen () const
virtual int GetHandle () const
virtual BOOL Abort ()
static PStringList GetDriverNames (PPluginManager *pluginMgr=NULL)
static PStringList GetDriversDeviceNames (const PString &driverName, Directions direction, PPluginManager *pluginMgr=NULL)
static PStringList GetDeviceNames (const PString &driverName, Directions direction, PPluginManager *pluginMgr=NULL)
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)

Run Time Type functions

virtual const char * GetClass (unsigned=0) const
BOOL IsClass (const char *cls) const
virtual BOOL InternalIsDescendant (const char *clsName) 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)

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.


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

Generated by  Doxygen 1.6.0   Back to index