1 /*
2 * dummyaudio.cxx
3 *
4 * Sound driver implementation.
5 *
6 * Portable Windows Library
7 *
8 * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
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 Equivalence Pty. Ltd.
23 *
24 * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25 * All Rights Reserved.
26 *
27 * Contributor(s): ______________________________________.
28 *
29 * $Revision: 20385 $
30 * $Author: rjongbloed $
31 * $Date: 2008-06-04 05:40:38 -0500 (Wed, 04 Jun 2008) $
32 */
33
34 #pragma implementation "sound.h"
35
36 #include <ptlib.h>
37
PSound(unsigned channels,unsigned samplesPerSecond,unsigned bitsPerSample,PINDEX bufferSize,const BYTE * buffer)38 PSound::PSound(unsigned channels,
39 unsigned samplesPerSecond,
40 unsigned bitsPerSample,
41 PINDEX bufferSize,
42 const BYTE * buffer)
43 {
44 encoding = 0;
45 numChannels = channels;
46 sampleRate = samplesPerSecond;
47 sampleSize = bitsPerSample;
48 SetSize(bufferSize);
49 if (buffer != NULL)
50 memcpy(GetPointer(), buffer, bufferSize);
51 }
52
53
PSound(const PFilePath & filename)54 PSound::PSound(const PFilePath & filename)
55 {
56 encoding = 0;
57 numChannels = 1;
58 sampleRate = 8000;
59 sampleSize = 16;
60 Load(filename);
61 }
62
63
operator =(const PBYTEArray & data)64 PSound & PSound::operator=(const PBYTEArray & data)
65 {
66 PBYTEArray::operator=(data);
67 return *this;
68 }
69
70
SetFormat(unsigned channels,unsigned samplesPerSecond,unsigned bitsPerSample)71 void PSound::SetFormat(unsigned channels,
72 unsigned samplesPerSecond,
73 unsigned bitsPerSample)
74 {
75 encoding = 0;
76 numChannels = channels;
77 sampleRate = samplesPerSecond;
78 sampleSize = bitsPerSample;
79 formatInfo.SetSize(0);
80 }
81
82
Load(const PFilePath &)83 PBoolean PSound::Load(const PFilePath & /*filename*/)
84 {
85 return PFalse;
86 }
87
88
Save(const PFilePath &)89 PBoolean PSound::Save(const PFilePath & /*filename*/)
90 {
91 return PFalse;
92 }
93
Play(const PString & device)94 PBoolean PSound::Play(const PString & device)
95 {
96
97 PSoundChannel channel(device,
98 PSoundChannel::Player);
99 if (!channel.IsOpen())
100 return PFalse;
101
102 return channel.PlaySound(*this, PTrue);
103 }
104
105 ///////////////////////////////////////////////////////////////////////////////
106
PSoundChannel()107 PSoundChannel::PSoundChannel()
108 {
109 Construct();
110 }
111
112
PSoundChannel(const PString & device,Directions dir,unsigned numChannels,unsigned sampleRate,unsigned bitsPerSample)113 PSoundChannel::PSoundChannel(const PString & device,
114 Directions dir,
115 unsigned numChannels,
116 unsigned sampleRate,
117 unsigned bitsPerSample)
118 {
119 Construct();
120 Open(device, dir, numChannels, sampleRate, bitsPerSample);
121 }
122
123
Construct()124 void PSoundChannel::Construct()
125 {
126 }
127
128
~PSoundChannel()129 PSoundChannel::~PSoundChannel()
130 {
131 Close();
132 }
133
134
GetDeviceNames(Directions)135 PStringArray PSoundChannel::GetDeviceNames(Directions /*dir*/)
136 {
137 PStringArray array;
138
139 array[0] = "/dev/audio";
140 array[1] = "/dev/dsp";
141
142 return array;
143 }
144
145
GetDefaultDevice(Directions)146 PString PSoundChannel::GetDefaultDevice(Directions /*dir*/)
147 {
148 return "/dev/audio";
149 }
150
151
Open(const PString & device,Directions dir,unsigned numChannels,unsigned sampleRate,unsigned bitsPerSample)152 PBoolean PSoundChannel::Open(const PString & device,
153 Directions dir,
154 unsigned numChannels,
155 unsigned sampleRate,
156 unsigned bitsPerSample)
157 {
158 Close();
159
160 if (!ConvertOSError(os_handle = ::open(device, dir == Player ? O_RDONLY : O_WRONLY)))
161 return PFalse;
162
163 return SetFormat(numChannels, sampleRate, bitsPerSample);
164 }
165
166
Close()167 PBoolean PSoundChannel::Close()
168 {
169 return PChannel::Close();
170 }
171
172
SetFormat(unsigned numChannels,unsigned sampleRate,unsigned bitsPerSample)173 PBoolean PSoundChannel::SetFormat(unsigned numChannels,
174 unsigned sampleRate,
175 unsigned bitsPerSample)
176 {
177 Abort();
178
179 PAssert(numChannels >= 1 && numChannels <= 2, PInvalidParameter);
180 PAssert(bitsPerSample == 8 || bitsPerSample == 16, PInvalidParameter);
181
182 return PTrue;
183 }
184
185
SetBuffers(PINDEX size,PINDEX count)186 PBoolean PSoundChannel::SetBuffers(PINDEX size, PINDEX count)
187 {
188 Abort();
189
190 PAssert(size > 0 && count > 0 && count < 65536, PInvalidParameter);
191
192 return PTrue;
193 }
194
195
GetBuffers(PINDEX & size,PINDEX & count)196 PBoolean PSoundChannel::GetBuffers(PINDEX & size, PINDEX & count)
197 {
198 return PTrue;
199 }
200
201
Write(const void * buffer,PINDEX length)202 PBoolean PSoundChannel::Write(const void * buffer, PINDEX length)
203 {
204 return PChannel::Write(buffer, length);
205 }
206
207
PlaySound(const PSound & sound,PBoolean wait)208 PBoolean PSoundChannel::PlaySound(const PSound & sound, PBoolean wait)
209 {
210 Abort();
211
212 if (!Write((const BYTE *)sound, sound.GetSize()))
213 return PFalse;
214
215 if (wait)
216 return WaitForPlayCompletion();
217
218 return PTrue;
219 }
220
221
PlayFile(const PFilePath & filename,PBoolean wait)222 PBoolean PSoundChannel::PlayFile(const PFilePath & filename, PBoolean wait)
223 {
224 return PTrue;
225 }
226
227
HasPlayCompleted()228 PBoolean PSoundChannel::HasPlayCompleted()
229 {
230 return PTrue;
231 }
232
233
WaitForPlayCompletion()234 PBoolean PSoundChannel::WaitForPlayCompletion()
235 {
236 return PTrue;
237 }
238
239
Read(void * buffer,PINDEX length)240 PBoolean PSoundChannel::Read(void * buffer, PINDEX length)
241 {
242 return PChannel::Read(buffer, length);
243 }
244
245
RecordSound(PSound & sound)246 PBoolean PSoundChannel::RecordSound(PSound & sound)
247 {
248 return PTrue;
249 }
250
251
RecordFile(const PFilePath & filename)252 PBoolean PSoundChannel::RecordFile(const PFilePath & filename)
253 {
254 return PTrue;
255 }
256
257
StartRecording()258 PBoolean PSoundChannel::StartRecording()
259 {
260 return PTrue;
261 }
262
263
IsRecordBufferFull()264 PBoolean PSoundChannel::IsRecordBufferFull()
265 {
266 return PTrue;
267 }
268
269
AreAllRecordBuffersFull()270 PBoolean PSoundChannel::AreAllRecordBuffersFull()
271 {
272 return PTrue;
273 }
274
275
WaitForRecordBufferFull()276 PBoolean PSoundChannel::WaitForRecordBufferFull()
277 {
278 if (os_handle < 0) {
279 return PFalse;
280 }
281
282 return PXSetIOBlock(PXReadBlock, readTimeout);
283 }
284
285
WaitForAllRecordBuffersFull()286 PBoolean PSoundChannel::WaitForAllRecordBuffersFull()
287 {
288 return PFalse;
289 }
290
291
Abort()292 PBoolean PSoundChannel::Abort()
293 {
294 return PTrue;
295 }
296
SetVolume(unsigned newVolume)297 PBoolean PSoundChannel::SetVolume(unsigned newVolume)
298 {
299 return PFalse;
300 }
301
GetVolume(unsigned & volume)302 PBoolean PSoundChannel::GetVolume(unsigned & volume)
303 {
304 return PFalse;
305 }
306
307
308 // End of file
309
310