PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
portaudio.h
Go to the documentation of this file.
1 /*
2  * portaudio.h
3  *
4  * PortAudio sound driver
5  *
6  * Portable Windows Library
7  *
8  * Copyright (C) 2013 Post Increment
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Windows Library.
21  *
22  * The Initial Developer of the Original Code is Post Increment
23  *
24  * Contributor(s): ______________________________________.
25  *
26  */
27 
28 
30 // PSound
31 
32 #ifndef _PSOUND_PORTAUDIO
33 #define _PSOUND_PORTAUDIO
34 
35 #include <portaudio.h>
36 
37 #ifdef P_PORTMIXER
38 #include <portmixer.h>
39 #endif
40 
42 {
43  public:
46  static PStringArray GetDeviceNames(PSoundChannel::Directions = Player);
47  bool Open(const Params & params);
48  bool Setup();
49  bool Close();
50  bool IsOpen() const;
51  bool Write(const void * buf, PINDEX len);
52  bool Read(void * buf, PINDEX len);
53  bool SetFormat(unsigned numChannels,
54  unsigned sampleRate,
55  unsigned bitsPerSample);
56  unsigned GetChannels() const;
57  unsigned GetSampleRate() const;
58  unsigned GetSampleSize() const;
59  bool SetBuffers(PINDEX size, PINDEX count);
60  bool GetBuffers(PINDEX & size, PINDEX & count);
61  bool PlaySound(const PSound & sound, bool wait);
62  bool PlayFile(const PFilePath & filename, bool wait);
63  bool HasPlayCompleted();
64  bool WaitForPlayCompletion();
65  bool RecordSound(PSound & sound);
66  bool RecordFile(const PFilePath & filename);
67  bool StartRecording();
68  bool IsRecordBufferFull();
72  bool Abort();
73  bool SetVolume(unsigned newVal);
74  bool GetVolume(unsigned &devVol);
75  bool SetMute(bool mute);
76  bool GetMute(bool & mute);
77 
78  public:
79  static PMutex & GetInitMutex();
80  static bool Initialise();
81 
82  bool OpenStream(unsigned numChannels, unsigned sampleRate, unsigned bitsPerSample);
83 
84  bool StartStream();
85  bool StopStream();
86 
87  // Overrides from class PChannel
88  virtual PString GetName() const;
89  // Return the name of the channel.
90 
92  // Get a text form of the last error encountered.
93 
94  protected:
101 
102  const PaDeviceInfo * m_deviceInfo;
105  bool m_started;
106  bool m_mute;
107  unsigned char * m_muteBuffer;
109 
110  PaStream * m_stream;
111  PaStreamParameters m_streamParms;
112 
113 #ifdef P_PORTMIXER
114  PxMixer * m_mixer;
115 #endif
116  int m_volume;
117 
120 };
121 
122 
123 #endif
124 
125 // End Of File ///////////////////////////////////////////////////////////////
bool GetMute(bool &mute)
Get the mute state of the play/read process.
bool IsRecordBufferFull()
Determine if a record buffer has been filled, so that the next Read() call will not block...
int m_bitsPerSample
Definition: portaudio.h:98
bool WaitForAllRecordBuffersFull()
Block the thread until all of the record buffer allocated has been filled.
Abstract class for a generalised sound channel, and an implementation of PSoundChannel for old code t...
Definition: sound.h:267
Definition: channel.h:255
bool WaitForRecordBufferFull()
Block the thread until a record buffer has been filled, so that the next Read() call will not block...
bool HasPlayCompleted()
Indicate if the sound play begun with PlayBuffer() or PlayFile() has completed.
int m_bytesPerSample
Definition: portaudio.h:99
bool PlaySound(const PSound &sound, bool wait)
Play a sound to the open device.
bool StartRecording()
Start filling record buffers.
bool Abort()
Abort the background playing/recording of the sound channel.
bool Write(const void *buf, PINDEX len)
Low level write to the channel.
static PStringArray GetDeviceNames(PSoundChannel::Directions=Player)
This class describes a full description for a file on the particular platform.
Definition: filepath.h:61
PINDEX m_muteBufferSize
Definition: portaudio.h:108
int m_playBufferCount
Definition: portaudio.h:119
bool IsOpen() const
Determine if the channel is currently open and read and write operations can be executed on it...
unsigned GetSampleRate() const
Get the sample rate in samples per second.
This is an array collection class of PString objects.
Definition: pstring.h:2365
int m_deviceId
Definition: portaudio.h:103
bool SetMute(bool mute)
Set the mute state of the play/read process.
int m_sampleFormat
Definition: portaudio.h:100
A class representing a sound.
Definition: sound.h:53
PString m_deviceName
Definition: portaudio.h:104
bool SetBuffers(PINDEX size, PINDEX count)
Set the internal buffers for the sound channel I/O.
bool RecordFile(const PFilePath &filename)
Record into the platform dependent sound file all of the buffer&#39;s of sound data.
bool Read(void *buf, PINDEX len)
Low level read from the channel.
Definition: portaudio.h:41
bool GetBuffers(PINDEX &size, PINDEX &count)
Get the internal buffers for the sound channel I/O.
static bool Initialise()
bool m_started
Definition: portaudio.h:105
bool SetVolume(unsigned newVal)
Set the volume of the play/read process.
PaStream * m_stream
Definition: portaudio.h:110
int m_playBufferSize
Definition: portaudio.h:118
PString GetErrorText(ErrorGroup group=NumErrorGroups) const
Get error message description.
The character string class.
Definition: pstring.h:108
PMutex m_mutex
Definition: portaudio.h:95
bool Open(const Params &params)
Open the specified device for playing or recording.
int m_sampleRate
Definition: portaudio.h:97
PaStreamParameters m_streamParms
Definition: portaudio.h:111
bool OpenStream(unsigned numChannels, unsigned sampleRate, unsigned bitsPerSample)
ErrorGroup
Error groups.
Definition: channel.h:251
const PaDeviceInfo * m_deviceInfo
Definition: portaudio.h:102
This class defines a thread mutual exclusion object.
Definition: mutex.h:101
bool WaitForPlayCompletion()
Block calling thread until the sound play begun with PlaySound() or PlayFile() has completed...
virtual PString GetName() const
Get the name of the channel.
int m_volume
Definition: portaudio.h:116
bool m_mute
Definition: portaudio.h:106
unsigned char * m_muteBuffer
Definition: portaudio.h:107
unsigned GetSampleSize() const
Get the sample size in bits per sample.
Parameters for opening a sound channel.
Definition: sound.h:289
bool SetFormat(unsigned numChannels, unsigned sampleRate, unsigned bitsPerSample)
Set the format for play/record.
bool AreAllRecordBuffersFull()
Determine if all of the record buffer allocated has been filled.
bool Close()
Close the channel.
bool PlayFile(const PFilePath &filename, bool wait)
bool GetVolume(unsigned &devVol)
Get the volume of the play/read process.
int m_channels
Definition: portaudio.h:96
unsigned GetChannels() const
Get the number of channels (mono/stereo) in the sound.
bool RecordSound(PSound &sound)
Record into the sound object all of the buffer&#39;s of sound data.
static PMutex & GetInitMutex()