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

#include <portaudio.h>

Inheritance diagram for PSoundChannelPortAudio:
Collaboration diagram for PSoundChannelPortAudio:

Public Member Functions

 PSoundChannelPortAudio ()
 
 ~PSoundChannelPortAudio ()
 
bool Open (const Params &params)
 Open the specified device for playing or recording. More...
 
bool Setup ()
 
bool Close ()
 Close the channel. More...
 
bool IsOpen () const
 Determine if the channel is currently open and read and write operations can be executed on it. More...
 
bool Write (const void *buf, PINDEX len)
 Low level write to the channel. More...
 
bool Read (void *buf, PINDEX len)
 Low level read from the channel. More...
 
bool SetFormat (unsigned numChannels, unsigned sampleRate, unsigned bitsPerSample)
 Set the format for play/record. 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...
 
bool SetBuffers (PINDEX size, PINDEX count)
 Set the internal buffers for the sound channel I/O. More...
 
bool GetBuffers (PINDEX &size, PINDEX &count)
 Get the internal buffers for the sound channel I/O. More...
 
bool PlaySound (const PSound &sound, bool wait)
 Play a sound to the open device. More...
 
bool PlayFile (const PFilePath &filename, bool wait)
 
bool HasPlayCompleted ()
 Indicate if the sound play begun with PlayBuffer() or PlayFile() has completed. More...
 
bool WaitForPlayCompletion ()
 Block calling thread until the sound play begun with PlaySound() or PlayFile() has completed. More...
 
bool RecordSound (PSound &sound)
 Record into the sound object all of the buffer's of sound data. More...
 
bool RecordFile (const PFilePath &filename)
 Record into the platform dependent sound file all of the buffer's of sound data. More...
 
bool StartRecording ()
 Start filling record buffers. More...
 
bool IsRecordBufferFull ()
 Determine if a record buffer has been filled, so that the next Read() call will not block. More...
 
bool AreAllRecordBuffersFull ()
 Determine if all of the record buffer allocated has been filled. More...
 
bool WaitForRecordBufferFull ()
 Block the thread until a record buffer has been filled, so that the next Read() call will not block. More...
 
bool WaitForAllRecordBuffersFull ()
 Block the thread until all of the record buffer allocated has been filled. More...
 
bool Abort ()
 Abort the background playing/recording of the sound channel. More...
 
bool SetVolume (unsigned newVal)
 Set the volume of the play/read process. More...
 
bool GetVolume (unsigned &devVol)
 Get the volume of the play/read process. More...
 
bool SetMute (bool mute)
 Set the mute state of the play/read process. More...
 
bool GetMute (bool &mute)
 Get the mute state of the play/read process. More...
 
bool OpenStream (unsigned numChannels, unsigned sampleRate, unsigned bitsPerSample)
 
bool StartStream ()
 
bool StopStream ()
 
virtual PString GetName () const
 Get the name of the channel. More...
 
PString GetErrorText (ErrorGroup group=NumErrorGroups) const
 Get error message description. More...
 
- Public Member Functions inherited from PSoundChannel
 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)
 
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 bool PlayFile (const PFilePath &file, bool wait=true, unsigned volume=100)
 Play a sound file to the open device. More...
 
- 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 P_INT_PTR GetHandle () const
 Get the OS specific handle for the PSoundChannel. More...
 
virtual int ReadChar ()
 Read a single character from 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 bool CloseBaseReadChannel ()
 Close the base channel of channel indirection using PIndirectChannel. More...
 
virtual bool CloseBaseWriteChannel ()
 Close the base channel of channel indirection using PIndirectChannel. 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...
 
template<class ChannelClass >
ChannelClass * FindChannel ()
 Locate a channel of a specific class in the indirect chain. More...
 
- Public Member Functions inherited from PChannel
PBoolean SetErrorValues (Errors errorCode, int osError, ErrorGroup group=LastGeneralError)
 Set error values to those specified. More...
 
virtual PINDEX HashFunction () const
 Calculate a hash value for use in sets and dictionaries. More...
 
FILE * FDOpen (const char *mode)
 Re-open the device using the stdio library. More...
 
void SetReadTimeout (const PTimeInterval &time)
 Set the timeout for read operations. More...
 
PTimeInterval GetReadTimeout () const
 Get the timeout for read operations. More...
 
virtual PINDEX GetLastReadCount () const
 Get the number of bytes read by the last Read() call. More...
 
virtual PINDEX SetLastReadCount (PINDEX count)
 
