PTLib  Version 2.14.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PSoundChannel Class Reference

Abstract class for a generalised sound channel, and an implementation of PSoundChannel for old code that is not plugin-aware. More...

#include <sound.h>

Inheritance diagram for PSoundChannel:
Collaboration diagram for PSoundChannel:

Classes

struct  Params
 Parameters for opening a sound channel. More...
 

Protected Member Functions

PSoundChannelGetSoundChannel () const
 
 P_REMOVE_VIRTUAL (PBoolean, Open(const PString &, Directions, unsigned, unsigned, unsigned), false)
 
- Protected Member Functions inherited from PIndirectChannel
virtual PBoolean OnOpen ()
 This callback is executed when the Open() function is called with open channels. More...
 
- Protected Member Functions inherited from PChannel
 PChannel (const PChannel &)
 
PChanneloperator= (const PChannel &)
 
virtual PBoolean ConvertOSError (P_INT_PTR libcReturnValue, ErrorGroup group=LastGeneralError)
 Convert an operating system error into platform independent error. More...
 
int ReadCharWithTimeout (PTimeInterval &timeout)
 Read a character with specified timeout. More...
 
PBoolean ReceiveCommandString (int nextChar, const PString &reply, PINDEX &pos, PINDEX start)
 
virtual int os_errno () const
 
PBoolean PXSetIOBlock (PXBlockType type, const PTimeInterval &timeout)
 
P_INT_PTR GetOSHandleAsInt () const
 
int PXClose ()
 
 PChannel ()
 Create the channel. More...
 
- Protected Member Functions inherited from PObject
 PObject ()
 Constructor for PObject, made protected so cannot ever create one on its own. More...
 

Protected Attributes

Directions activeDirection
 This is the direction that this sound channel is opened for use in. More...
 
- Protected Attributes inherited from PIndirectChannel
PChannelreadChannel
 Channel for read operations. More...
 
PBoolean readAutoDelete
 Automatically delete read channel on destruction. More...
 
PChannelwriteChannel
 Channel for write operations. More...
 
PBoolean writeAutoDelete
 Automatically delete write channel on destruction. More...
 
PReadWriteMutex channelPointerMutex
 Race condition prevention on closing channel. More...
 
- Protected Attributes inherited from PChannel
P_INT_PTR os_handle
 The operating system file handle return by standard open() function. More...
 
Errors lastErrorCode [NumErrorGroups+1]
 The platform independant error code. More...
 
int lastErrorNumber [NumErrorGroups+1]
 The operating system error number (eg as returned by errno). More...
 
PINDEX lastReadCount
 Number of byte last read by the Read() function. More...
 
PINDEX lastWriteCount
 Number of byte last written by the Write() function. More...
 
PTimeInterval readTimeout
 Timeout for read operations. More...
 
PTimeInterval writeTimeout
 Timeout for write operations. More...
 
PString channelName
 Name of channel. More...
 
PMutex px_threadMutex
 
PXBlockType px_lastBlockType
 
PThreadpx_readThread
 
PThreadpx_writeThread
 
PMutex px_writeMutex
 
PThreadpx_selectThread [3]
 
PMutex px_selectMutex [3]
 
- Protected Attributes inherited from PObject
unsigned m_traceContextIdentifier
 

Construction

enum  { DefaultBufferSize = 320, DefaultBufferCount = 2 }
 
 P_DECLARE_STREAMABLE_ENUM (Directions, Recorder, Player, Closed)
 
 PSoundChannel ()
 Create a sound channel. More...
 
 PSoundChannel (const Params &params)
 Create a sound channel. More...
 
 PSoundChannel (const PString &device, Directions dir, unsigned numChannels=1, unsigned sampleRate=8000, unsigned bitsPerSample=16)
 

Open functions

virtual bool Open (const Params &params)
 Open the specified device for playing or recording. More...
 
bool Open (const PString &device, Directions dir, unsigned numChannels=1, unsigned sampleRate=8000, unsigned bitsPerSample=16, PPluginManager *pluginMgr=NULL)
 
