43 #define PSOUND_PCM16 "PCM-16"
69 unsigned bitsPerSample = 16,
70 PINDEX bufferSize = 0,
71 const BYTE * data = NULL
127 unsigned bitsPerSample
167 unsigned volume = 100
177 const short * srcPtr,
180 unsigned srcChannels,
291 Directions dir = Player,
294 unsigned channels = 1,
295 unsigned sampleRate = 8000,
296 unsigned bitsPerSample = 16,
299 PPluginManager * pluginMgr = NULL
329 unsigned numChannels = 1,
330 unsigned sampleRate = 8000,
331 unsigned bitsPerSample = 16
340 PPluginManager * pluginMgr = NULL
349 Directions direction,
350 PPluginManager * pluginMgr = NULL
356 Directions direction,
357 PPluginManager * pluginMgr = NULL
364 PPluginManager * pluginMgr = NULL
376 Directions direction,
377 PPluginManager * pluginMgr = NULL
386 const Params & params
393 Directions direction,
394 unsigned numChannels = 1,
395 unsigned sampleRate = 8000,
396 unsigned bitsPerSample = 16,
397 PPluginManager * pluginMgr = NULL
425 Directions direction,
426 PPluginManager * pluginMgr = NULL
436 const Params & params
443 unsigned numChannels = 1,
444 unsigned sampleRate = 8000,
445 unsigned bitsPerSample = 16,
446 PPluginManager * pluginMgr = NULL
486 unsigned numChannels = 1,
487 unsigned sampleRate = 8000,
488 unsigned bitsPerSample = 16
612 unsigned volume = 100
641 const Params & params,
643 const char * toneSpec = NULL
740 const Params & recorderParams,
741 const Params & playerParams,
772 virtual PBoolean SetFormat(
unsigned numChannels,
unsigned sampleRate,
unsigned bitsPerSample);
789 virtual bool SetMute(
bool mute);
790 virtual bool GetMute(
bool & mute);
793 virtual bool RawWrite(
const void * data, PINDEX size);
794 virtual bool RawRead(
void * data, PINDEX size);
818 #define PCREATE_SOUND_PLUGIN_EX(name, InstanceClass, extra) \
819 PCREATE_PLUGIN(name, PSoundChannel, InstanceClass, PPlugin_PSoundChannel, \
820 virtual PStringArray GetDeviceNames(P_INT_PTR userData) const { return InstanceClass::GetDeviceNames((PSoundChannel::Directions)userData); } \
823 #define PCREATE_SOUND_PLUGIN(name, InstanceClass) PCREATE_SOUND_PLUGIN_EX(name, InstanceClass, )
826 #define P_NULL_AUDIO_DEVICE "NullAudio"
830 #define P_WINDOWS_MULTIMEDIA_DRIVER "WindowsMultimedia"
832 #elif defined(P_ANDROID)
834 #elif defined(P_MACOSX) || defined(P_IOS)
836 #elif defined(__BEOS__)
840 #if defined(P_DIRECTSOUND)
841 #define P_DIRECT_SOUND_DRIVER "DirectSound"
845 #if defined(P_WAVFILE)
846 #define P_WAV_FILE_DRIVER "WAVFile"
855 #endif // PTLIB_SOUND_H
Directions GetDirection() const
Get the direction of the channel.
Definition: sound.h:450
virtual bool PlayFile(const PFilePath &file, bool wait=true, unsigned volume=100)
Play a sound file to the open device.
unsigned m_sampleRate
Definition: sound.h:798
Abstract class for a generalised sound channel, and an implementation of PSoundChannel for old code t...
Definition: sound.h:267
PSound(unsigned numChannels=1, unsigned sampleRate=8000, unsigned bitsPerSample=16, PINDEX bufferSize=0, const BYTE *data=NULL)
Create a new sound, using the parameters provided.
virtual bool RawWrite(const void *data, PINDEX size)
virtual PBoolean Read(void *buf, PINDEX len)
Low level read from the channel.
virtual PBoolean WaitForPlayCompletion()
Block calling thread until the sound play begun with PlaySound() or PlayFile() has completed...
bool m_autoRepeat
Definition: sound.h:805
friend ostream & operator<<(ostream &, const Params ¶ms)
unsigned GetChannels() const
Get the number of channels (mono/stereo) in the sound.
Definition: sound.h:136
Class specialisation for PNotifierTemplate<P_INT_PTR>
PString m_device
Name of sound device.
Definition: sound.h:303
unsigned GetSampleSize() const
Get the sample size in bits per sample.
Definition: sound.h:142
static void Beep()
Play the "standard" warning beep for the platform.
virtual PBoolean GetVolume(unsigned &volume)
Get the volume of the play/read process.
const void * GetFormatInfoData() const
Get pointer to the platform dependent format info.
Definition: sound.h:151
unsigned m_bufferSize
Size of the internal buffer in bytes, typically the smallest amount of data channel can read or writt...
Definition: sound.h:308
static PStringArray GetDriversDeviceNames(const PString &driverName, Directions direction, PPluginManager *pluginMgr=NULL)
Get sound devices that correspond to the specified driver name.
static PString TestRecorder(const Params &recorderParams, const Params &playerParams, const PNotifier &progress=PNotifier(), unsigned seconds=5)
Test the specified device for playing.
virtual PBoolean SetVolume(unsigned volume)
Set the volume of the play/read process.
virtual bool Open(const Params ¶ms)
Open the specified device for playing or recording.
PSound & operator=(const PBYTEArray &data)
Set new data bytes for the sound.
virtual unsigned GetSampleSize() const
Get the sample size in bits per sample.
virtual PBoolean AreAllRecordBuffersFull()
Determine if all of the record buffer allocated has been filled.
virtual PBoolean HasPlayCompleted()
Indicate if the sound play begun with PlayBuffer() or PlayFile() has completed.
virtual PBoolean StartRecording()
Start filling record buffers.
This class describes a full description for a file on the particular platform.
Definition: filepath.h:61
virtual PBoolean RecordFile(const PFilePath &file)
Record into the platform dependent sound file all of the buffer's of sound data.
Directions m_direction
Sound I/O direction.
Definition: sound.h:302
#define PPLUGIN_STATIC_LOAD(serviceName, serviceType)
Definition: plugin.h:123
virtual bool RawRead(void *data, PINDEX size)
void SetBufferCountFromMS(unsigned milliseconds)
virtual PBoolean WaitForPlayCompletion()
Block calling thread until the sound play begun with PlaySound() or PlayFile() has completed...
This is a channel that operates indirectly through another channel(s).
Definition: indchan.h:45
virtual PBoolean SetFormat(unsigned numChannels=1, unsigned sampleRate=8000, unsigned bitsPerSample=16)
Set the format for play/record.
static PSoundChannel * CreateChannelByName(const PString &deviceName, Directions direction, PPluginManager *pluginMgr=NULL)
virtual PBoolean Write(const void *buf, PINDEX len)
Low level write to the channel.
PAdaptiveDelay m_Pacing
Definition: sound.h:806
virtual unsigned GetSampleSize() const
Get the sample size in bits per sample.
virtual PBoolean WaitForAllRecordBuffersFull()
Block the thread until all of the record buffer allocated has been filled.
virtual PBoolean GetVolume(unsigned &volume)
Get the volume of the play/read process.
This is an array collection class of PString objects.
Definition: pstring.h:2365
PChannel * readChannel
Channel for read operations.
Definition: indchan.h:362
virtual PBoolean StartRecording()
Start filling record buffers.
virtual PBoolean AreAllRecordBuffersFull()
Determine if all of the record buffer allocated has been filled.
static PStringArray GetDriverNames(PPluginManager *pluginMgr=NULL)
Get the list of available sound drivers (plug-ins)
PSoundChannel * GetSoundChannel() const
Definition: sound.h:748
virtual PBoolean Close()
Close the channel.
virtual PBoolean Abort()
Abort the background playing/recording of the sound channel.
DWORD GetErrorCode() const
Get the platform dependent error code from the last file load.
Definition: sound.h:145
unsigned m_bytesPerSample
Definition: sound.h:800
unsigned m_channels
Number of channels eg mono/stereo.
Definition: sound.h:305
#define PCREATE_PLUGIN_DEVICE(serviceType)
Definition: plugin.h:92
PBoolean Load(const PFilePath &filename)
Load a platform dependent sound file (eg .WAV file for Win32) into the object.
virtual PBoolean IsRecordBufferFull()
Determine if a record buffer has been filled, so that the next Read() call will not block...
virtual PBoolean WaitForRecordBufferFull()
Block the thread until a record buffer has been filled, so that the next Read() call will not block...
PINDEX GetFormatInfoSize() const
Get the size of the platform dependent format info.
Definition: sound.h:148
A class representing a sound.
Definition: sound.h:53
unsigned m_bufferCount
Definition: sound.h:802
Array of unsigned characters.
Definition: array.h:605
static PString TestPlayer(const Params ¶ms, const PNotifier &progress=PNotifier(), const char *toneSpec=NULL)
Test the specified device for playing.
PBoolean Play()
Play the sound on the default sound device.
virtual PBoolean WaitForAllRecordBuffersFull()
Block the thread until all of the record buffer allocated has been filled.
virtual PBoolean SetBuffers(PINDEX size, PINDEX)
Set the internal buffers for the sound channel I/O.
virtual unsigned GetSampleRate() const
Get the sample rate in samples per second.
static PString GetDefaultDevice(Directions dir)
Get the name for the default sound devices/driver that is on this platform.
virtual PBoolean SetFormat(unsigned numChannels, unsigned sampleRate, unsigned bitsPerSample)
Set the format for play/record.
static PSoundChannel * CreateChannel(const PString &driverName, PPluginManager *pluginMgr=NULL)
Create the sound channel that corresponds to the specified driver name.
static bool PlayFile(const PFilePath &file, bool wait=true, unsigned volume=100)
Play a sound file to the default device.
P_REMOVE_VIRTUAL(PBoolean, Open(const PString &, Directions, unsigned, unsigned, unsigned), false)
virtual PINDEX GetSize() const
Get the current size of the container.
bool PBoolean
Definition: object.h:174
bool m_muted
Definition: sound.h:807
PDECLARE_MUTEX(m_writeMutex)
PNotifierTemplate< P_INT_PTR > PNotifier
Definition: notifier.h:145
The character string class.
Definition: pstring.h:108
DWORD dwLastError
Last error code for Load()/Save() functions.
Definition: sound.h:198
virtual PBoolean GetBuffers(PINDEX &size, PINDEX &count)
Get the internal buffers for the sound channel I/O.
Class for implementing an "adaptive" delay.
Definition: delaychan.h:48
unsigned m_channels
Definition: sound.h:799
Directions m_activeDirection
This is the direction that this sound channel is opened for use in.
Definition: sound.h:754
void SetFormat(unsigned numChannels, unsigned sampleRate, unsigned bitsPerSample)
Set the internal sound format to linear PCM at the specification in the parameters.
virtual unsigned GetChannels() const
Get the number of channels (mono/stereo) in the sound.
PBoolean Save(const PFilePath &filename)
Save a platform dependent sound file (eg .WAV file for Win32) from the object.
virtual bool GetMute(bool &mute)
Get the mute state of the play/read process.
virtual PBoolean HasPlayCompleted()
Indicate if the sound play begun with PlayBuffer() or PlayFile() has completed.
PPluginManager * m_pluginMgr
Definition: sound.h:312
virtual PBoolean GetBuffers(PINDEX &size, PINDEX &count)
Get the internal buffers for the sound channel I/O.
unsigned m_sampleRate
Samples per second.
Definition: sound.h:306
unsigned GetEncoding() const
Get the current encoding.
Definition: sound.h:133
static const PString & Empty()
Return an empty string.
unsigned sampleSize
Number of bits per sample.
Definition: sound.h:196
virtual PBoolean WaitForRecordBufferFull()
Block the thread until a record buffer has been filled, so that the next Read() call will not block...
virtual PBoolean IsRecordBufferFull()
Determine if a record buffer has been filled, so that the next Read() call will not block...
static bool ConvertPCM(const short *srcPtr, PINDEX &srcSize, unsigned srcRate, unsigned srcChannels, short *dstPtr, PINDEX &dstSize, unsigned dstRate, unsigned dstChannels)
Convert PCM data sample rates and channel depth.
PBYTEArray formatInfo
Full info on the format (platform dependent)
Definition: sound.h:200
virtual bool SetMute(bool mute)
Set the mute state of the play/read process.
virtual unsigned GetChannels() const
Get the number of channels (mono/stereo) in the sound.
Params(Directions dir=Player, const PString &device=PString::Empty(), const PString &driver=PString::Empty(), unsigned channels=1, unsigned sampleRate=8000, unsigned bitsPerSample=16, unsigned bufferSize=DefaultBufferSize, unsigned bufferCount=DefaultBufferCount, PPluginManager *pluginMgr=NULL)
static PStringArray GetDeviceNames(const PString &driverName, Directions direction, PPluginManager *pluginMgr=NULL)
Definition: sound.h:354
unsigned sampleRate
Samples per second.
Definition: sound.h:194
virtual const char * GetDirectionText() const
Get text representing the direction of the channel.
Definition: sound.h:459
unsigned m_bufferCount
Number of buffers to queue.
Definition: sound.h:311
virtual PBoolean PlaySound(const PSound &sound, PBoolean wait=true)
Play a sound to the open device.
virtual bool GetMute(bool &mute)
Get the mute state of the play/read process.
virtual unsigned GetSampleRate() const
Get the sample rate in samples per second.
PINDEX m_bufferPos
Definition: sound.h:803
PSoundChannel()
Create a sound channel.
virtual bool SetMute(bool mute)
Set the mute state of the play/read process.
Parameters for opening a sound channel.
Definition: sound.h:289
unsigned numChannels
Number of channels eg mono/stereo.
Definition: sound.h:192
unsigned m_bitsPerSample
Number of bits per sample.
Definition: sound.h:307
virtual PBoolean RecordSound(PSound &sound)
Record into the sound object all of the buffer's of sound data.
virtual PBoolean SetBuffers(PINDEX size, PINDEX count=2)
Set the internal buffers for the sound channel I/O.
P_DECLARE_STREAMABLE_ENUM(Directions, Recorder, Player, Closed)
PString m_driver
Name of sound driver.
Definition: sound.h:304
unsigned encoding
Format code.
Definition: sound.h:190
unsigned GetSampleRate() const
Get the sample rate in samples per second.
Definition: sound.h:139
static PSoundChannel * CreateOpenedChannel(const Params ¶ms)
Create an opened sound channel that corresponds to the specified names.
virtual PBoolean SetVolume(unsigned volume)
Set the volume of the play/read process.
PBYTEArray m_buffer
Definition: sound.h:804
unsigned m_bufferSize
Definition: sound.h:801