2 #include <ptlib/sound.h>
4 #define ALSA_PCM_NEW_HW_PARAMS_API 1
5 #include <alsa/asoundlib.h>
7 class PAudioDelay
: public PObject
9 PCLASSINFO(PAudioDelay
, PObject
);
23 #define MIN_HEADROOM 30
24 #define MAX_HEADROOM 60
26 class SoundHandleEntry
: public PObject
{
28 PCLASSINFO(SoundHandleEntry
, PObject
)
38 unsigned bitsPerSample
;
39 unsigned fragmentValue
;
43 #define LOOPBACK_BUFFER_SIZE 5000
44 #define BYTESINBUF ((startptr<endptr)?(endptr-startptr):(LOOPBACK_BUFFER_SIZE+endptr-startptr))
48 class PSoundChannelALSA
: public PSoundChannel
{
52 PSoundChannelALSA(const PString
&device
,
53 PSoundChannel::Directions dir
,
56 unsigned bitsPerSample
);
58 static PStringArray
GetDeviceNames(PSoundChannel::Directions
);
59 static PString
GetDefaultDevice(PSoundChannel::Directions
);
60 BOOL
Open(const PString
& _device
,
62 unsigned _numChannels
,
64 unsigned _bitsPerSample
);
67 BOOL
Write(const void * buf
, PINDEX len
);
68 BOOL
Read(void * buf
, PINDEX len
);
69 BOOL
SetFormat(unsigned numChannels
,
71 unsigned bitsPerSample
);
72 unsigned GetChannels() const;
73 unsigned GetSampleRate() const;
74 unsigned GetSampleSize() const;
75 BOOL
SetBuffers(PINDEX size
, PINDEX count
);
76 BOOL
GetBuffers(PINDEX
& size
, PINDEX
& count
);
77 BOOL
PlaySound(const PSound
& sound
, BOOL wait
);
78 BOOL
PlayFile(const PFilePath
& filename
, BOOL wait
);
79 BOOL
HasPlayCompleted();
80 BOOL
WaitForPlayCompletion();
81 BOOL
RecordSound(PSound
& sound
);
82 BOOL
RecordFile(const PFilePath
& filename
);
83 BOOL
StartRecording();
84 BOOL
IsRecordBufferFull();
85 BOOL
AreAllRecordBuffersFull();
86 BOOL
WaitForRecordBufferFull();
87 BOOL
WaitForAllRecordBuffersFull();
89 BOOL
SetVolume (unsigned);
90 BOOL
GetVolume (unsigned &);
95 static void UpdateDictionary(PSoundChannel::Directions
);
96 BOOL
Volume (BOOL
, unsigned, unsigned &);
97 PSoundChannel::Directions direction
;
99 unsigned mNumChannels
;
100 unsigned mSampleRate
;
101 unsigned mBitsPerSample
;
104 snd_pcm_t
*os_handle
; /* Handle, different from the PChannel handle */
109 /**number of 30 (or 20) ms long sound intervals stored by ALSA. Typically, 2.*/
110 PINDEX storedPeriods
;
112 /**Total number of bytes of audio stored by ALSA. Typically, 2*480 or 960.*/
115 /** Number of bytes in a ALSA frame. a frame may only be 4ms long*/