Directions GetDirection () const
 Get the direction of the channel. More...
 
virtual const char * GetDirectionText () const
 Get text representing the direction of the channel. More...
 
virtual PBoolean Abort ()
 Abort the background playing/recording of the sound channel. More...
 
static PStringArray GetDriverNames (PPluginManager *pluginMgr=NULL)
 Get the list of available sound drivers (plug-ins) More...
 
static PStringArray GetDriversDeviceNames (const PString &driverName, Directions direction, PPluginManager *pluginMgr=NULL)
 Get sound devices that correspond to the specified driver name. More...
 
static PStringArray GetDeviceNames (const PString &driverName, Directions direction, PPluginManager *pluginMgr=NULL)
 
static PSoundChannelCreateChannel (const PString &driverName, PPluginManager *pluginMgr=NULL)
 Create the sound channel that corresponds to the specified driver name. More...
 
static PSoundChannelCreateChannelByName (const PString &deviceName, Directions direction, PPluginManager *pluginMgr=NULL)
 
static PSoundChannelCreateOpenedChannel (const Params &params)
 Create an opened sound channel that corresponds to the specified names. More...
 
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)
 Get the name for the default sound devices/driver that is on this platform. More...
 
static PStringArray GetDeviceNames (Directions direction, PPluginManager *pluginMgr=NULL)
 Get the list of all devices name for the default sound devices/driver that is on this platform. More...
 
static const char * GetDirectionText (Directions dir)
 Get text representing the direction of a channel. More...
 

Channel set up functions

enum  { MaxVolume = 100 }
 
virtual PBoolean SetFormat (unsigned numChannels=1, unsigned sampleRate=8000, unsigned bitsPerSample=16)
 Set the format for play/record. More...
 
virtual unsigned GetChannels () const
 Get the number of channels (mono/stereo) in the sound. More...
 
virtual unsigned GetSampleRate () const
 Get the sample rate in samples per second. More...
 
virtual unsigned GetSampleSize () const
 Get the sample size in bits per sample. More...
 
virtual PBoolean SetBuffers (PINDEX size, PINDEX count=2)
 Set the internal buffers for the sound channel I/O. More...
 
virtual PBoolean GetBuffers (PINDEX &size, PINDEX &count)
 Get the internal buffers for the sound channel I/O. More...
 
virtual PBoolean SetVolume (unsigned volume)
 Set the volume of the play/read process. More...
 
virtual PBoolean GetVolume (unsigned &volume)
 Get the volume of the play/read process. More...
 
virtual bool SetMute (bool mute)
 Set the mute state of the play/read process. More...
 
virtual bool GetMute (bool &mute)
 Get the mute state of the play/read process. More...
 

Play functions

virtual PBoolean PlaySound (const PSound &sound, PBoolean wait=true)
 Play a sound to the open device. More...
 
virtual PBoolean PlayFile (const PFilePath &file, PBoolean wait=true)
 Play a sound file to the open device. More...
 
virtual PBoolean HasPlayCompleted ()
 Indicate if the sound play begun with PlayBuffer() or PlayFile() has completed. More...
 
virtual PBoolean WaitForPlayCompletion ()
 Block calling thread until the sound play begun with PlaySound() or PlayFile() has completed. More...
 
static PString TestPlayer (const Params &params, const PNotifier &progress=PNotifier(), const char *toneSpec=NULL)
 Test the specified device for playing. More...
 

Record functions

virtual PBoolean RecordSound (PSound &sound)
 Record into the sound object all of the buffer's of sound data. More...
 
virtual PBoolean RecordFile (const PFilePath &file)
 Record into the platform dependent sound file all of the buffer's of sound data. More...
 
virtual PBoolean StartRecording ()
 Start filling record buffers. More...
 
virtual PBoolean IsRecordBufferFull ()
 Determine if a record buffer has been filled, so that the next Read() call will not block. More...
 
virtual PBoolean AreAllRecordBuffersFull ()
 Determine if all of the record buffer allocated has been filled. More...
 
virtual PBoolean WaitForRecordBufferFull ()
 Block the thread until a record buffer has been filled, so that the next Read() call will not block. More...
 
