Removed printf that was interpreted as a trigraph
[pwlib.git] / plugins / sound_alsa / sound_alsa.h
blobb7042bd9396ddd00ccb4e3d24441f9f807a23ec8
1 #include <ptlib.h>
3 #define ALSA_PCM_NEW_HW_PARAMS_API 1
4 #include <alsa/asoundlib.h>
6 class PAudioDelay : public PObject
8 PCLASSINFO(PAudioDelay, PObject);
10 public:
11 PAudioDelay();
12 BOOL Delay(int time);
13 void Restart();
14 int GetError();
16 protected:
17 PTime previousTime;
18 BOOL firstTime;
19 int error;
22 #define MIN_HEADROOM 30
23 #define MAX_HEADROOM 60
25 class SoundHandleEntry : public PObject {
27 PCLASSINFO(SoundHandleEntry, PObject)
29 public:
30 SoundHandleEntry();
32 int handle;
33 int direction;
35 unsigned numChannels;
36 unsigned sampleRate;
37 unsigned bitsPerSample;
38 unsigned fragmentValue;
39 BOOL isInitialised;
42 #define LOOPBACK_BUFFER_SIZE 5000
43 #define BYTESINBUF ((startptr<endptr)?(endptr-startptr):(LOOPBACK_BUFFER_SIZE+endptr-startptr))
45 class PSoundChannelALSA: public PSoundChannel
47 public:
48 PSoundChannelALSA();
49 void Construct();
50 PSoundChannelALSA(const PString &device,
51 PSoundChannel::Directions dir,
52 unsigned numChannels,
53 unsigned sampleRate,
54 unsigned bitsPerSample);
55 ~PSoundChannelALSA();
56 static PStringArray GetDeviceNames(PSoundChannel::Directions);
57 static PString GetDefaultDevice(PSoundChannel::Directions);
58 BOOL Open(const PString & _device,
59 Directions _dir,
60 unsigned _numChannels,
61 unsigned _sampleRate,
62 unsigned _bitsPerSample);
63 BOOL Setup();
64 BOOL Close();
65 BOOL Write(const void * buf, PINDEX len);
66 BOOL Read(void * buf, PINDEX len);
67 BOOL SetFormat(unsigned numChannels,
68 unsigned sampleRate,
69 unsigned bitsPerSample);
70 unsigned GetChannels() const;
71 unsigned GetSampleRate() const;
72 unsigned GetSampleSize() const;
73 BOOL SetBuffers(PINDEX size, PINDEX count);
74 BOOL GetBuffers(PINDEX & size, PINDEX & count);
75 BOOL PlaySound(const PSound & sound, BOOL wait);
76 BOOL PlayFile(const PFilePath & filename, BOOL wait);
77 BOOL HasPlayCompleted();
78 BOOL WaitForPlayCompletion();
79 BOOL RecordSound(PSound & sound);
80 BOOL RecordFile(const PFilePath & filename);
81 BOOL StartRecording();
82 BOOL IsRecordBufferFull();
83 BOOL AreAllRecordBuffersFull();
84 BOOL WaitForRecordBufferFull();
85 BOOL WaitForAllRecordBuffersFull();
86 BOOL Abort();
87 BOOL SetVolume (unsigned);
88 BOOL GetVolume (unsigned &);
89 BOOL IsOpen() const;
91 private:
93 BOOL Volume (BOOL, unsigned, unsigned &);
94 PSoundChannel::Directions direction;
95 PString device;
96 unsigned mNumChannels;
97 unsigned mSampleRate;
98 unsigned mBitsPerSample;
99 BOOL isInitialised;
101 snd_pcm_t *os_handle; /* Handle, different from the PChannel handle */
102 int card_nr;
103 int frame_bytes; /* Number of bytes in a frame */
104 snd_pcm_uframes_t period_size;
105 unsigned int periods;
106 PMutex device_mutex;