PBoolean ReadBlock (void *buf, PINDEX len)
 Read len bytes into the buffer from the channel. More...
 
PString ReadString (PINDEX len)
 Read len character into a string from the channel. More...
 
void SetWriteTimeout (const PTimeInterval &time)
 Set the timeout for write operations to complete. More...
 
PTimeInterval GetWriteTimeout () const
 Get the timeout for write operations to complete. More...
 
virtual PBoolean Write (const void *buf, PINDEX len, const void *)
 Low level write to the channel with marker. More...
 
virtual PINDEX GetLastWriteCount () const
 Get the number of bytes written by the last Write() call. More...
 
virtual PINDEX SetLastWriteCount (PINDEX count)
 
PBoolean WriteChar (int c)
 Write a single character to the channel. More...
 
PBoolean WriteString (const PString &str)
 Write a string to the channel. More...
 
 ~PChannel ()
 Close down the channel. More...
 
Errors GetErrorCode (ErrorGroup group=NumErrorGroups) const
 Get normalised error code. More...
 
int GetErrorNumber (ErrorGroup group=NumErrorGroups) const
 Get OS errro code. More...
 
virtual bool ReadAsync (AsyncContext &context)
 Begin an asynchronous read from channel. More...
 
virtual void OnReadComplete (AsyncContext &context)
 User callback function for when a ReadAsync() call has completed or timed out. More...
 
virtual bool WriteAsync (AsyncContext &context)
 Begin an asynchronous write from channel. More...
 
virtual void OnWriteComplete (AsyncContext &context)
 User callback function for when a WriteAsync() call has completed or timed out. More...
 
virtual bool FlowControl (const void *flowData)
 Flow Control information Pass data to the channel for flowControl determination. More...
 
PBoolean SetBufferSize (PINDEX newSize)
 Set the iostream buffer size for reads and writes. More...
 
PBoolean SendCommandString (const PString &command)
 Send a command meta-string. More...
 
void AbortCommandString ()
 Abort a command string that is in progress. More...
 
- Public Member Functions inherited from PObject
__inline unsigned GetTraceContextIdentifier () const
 Get PTRACE context identifier. More...
 
__inline void SetTraceContextIdentifier (unsigned id)
 
__inline void SetTraceContextIdentifier (const PObject &obj)
 
__inline void SetTraceContextIdentifier (const PObject *obj)
 
__inline void CopyTraceContextIdentifier (PObject &obj) const
 
__inline void CopyTraceContextIdentifier (PObject *obj) const
 
virtual ~PObject ()
 
__inline const char * GetClass () const
 
__inline bool IsClass (const char *name) const
 
__inline const PObjectPTraceObjectInstance () const
 
virtual PObjectClone () const
 Create a copy of the class on the heap. More...
 
template<class CLS >
CLS * CloneAs () const
 As for Clone() but converts to specified type. More...
 
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...
 
virtual void PrintOn (ostream &strm) const
 Output the contents of the object to the stream. More...
 
virtual void ReadFrom (istream &strm)
 Input the contents of the object from the stream. More...
 

Static Public Member Functions

static PStringArray GetDeviceNames (PSoundChannel::Directions=Player)
 
static PMutexGetInitMutex ()
 
static bool Initialise ()
 
- Static Public Member Functions inherited from PSoundChannel
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...
 
static PString TestPlayer (const Params &params, const PNotifier &progress=PNotifier(), const char *toneSpec=NULL)
 Test the specified device for playing. More...
 
static PString TestRecorder (const Params &recorderParams, const Params &playerParams, const PNotifier &progress=PNotifier(), unsigned seconds=5)
 Test the specified device for playing. 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 __inline void CopyTraceContextIdentifier (PObject &to, const PObject &from)
 
static __inline void CopyTraceContextIdentifier (PObject &to, const PObject *from)
 
static __inline void CopyTraceContextIdentifier (PObject *to, const PObject &from)
 
static __inline void CopyTraceContextIdentifier (PObject *to, const PObject *from)
 
static __inline const char * Class ()
 
static __inline const PObjectPTraceObjectInstance (const char *)
 
static __inline const PObjectPTraceObjectInstance (const PObject *obj)
 
template<typename T >
static Comparison Compare2 (T v1, T v2)
 Compare two types, returning Comparison type. More...
 
static Comparison InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size)
 Internal function caled from CompareObjectMemoryDirect() More...
 

Protected Attributes

PMutex m_mutex
 
int m_channels
 
int m_sampleRate
 