virtual PBoolean WaitForAllRecordBuffersFull ()
 Block the thread until all of the record buffer allocated has been filled. More...
 
static PString TestRecorder (const Params &recorderParams, const Params &playerParams, const PNotifier &progress=PNotifier(), unsigned seconds=5)
 Test the specified device for playing. More...
 

Additional Inherited Members

- Public Types inherited from PChannel
enum  PXBlockType { PXReadBlock, PXWriteBlock, PXAcceptBlock, PXConnectBlock }
 
enum  Errors {
  NoError, NotFound, FileExists, DiskFull,
  AccessDenied, DeviceInUse, BadParameter, NoMemory,
  NotOpen, Timeout, Interrupted, BufferTooSmall,
  Miscellaneous, ProtocolFailure, Unavailable, NumNormalisedErrors
}
 Normalised error codes. More...
 
enum  ErrorGroup { LastReadError, LastWriteError, LastGeneralError, NumErrorGroups }
 Error groups. More...
 
typedef PNotifierTemplate
< PChannel::AsyncContext & > 
AsyncNotifier
 
enum  ShutdownValue { ShutdownRead = 0, ShutdownWrite = 1, ShutdownReadAndWrite = 2 }
 
- Public Member Functions inherited from PIndirectChannel
 PIndirectChannel ()
 Create a new indirect channel without any channels to redirect to. More...
 
 ~PIndirectChannel ()
 Close the indirect channel, deleting read/write channels if desired. More...
 
Comparison Compare (const PObject &obj) const
 Determine if the two objects refer to the same indirect channel. More...
 
virtual PString GetName () const
 Get the name of the channel. More...
 
virtual P_INT_PTR GetHandle () const
 Get the OS specific handle for the PSoundChannel. More...
 
virtual PBoolean Close ()
 Close the channel. More...
 
virtual PBoolean IsOpen () const
 Determine if the channel is currently open and read and write operations can be executed on it. More...
 
virtual PBoolean Read (void *buf, PINDEX len)
 Low level read from the channel. More...
 
virtual int ReadChar ()
 Read a single character from the channel. More...
 
virtual PBoolean Write (const void *buf, PINDEX len)
 Low level write to the channel. More...
 
virtual PBoolean Shutdown (ShutdownValue option)
 Close one or both of the data streams associated with a channel. More...
 
virtual bool SetLocalEcho (bool localEcho)
 Set local echo mode. More...
 
virtual PChannelGetBaseReadChannel () const
 This function returns the eventual base channel for reading of a series of indirect channels provided by descendents of PIndirectChannel. More...
 
virtual PChannelGetBaseWriteChannel () const
 This function returns the eventual base channel for writing of a series of indirect channels provided by descendents of PIndirectChannel. More...
 
virtual PString GetErrorText (ErrorGroup group=NumErrorGroups) const
 Get error message description. More...
 
PBoolean Open (PChannel &channel)
 Set the channel for both read and write operations. More...
 
PBoolean Open (PChannel *channel, PBoolean autoDelete=true)
 Set the channel for both read and write operations. More...
 
PBoolean Open (PChannel *readChannel, PChannel *writeChannel, PBoolean autoDeleteRead=true, PBoolean autoDeleteWrite=true)
 Set the channel for both read and write operations. More...
 
PChannelDetach (ShutdownValue option=ShutdownReadAndWrite)
 Detach without closing the read/write channel. More...
 
PChannelGetReadChannel () const
 Get the channel used for read operations. More...
 
bool SetReadChannel (PChannel *channel, bool autoDelete=true, bool closeExisting=false)
 Set the channel for read operations. More...
 
PChannelGetWriteChannel () const
 Get the channel used for write operations. More...
 
PBoolean SetWriteChannel (PChannel *channel, bool autoDelete=true, bool closeExisting=false)
 Set the channel for read operations. More...
 
- Static Public Member Functions inherited from PChannel
static PString GetErrorText (Errors lastError, int osError=0)
 Get error message description. More...
 
