#include <sound.h>
Inheritance diagram for PSoundChannel:
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) |
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 () |
PStringList | GetDriverNames (PPluginManager *pluginMgr=NULL) |
PStringList | GetDeviceNames (const PString &driverName, const PSoundChannel::Directions, PPluginManager *pluginMgr=NULL) |
PSoundChannel * | CreateChannel (const PString &driverName, PPluginManager *pluginMgr=NULL) |
PSoundChannel * | CreateOpenedChannel (const PString &driverName, const PString &deviceName, const PSoundChannel::Directions, unsigned numChannels=1, unsigned sampleRate=8000, unsigned bitsPerSample=16) |
PString | GetDefaultDevice (Directions dir) |
PStringList | GetDeviceNames (Directions dir) |
Public Types | |
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 () |
Protected Attributes | |
PSoundChannel * | baseChannel |
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.
|
|
|
|
|
Create a sound channel.
|
|
Create a sound channel. Create a reference to the sound drivers for the platform.
|
|
|
|
Abort the background playing/recording of the sound channel.
|
|
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.
|
|
Return sound channel object that correspond to the specified name |
|
Return opened sound channel object that correspond to the specified name |
|
Get the internal buffers for the sound channel I/O.
|
|
Get the number of channels (mono/stereo) in the sound.
|
|
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 arrays returned with the #dir# parameter in each value is not necessarily the same.
|
|
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.
|
|
Return sound devices that correspond to the specified name |
|
Return names of all plugins that correspond to sound devices |
|
Get the OS specific handle for the PSoundChannel.
Reimplemented from PChannel. |
|
Get the number of bytes read by the last Read() call. This will be from 0 to the maximum number of bytes as passed to the Read() call.
Note that the number of bytes read may often be less than that asked for. Aside from the most common case of being at end of file, which the applications semantics may regard as an exception, there are some cases where this is normal. For example, if a PTextFile channel on the MSDOS platform is read from, then the translation of CR/LF pairs to
Reimplemented from PChannel. |
|
Get the number of bytes written by the last Write() call.
Note that the number of bytes written may often be less, or even more, than that asked for. A common case of it being less is where the disk is full. An example of where the bytes written is more is as follows. On a PTextFile# channel on the MSDOS platform, there is translation of
Reimplemented from PChannel. |
|
Get the sample rate in samples per second.
|
|
Get the sample size in bits per sample.
|
|
Get the volume of the play/read process. The volume range is 0 == quiet. 100 == LOUD.
|
|
Indicate if the sound play begun with PlayBuffer() or PlayFile() has completed.
|
|
Test if this instance of PSoundChannel is open.
Reimplemented from PChannel. |
|
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.
|
|
Open the specified device for playing or recording. The device name is platform specific and is as returned in the GetDevices() function.
|
|
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.
|
|
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 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.
|
|
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. The GetErrorCode() function should be consulted after Read() returns FALSE to determine what caused the failure.
Reimplemented from PChannel. |
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
Set the volume of the play/read process. The volume range is 0 == quiet. 100 == LOUD.
|
|
Start filling record buffers. The first call to Read() will also initiate the recording.
|
|
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.
|
|
Block the thread until the sound play begun with PlayBuffer() or PlayFile() has completed.
|
|
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.
|
|
Low level write (or play) 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. The GetErrorCode() function should be consulted after Write() returns FALSE to determine what caused the failure.
Reimplemented from PChannel. |
|
|