1 
2 #include <ptlib.h>
3 #include <ptlib/sound.h>
4 #include <ptlib/socket.h>
5 
6 //#if !P_USE_INLINES
7 //#include <ptlib/contain.inl>
8 //#endif
9 
10 #ifdef P_LINUX
11 #include <sys/soundcard.h>
12 #endif
13 
14 #ifdef P_FREEBSD
15 #if P_FREEBSD >= 500000
16 #include <sys/soundcard.h>
17 #else
18 #include <machine/soundcard.h>
19 #endif
20 #endif
21 
22 #if defined(P_OPENBSD) || defined(P_NETBSD)
23 #include <soundcard.h>
24 #endif
25 
26 class PSoundChannelESD: public PSoundChannel
27 {
28  public:
29     PSoundChannelESD();
30     void Construct();
31     PSoundChannelESD(const PString &device,
32                      PSoundChannel::Directions dir,
33                      unsigned numChannels,
34                      unsigned sampleRate,
35                      unsigned bitsPerSample);
36     ~PSoundChannelESD();
37     static PStringArray GetDeviceNames(PSoundChannel::Directions = Player);
38     static PString GetDefaultDevice(PSoundChannel::Directions);
39     PBoolean Open(const PString & _device,
40               Directions _dir,
41               unsigned _numChannels,
42               unsigned _sampleRate,
43               unsigned _bitsPerSample);
44     PBoolean Setup();
45     PBoolean Close();
46 //    PBoolean IsOpen() const;
47     PBoolean Write(const void * buf, PINDEX len);
48     PBoolean Read(void * buf, PINDEX len);
49     PBoolean SetFormat(unsigned numChannels,
50                    unsigned sampleRate,
51                    unsigned bitsPerSample);
52 //    unsigned GetChannels() const;
53 //    unsigned GetSampleRate() const;
54 //    unsigned GetSampleSize() const;
55     PBoolean SetBuffers(PINDEX size, PINDEX count);
56     PBoolean GetBuffers(PINDEX & size, PINDEX & count);
57     PBoolean PlaySound(const PSound & sound, PBoolean wait);
58     PBoolean PlayFile(const PFilePath & filename, PBoolean wait);
59     PBoolean HasPlayCompleted();
60     PBoolean WaitForPlayCompletion();
61     PBoolean RecordSound(PSound & sound);
62     PBoolean RecordFile(const PFilePath & filename);
63     PBoolean StartRecording();
64     PBoolean IsRecordBufferFull();
65     PBoolean AreAllRecordBuffersFull();
66     PBoolean WaitForRecordBufferFull();
67     PBoolean WaitForAllRecordBuffersFull();
68     PBoolean Abort();
69     PBoolean SetVolume(unsigned newVal);
70     PBoolean GetVolume(unsigned &devVol);
71 
72   protected:
73     unsigned mNumChannels;
74     unsigned mSampleRate;
75     unsigned mBitsPerSample;
76     unsigned actualSampleRate;
77     Directions direction;
78     PString device;
79     PBoolean isInitialised;
80 };
81