int m_bitsPerSample
 
int m_bytesPerSample
 
int m_sampleFormat
 
const PaDeviceInfo * m_deviceInfo
 
int m_deviceId
 
PString m_deviceName
 
bool m_started
 
bool m_mute
 
unsigned char * m_muteBuffer
 
PINDEX m_muteBufferSize
 
PaStream * m_stream
 
PaStreamParameters m_streamParms
 
int m_volume
 
int m_playBufferSize
 
int m_playBufferCount
 
- Protected Attributes inherited from PSoundChannel
Directions m_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...
 
- Protected Attributes inherited from PChannel
PTimeInterval readTimeout
 Timeout for read operations. More...
 
PTimeInterval writeTimeout
 Timeout for write operations. More...
 
atomic< P_INT_PTRos_handle
 The operating system file handle return by standard open() function. More...
 
PThreadLocalStorage< Statusm_status [NumErrorGroups+1]
 
PXBlockType px_lastBlockType
 
PThreadpx_readThread
 
PThreadpx_writeThread
 
PThreadpx_selectThread [3]
 
PCriticalSection px_selectMutex [3]
 
- Protected Attributes inherited from PObject
unsigned m_traceContextIdentifier
 

Additional Inherited Members

- Public Types inherited from PSoundChannel
enum  { DefaultBufferSize = 320, DefaultBufferCount = 2 }
 
enum  { MaxVolume = 100 }
 
- 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 Types inherited from PObject
enum  Comparison { LessThan = -1, EqualTo = 0, GreaterThan = 1 }
 Result of the comparison operation performed by the Compare() function. More...
 
- Protected Member Functions inherited from PSoundChannel
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...
 
 PDECLARE_READ_WRITE_MUTEX (channelPointerMutex)
 Race condition prevention on closing channel. 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)
 
bool CheckNotOpen ()
 
virtual int os_errno () const
 
PBoolean PXSetIOBlock (PXBlockType type, const PTimeInterval &timeout)
 
P_INT_PTR GetOSHandleAsInt () const
 
int PXClose ()
 
 PDECLARE_MUTEX (px_threadMutex)
 
 PDECLARE_MUTEX (px_writeMutex)
 
 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...
 

Constructor & Destructor Documentation

PSoundChannelPortAudio::PSoundChannelPortAudio ( )
PSoundChannelPortAudio::~PSoundChannelPortAudio ( )

Member Function Documentation

bool PSoundChannelPortAudio::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 from PSoundChannel.

bool PSoundChannelPortAudio::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 from PSoundChannel.

bool PSoundChannelPortAudio::Close ( )
virtual

Close the channel.

This will detach itself from the read and write channels and delete both of them if they are auto delete.

Returns
true if the channel is closed.

Reimplemented from PIndirectChannel.

bool PSoundChannelPortAudio::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 from PSoundChannel.

unsigned PSoundChannelPortAudio::GetChannels ( ) const
virtual

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

Reimplemented from PSoundChannel.

static PStringArray PSoundChannelPortAudio::GetDeviceNames ( PSoundChannel::Directions  = Player)
static
PString PSoundChannelPortAudio::GetErrorText ( ErrorGroup  group = NumErrorGroups) const
virtual

Get error message description.

Return a string indicating the error message that may be displayed to the user. The error for the last I/O operation in this object is used.

Returns
Operating System error description string.

Reimplemented from PIndirectChannel.

static PMutex& PSoundChannelPortAudio::GetInitMutex ( )
static
bool PSoundChannelPortAudio::GetMute ( bool &  mute)
virtual

Get the mute state of the play/read process.

Returns
true if there were no errors.

Reimplemented from PSoundChannel.

virtual PString PSoundChannelPortAudio::GetName ( ) const
virtual

Get the name of the channel.

This is a combination of the channel pointers names (or simply the channel pointers name if the read and write channels are the same) or empty string if both null.

Returns
string for the channel names.

Reimplemented from PIndirectChannel.

unsigned PSoundChannelPortAudio::GetSampleRate ( ) const
virtual

Get the sample rate in samples per second.

Reimplemented from PSoundChannel.

unsigned PSoundChannelPortAudio::GetSampleSize ( ) const
virtual

Get the sample size in bits per sample.

Reimplemented from PSoundChannel.

bool PSoundChannelPortAudio::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.

Reimplemented from PSoundChannel.

bool PSoundChannelPortAudio::HasPlayCompleted ( )
virtual

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

Returns
true if the sound has completed playing.