- Static Public Member Functions inherited from PObject
static const char * Class ()
 Get the name of the class as a C string. More...
 
static __inline const PObjectPTraceObjectInstance (const char *)
 
static __inline const PObjectPTraceObjectInstance (const PObject *obj)
 
static Comparison InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size)
 Internal function caled from CompareObjectMemoryDirect() More...
 
- Friends inherited from PObject

Detailed Description

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 channel. Drivers for real, platform dependent sound hardware will be ancestors of this class and can be found in the plugins section of PTLib.

A sound channel is either playing or recording. If simultaneous playing and recording is desired, two instances of PSoundChannel must be created. It is an error for the same thread to attempt to both read and write audio data to once instance of a PSoundChannel class.

PSoundChannel instances are designed to be reentrant. The actual usage model employed is left to the developer. One model could be where one thread is responsible for construction, setup, opening and read/write operations. After creating and eventually opening the channel this thread is responsible for handling read/writes fast enough to avoid gaps in the generated audio stream.

Remaining operations may beinvoked from other threads. This includes Close() and actually gathering the necessary data to be sent to the device.

Besides the basic I/O task, the Read()/Write(() functions have well defined timing characteristics. When a PSoundChannel instance is used from Opal, the read/write operations are designed to also act as timers so as to nicely space the generated network packets of audio/ sound packets to the speaker.

Read and Writes of audio data to a PSoundChannel are blocking. The length of time required to read/write a block of audio from/to a PSoundChannel instance is equal to the time required for that block of audio to record/play. So for a sound rate of 8khz, 240 samples, it is going to take 30ms to do a read/write.

Since the Read()/Write(() functions have well defined timing characteristics; they are designed to also act as timers in a loop involving data transfers to/from the codecs.

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, 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.

Member Enumeration Documentation

anonymous enum
Enumerator
DefaultBufferSize 
DefaultBufferCount 
anonymous enum
Enumerator
MaxVolume 

Constructor & Destructor Documentation

PSoundChannel::PSoundChannel ( )

Create a sound channel.

PSoundChannel::PSoundChannel ( const Params params)

Create a sound channel.

Create a reference to the sound drivers for the platform.

Parameters
paramsParameters for opening channel
PSoundChannel::PSoundChannel ( const PString device,
Directions  dir,
unsigned  numChannels = 1,
unsigned  sampleRate = 8000,
unsigned  bitsPerSample = 16 
)
Parameters
deviceName of sound driver/device
dirSound I/O direction
numChannelsNumber of channels eg mono/stereo
sampleRateSamples per second
bitsPerSampleNumber of bits per sample

Member Function Documentation

virtual PBoolean PSoundChannel::Abort ( )
virtual

Abort the background playing/recording of the sound channel.

There will be a logic assertion if you attempt to Abort a sound channel operation, when the device is currently closed.

Returns
true if the sound has successfully been aborted.

Reimplemented in PSoundChannelPortAudio.

virtual PBoolean PSoundChannel::AreAllRecordBuffersFull ( )
virtual

Determine if all of the record buffer allocated has been filled.

There is an implicit Abort() of the recording if this occurs and recording is stopped. The channel may need to be closed and opened again to start a new recording.

Returns
true if the sound driver has filled a buffer.

Reimplemented in PSoundChannelPortAudio.

static PSoundChannel* PSoundChannel::CreateChannel ( const PString driverName,
PPluginManager pluginMgr = NULL 
)
static

Create the sound channel that corresponds to the specified driver name.

Parameters
driverNameName of driver
pluginMgrPlug in manager, use default if NULL
static PSoundChannel* PSoundChannel::CreateChannelByName ( const PString deviceName,
Directions  direction,
PPluginManager pluginMgr = NULL 
)
static
Parameters
deviceNameName of device
directionDirection for device (record or play)
pluginMgrPlug in manager, use default if NULL
static PSoundChannel* PSoundChannel::CreateOpenedChannel ( const Params params)
static

Create an opened sound channel that corresponds to the specified names.

If the driverName parameter is an empty string or "*" then CreateChannelByName is used with the deviceName parameter which is assumed to be a value returned from GetAllDeviceNames().

Parameters
paramsParameters for opening channel
static PSoundChannel* PSoundChannel::CreateOpenedChannel ( const PString driverName,
const PString deviceName,
Directions  direction,
unsigned  numChannels = 1,
unsigned  sampleRate = 8000,
unsigned  bitsPerSample = 16,
PPluginManager pluginMgr = NULL 
)
static
Parameters
driverNameName of driver
deviceNameName of device
directionDirection for device (record or play)
numChannelsNumber of channels 1=mon, 2=stereo
sampleRateSample rate
bitsPerSampleBits per sample
pluginMgrPlug in manager, use default if NULL
virtual PBoolean PSoundChannel::GetBuffers ( PINDEX &  size,
PINDEX &  count 
)
virtual

Get the internal buffers for the sound channel I/O.

Returns
true if the buffer size were obtained.

Reimplemented in PSoundChannelPortAudio.

virtual unsigned PSoundChannel::GetChannels ( ) const
virtual

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

Reimplemented in PSoundChannelPortAudio.

static PString PSoundChannel::GetDefaultDevice ( Directions  dir)
static

Get the name for the default sound devices/driver that is on this platform.

Note that a named device may not necessarily do both playing and recording so the string returned with the dir parameter in each value is not necessarily the same.

Returns
A platform dependent string for the sound player/recorder.
static PStringArray PSoundChannel::GetDeviceNames ( const PString driverName,
Directions  direction,
PPluginManager pluginMgr = NULL 
)
inlinestatic
static PStringArray PSoundChannel::GetDeviceNames ( Directions  direction,
PPluginManager pluginMgr = NULL 
)
static

Get the list of all devices name for the default sound devices/driver that is on this platform.

Note that a named device may not necessarily do both playing and recording so the arrays returned with the dir parameter in each value is not necessarily the same.

This will return a list of unique device names across all of the available drivers. If two drivers have identical names for devices, then the string returned will be of the form driver+'\t'+device.

Returns
Platform dependent strings for the sound player/recorder.
Parameters
directionDirection for device (record or play)
pluginMgrPlug in manager, use default if NULL
Directions PSoundChannel::GetDirection ( ) const
inline

Get the direction of the channel.

References activeDirection.

static const char* PSoundChannel::GetDirectionText ( Directions  dir)
static

Get text representing the direction of a channel.

virtual const char* PSoundChannel::GetDirectionText ( ) const
inlinevirtual

Get text representing the direction of the channel.

References activeDirection.

static PStringArray PSoundChannel::GetDriverNames ( PPluginManager pluginMgr = NULL)
static

Get the list of available sound drivers (plug-ins)

Parameters
pluginMgrPlug in manager, use default if NULL
static PStringArray PSoundChannel::GetDriversDeviceNames ( const PString driverName,
Directions  direction,
PPluginManager pluginMgr = NULL 
)
static

Get sound devices that correspond to the specified driver name.

If driverName is an empty string or the value "*" then GetAllDeviceNames() is used.

Parameters
driverNameName of driver
directionDirection for device (record or play)
pluginMgrPlug in manager, use default if NULL

Referenced by GetDeviceNames().

virtual bool PSoundChannel::GetMute ( bool &  mute)
virtual

Get the mute state of the play/read process.

Returns
true if there were no errors.
Parameters
muteVariable to receive mute state.

Reimplemented in PSoundChannelPortAudio.

virtual unsigned PSoundChannel::GetSampleRate ( ) const
virtual

Get the sample rate in samples per second.

Reimplemented in PSoundChannelPortAudio.

virtual unsigned PSoundChannel::GetSampleSize ( ) const
virtual

Get the sample size in bits per sample.

Reimplemented in PSoundChannelPortAudio.

PSoundChannel* PSoundChannel::GetSoundChannel ( ) const
inlineprotected
virtual PBoolean PSoundChannel::GetVolume ( unsigned &  volume)
virtual

Get the volume of the play/read process.

The volume range is 0 == muted, 100 == LOUDEST. The volume is a logarithmic scale mapped from the lowest gain possible on the device to the highest gain.

Returns
true if there were no errors.
Parameters
volumeVariable to receive volume level.

Reimplemented in PSoundChannelPortAudio.

virtual PBoolean PSoundChannel::HasPlayCompleted ( )
virtual

Indicate if the sound play begun with PlayBuffer() or PlayFile() has completed.

Returns
true if the sound has completed playing.

Reimplemented in PSoundChannelPortAudio.

virtual PBoolean PSoundChannel::IsRecordBufferFull ( )
virtual

Determine if a record buffer has been filled, so that the next Read() call will not block.

Provided that the amount of data read is less than the buffer size.

Returns
true if the sound driver has filled a buffer.

Reimplemented in PSoundChannelPortAudio.

virtual bool PSoundChannel::Open ( const Params params)
virtual

Open the specified device for playing or recording.

The device name is platform specific and is as returned in the GetDevices() function.

Returns
true if the sound device is valid for playing/recording.
Parameters
paramsParameters for opening channel

Reimplemented in PSoundChannelPortAudio.

bool PSoundChannel::Open ( const PString device,
Directions  dir,
unsigned  numChannels = 1,
unsigned  sampleRate = 8000,
unsigned  bitsPerSample = 16,
PPluginManager pluginMgr = NULL 
)
Parameters
deviceName of sound driver/device
dirSound I/O direction
numChannelsNumber of channels eg mono/stereo
sampleRateSamples per second
bitsPerSampleNumber of bits per sample
pluginMgrPlug in manager, use default if NULL
PSoundChannel::P_DECLARE_STREAMABLE_ENUM ( Directions  ,
Recorder  ,
Player  ,
Closed   
)
PSoundChannel::P_REMOVE_VIRTUAL ( PBoolean  ,
Open(const PString &, Directions, unsigned, unsigned, unsigned)  ,
false   
)
protected
virtual PBoolean PSoundChannel::PlayFile ( const PFilePath file,
PBoolean  wait = true 
)
virtual

Play a sound file to the open 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.

Note if the driver is closed of the object destroyed then the sound play is aborted.

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

Returns
true if the sound is playing or has played.
Parameters
fileSound file to play.
waitFlag to play sound synchronously.

Reimplemented in PSoundChannelPortAudio.

virtual PBoolean PSoundChannel::PlaySound ( const PSound sound,
PBoolean  wait = true 
)
virtual

Play a sound to the open 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.

Note: if the driver is closed while playing the sound, the play operation stops immediately.

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

Returns
true if the sound is playing or has played.
Parameters
soundSound to play.
waitFlag to play sound synchronously.

Reimplemented in PSoundChannelPortAudio.

virtual PBoolean PSoundChannel::RecordFile ( const PFilePath file)
virtual

Record into the platform dependent sound file all of the buffer's of sound data.

Use the SetBuffers() function to determine how long the recording will be made.

Note that this function will block until all of the data is buffered. If you wish to do this asynchronously, use StartRecording() and AreAllrecordBuffersFull() to determine when you can call RecordSound() without blocking.

Returns
true if the sound has been recorded.
Parameters
fileSound file recorded

Reimplemented in PSoundChannelPortAudio.

virtual PBoolean PSoundChannel::RecordSound ( PSound sound)
virtual

Record into the sound object all of the buffer's of sound data.

Use the SetBuffers() function to determine how long the recording will be made.

For the Win32 platform, the most efficient way to record a PSound is to use the SetBuffers() function to set a single buffer of the desired size and then do the recording. For Linux OSS this can cause problems as the buffers are rounded up to a power of two, so to gain more accuracy you need a number of smaller buffers.

Note that this function will block until all of the data is buffered. If you wish to do this asynchronously, use StartRecording() and AreAllrecordBuffersFull() to determine when you can call RecordSound() without blocking.

Returns
true if the sound has been recorded.
Parameters
soundSound recorded

Reimplemented in PSoundChannelPortAudio.

virtual PBoolean PSoundChannel::SetBuffers ( PINDEX  size,
PINDEX  count = 2 
)
virtual

Set the internal buffers for the sound channel I/O.

Note that with Linux OSS, the size is always rounded up to the nearest power of two, so 20000 => 32768.

Returns
true if the sound device is valid for playing/recording.
Parameters
sizeSize of each buffer in bytes
countNumber of buffers

Reimplemented in PSoundChannelPortAudio.

virtual PBoolean PSoundChannel::SetFormat ( unsigned  numChannels = 1,
unsigned  sampleRate = 8000,
unsigned  bitsPerSample = 16 
)
virtual

Set the format for play/record.

Note that linear PCM data is the only one supported at this time.

Note that if the PlayFile() function is used, this may be overridden by information in the file being played.

Returns
true if the format is valid.
Parameters
numChannelsNumber of channels eg mono/stereo
sampleRateSamples per second
bitsPerSampleNumber of bits per sample

Reimplemented in PSoundChannelPortAudio.

virtual bool PSoundChannel::SetMute ( bool  mute)
virtual

Set the mute state of the play/read process.

Returns
true if there were no errors.
Parameters
muteNew mute state

Reimplemented in PSoundChannelPortAudio.

virtual PBoolean PSoundChannel::SetVolume ( unsigned  volume)
virtual

Set the volume of the play/read process.

The volume range is 0 == muted, 100 == LOUDEST. The volume is a logarithmic scale mapped from the lowest gain possible on the device to the highest gain.

Returns
true if there were no errors.
Parameters
volumeNew volume level

Reimplemented in PSoundChannelPortAudio.

virtual PBoolean PSoundChannel::StartRecording ( )
virtual

Start filling record buffers.

The first call to Read() will also initiate the recording.

Returns
true if the sound driver has successfully started recording.

Reimplemented in PSoundChannelPortAudio.

static PString PSoundChannel::TestPlayer ( const Params params,
const PNotifier progress = PNotifier(),
const char *  toneSpec = NULL 
)
static

Test the specified device for playing.

A series of tones are played to the channel and the result return as a string. The string will start with "Success" or "Error" with the former having some statistics on the performace of the palyer and the latter containing whatever error information is available.

Returns
true if the sound device is valid for playing/recording.
Parameters
paramsParameters for opening channel
progressCall back for progress in playback
toneSpecTones as used by PTones class.
static PString PSoundChannel::TestRecorder ( const Params recorderParams,
const Params playerParams,
const PNotifier progress = PNotifier(),
unsigned  seconds = 5 
)
static

Test the specified device for playing.

A recording of a number of seconds of audio is made, and is played back using the second set of parameters.

Returns
true if the sound device is valid for playing/recording.
Parameters
recorderParamsParameters for opening channel
playerParamsParameters for opening channel
progressCall back for progress in playback
secondsSeconds to record
virtual PBoolean PSoundChannel::WaitForAllRecordBuffersFull ( )
virtual

Block the thread until all of the record buffer allocated has been filled.

There is an implicit Abort() of the recording if this occurs and recording is stopped. The channel may need to be closed and opened again to start a new recording.

Returns
true if the sound driver has filled a buffer.

Reimplemented in PSoundChannelPortAudio.

virtual PBoolean PSoundChannel::WaitForPlayCompletion ( )
virtual

Block calling thread until the sound play begun with PlaySound() or PlayFile() has completed.

Returns
true if the sound has successfully completed playing.

Reimplemented in PSoundChannelPortAudio.

virtual PBoolean PSoundChannel::WaitForRecordBufferFull ( )
virtual

Block the thread until a record buffer has been filled, so that the next Read() call will not block.

Provided that the amount of data read is less than the buffer size.

Returns
true if the sound driver has filled a buffer.

Reimplemented in PSoundChannelPortAudio.

Member Data Documentation

Directions PSoundChannel::activeDirection
protected

This is the direction that this sound channel is opened for use in.

Should the user attempt to used this opened class instance in a direction opposite to that specified in activeDirection, an assert happens.

Referenced by GetDirection(), and GetDirectionText().


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