Fixed DevStudio 2003 build with memory check code.
[pwlib.git] / plugins / sound_alsa / sound_alsa.h
blob3303178d5f83af837244c000024ac45567678732
1 #include <ptlib.h>
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);
11 public:
12 PAudioDelay();
13 BOOL Delay(int time);
14 void Restart();
15 int GetError();
17 protected:
18 PTime previousTime;
19 BOOL firstTime;
20 int error;
23 #define MIN_HEADROOM 30
24 #define MAX_HEADROOM 60
26 class SoundHandleEntry : public PObject {
28 PCLASSINFO(SoundHandleEntry, PObject)
30 public:
31 SoundHandleEntry();
33 int handle;
34 int direction;
36 unsigned numChannels;
37 unsigned sampleRate;
38 unsigned bitsPerSample;
39 unsigned fragmentValue;
40 BOOL isInitialised;
43 #define LOOPBACK_BUFFER_SIZE 5000
44 #define BYTESINBUF ((startptr<endptr)?(endptr-startptr):(LOOPBACK_BUFFER_SIZE+endptr-startptr))
48 class PSoundChannelALSA : public PSoundChannel {
49 public:
50 PSoundChannelALSA();
51 void Construct();
52 PSoundChannelALSA(const PString &device,
53 PSoundChannel::Directions dir,
54 unsigned numChannels,
55 unsigned sampleRate,
56 unsigned bitsPerSample);
57 ~PSoundChannelALSA();
58 static PStringArray GetDeviceNames(PSoundChannel::Directions);
59 static PString GetDefaultDevice(PSoundChannel::Directions);
60 BOOL Open(const PString & _device,
61 Directions _dir,
62 unsigned _numChannels,
63 unsigned _sampleRate,
64 unsigned _bitsPerSample);
65 BOOL Setup();
66 BOOL Close();
67 BOOL Write(const void * buf, PINDEX len);
68 BOOL Read(void * buf, PINDEX len);
69 BOOL SetFormat(unsigned numChannels,
70 unsigned sampleRate,
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();
88 BOOL Abort();
89 BOOL SetVolume (unsigned);
90 BOOL GetVolume (unsigned &);
91 BOOL IsOpen() const;
93 private:
95 static void UpdateDictionary(PSoundChannel::Directions);
96 BOOL Volume (BOOL, unsigned, unsigned &);
97 PSoundChannel::Directions direction;
98 PString device;
99 unsigned mNumChannels;
100 unsigned mSampleRate;
101 unsigned mBitsPerSample;
102 BOOL isInitialised;
104 snd_pcm_t *os_handle; /* Handle, different from the PChannel handle */
105 int card_nr;
107 PMutex device_mutex;
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.*/
113 PINDEX storedSize;
115 /** Number of bytes in a ALSA frame. a frame may only be 4ms long*/
116 int frameBytes;