Reimplemented from PSoundChannel.

static bool PSoundChannelPortAudio::Initialise ( )
static
bool PSoundChannelPortAudio::IsOpen ( ) const
virtual

Determine if the channel is currently open and read and write operations can be executed on it.

For example, in the PFile class it returns if the file is currently open.

Returns
true if the channel is open.

Reimplemented from PIndirectChannel.

bool PSoundChannelPortAudio::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 from PSoundChannel.

bool PSoundChannelPortAudio::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.

Reimplemented from PSoundChannel.

bool PSoundChannelPortAudio::OpenStream ( unsigned  numChannels,
unsigned  sampleRate,
unsigned  bitsPerSample 
)
bool PSoundChannelPortAudio::PlayFile ( const PFilePath filename,
bool  wait 
)
bool PSoundChannelPortAudio::PlaySound ( const PSound sound,
bool  wait 
)
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.

Reimplemented from PSoundChannel.

bool PSoundChannelPortAudio::Read ( void *  buf,
PINDEX  len 
)
virtual

Low level read from the channel.

This function may block until the requested number of characters were read or the read timeout was reached. The GetLastReadCount() function returns the actual number of bytes read.

This will use the readChannel pointer to actually do the read. If readChannel is null the this asserts.

The GetErrorCode() function should be consulted after Read() returns false to determine what caused the failure.

Returns
true indicates that at least one character was read from the channel. false means no bytes were read due to timeout or some other I/O error.

Reimplemented from PIndirectChannel.

bool PSoundChannelPortAudio::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.

Reimplemented from PSoundChannel.

bool PSoundChannelPortAudio::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.

Reimplemented from PSoundChannel.

bool PSoundChannelPortAudio::SetBuffers ( PINDEX  size,
PINDEX  count 
)
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.

Reimplemented from PSoundChannel.

bool PSoundChannelPortAudio::SetFormat ( unsigned  numChannels,
unsigned  sampleRate,
unsigned  bitsPerSample 
)
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.

Reimplemented from PSoundChannel.

bool PSoundChannelPortAudio::SetMute ( bool  mute)
virtual

Set the mute state of the play/read process.

Returns
true if there were no errors.

Reimplemented from PSoundChannel.

bool PSoundChannelPortAudio::Setup ( )
bool PSoundChannelPortAudio::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.

Reimplemented from PSoundChannel.

bool PSoundChannelPortAudio::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 from PSoundChannel.

bool PSoundChannelPortAudio::StartStream ( )
bool PSoundChannelPortAudio::StopStream ( )
bool PSoundChannelPortAudio::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 from PSoundChannel.

bool PSoundChannelPortAudio::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 from PSoundChannel.

bool PSoundChannelPortAudio::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 from PSoundChannel.

bool PSoundChannelPortAudio::Write ( const void *  buf,
PINDEX  len 
)
virtual

Low level write to the channel.

This function will block until the requested number of characters are written or the write timeout is reached. The GetLastWriteCount() function returns the actual number of bytes written.

This will use the writeChannel pointer to actually do the write. If writeChannel is null the this asserts.

The GetErrorCode() function should be consulted after Write() returns false to determine what caused the failure.

Returns
true if at least len bytes were written to the channel.

Reimplemented from PIndirectChannel.

Member Data Documentation

int PSoundChannelPortAudio::m_bitsPerSample
protected
int PSoundChannelPortAudio::m_bytesPerSample
protected
int PSoundChannelPortAudio::m_channels
protected
int PSoundChannelPortAudio::m_deviceId
protected
const PaDeviceInfo* PSoundChannelPortAudio::m_deviceInfo
protected
PString PSoundChannelPortAudio::m_deviceName
protected
bool PSoundChannelPortAudio::m_mute
protected
unsigned char* PSoundChannelPortAudio::m_muteBuffer
protected
PINDEX PSoundChannelPortAudio::m_muteBufferSize
protected
PMutex PSoundChannelPortAudio::m_mutex
protected
int PSoundChannelPortAudio::m_playBufferCount
protected
int PSoundChannelPortAudio::m_playBufferSize
protected
int PSoundChannelPortAudio::m_sampleFormat
protected
int PSoundChannelPortAudio::m_sampleRate
protected
bool PSoundChannelPortAudio::m_started
protected
PaStream* PSoundChannelPortAudio::m_stream
protected
PaStreamParameters PSoundChannelPortAudio::m_streamParms
protected
int PSoundChannelPortAudio::m_volume
protected

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