xref: /haiku/src/kits/game/GameSound.cpp (revision 93a78ecaa45114d68952d08c4778f073515102f2)
1 /*
2  * Copyright 2001-2002, Haiku Inc.
3  * Authors:
4  *		Christopher ML Zumwalt May (zummy@users.sf.net)
5  *
6  * Distributed under the terms of the MIT License.
7  */
8 
9 #include <stdio.h>
10 #include <string.h>
11 
12 #include <GameSound.h>
13 
14 #include "GameSoundBuffer.h"
15 #include "GameSoundDevice.h"
16 
17 
18 using std::nothrow;
19 
20 // Local Defines ---------------------------------------------------------------
21 
22 // BGameSound class ------------------------------------------------------------
23 BGameSound::BGameSound(BGameSoundDevice *device)
24 		:	fSound(-1)
25 {
26 	fDevice = GetDefaultDevice();
27 	fInitError = fDevice->InitCheck();
28 }
29 
30 
31 BGameSound::BGameSound(const BGameSound &other)
32 		:	fSound(-1)
33 {
34 	memcpy(&fFormat, &other.fFormat, sizeof(gs_audio_format));
35 	fDevice = GetDefaultDevice();
36 
37 	fInitError = fDevice->InitCheck();
38 }
39 
40 
41 BGameSound::~BGameSound()
42 {
43 	if (fSound >= 0)
44 		fDevice->ReleaseBuffer(fSound);
45 
46 	ReleaseDevice();
47 }
48 
49 
50 status_t
51 BGameSound::InitCheck() const
52 {
53 	return fInitError;
54 }
55 
56 
57 BGameSoundDevice *
58 BGameSound::Device() const
59 {
60 	return fDevice;
61 }
62 
63 
64 gs_id
65 BGameSound::ID() const
66 {
67 	return fSound;
68 }
69 
70 
71 const gs_audio_format &
72 BGameSound::Format() const
73 {
74 	return fDevice->Format(fSound);
75 }
76 
77 
78 status_t
79 BGameSound::StartPlaying()
80 {
81 	fDevice->StartPlaying(fSound);
82 	return B_OK;
83 }
84 
85 
86 bool
87 BGameSound::IsPlaying()
88 {
89 	return fDevice->IsPlaying(fSound);
90 }
91 
92 
93 status_t
94 BGameSound::StopPlaying()
95 {
96 	fDevice->StopPlaying(fSound);
97 	return B_OK;
98 }
99 
100 
101 status_t
102 BGameSound::SetGain(float gain,
103 					bigtime_t duration)
104 {
105 	gs_attribute attribute;
106 
107 	attribute.attribute = B_GS_GAIN;
108 	attribute.value = gain;
109 	attribute.duration = duration;
110 	attribute.flags = 0;
111 
112 	return fDevice->SetAttributes(fSound, &attribute, 1);
113 }
114 
115 
116 status_t
117 BGameSound::SetPan(float pan,
118 				   bigtime_t duration)
119 {
120 	gs_attribute attribute;
121 
122 	attribute.attribute = B_GS_PAN;
123 	attribute.value = pan;
124 	attribute.duration = duration;
125 	attribute.flags = 0;
126 
127 	return fDevice->SetAttributes(fSound, &attribute, 1);
128 }
129 
130 
131 float
132 BGameSound::Gain()
133 {
134 	gs_attribute attribute;
135 
136 	attribute.attribute = B_GS_GAIN;
137 	attribute.flags = 0;
138 
139 	if (fDevice->GetAttributes(fSound, &attribute, 1) != B_OK)
140 		return 0.0;
141 
142 	return attribute.value;
143 }
144 
145 
146 float
147 BGameSound::Pan()
148 {
149 	gs_attribute attribute;
150 
151 	attribute.attribute = B_GS_PAN;
152 	attribute.flags = 0;
153 
154 	if (fDevice->GetAttributes(fSound, &attribute, 1) != B_OK)
155 		return 0.0;
156 
157 	return attribute.value;
158 }
159 
160 
161 status_t
162 BGameSound::SetAttributes(gs_attribute *inAttributes,
163 						  size_t inAttributeCount)
164 {
165 	return fDevice->SetAttributes(fSound, inAttributes, inAttributeCount);
166 }
167 
168 
169 status_t
170 BGameSound::GetAttributes(gs_attribute *outAttributes,
171 						  size_t inAttributeCount)
172 {
173 	return fDevice->GetAttributes(fSound, outAttributes, inAttributeCount);
174 }
175 
176 
177 status_t
178 BGameSound::Perform(int32 selector,
179 					void *data)
180 {
181 	return B_ERROR;
182 }
183 
184 
185 void *
186 BGameSound::operator new(size_t size)
187 {
188 	return ::operator new(size);
189 }
190 
191 
192 void *
193 BGameSound::operator new(size_t size, const std::nothrow_t &nt) throw()
194 {
195 	return ::operator new(size, nt);
196 }
197 
198 
199 void
200 BGameSound::operator delete(void *ptr)
201 {
202 	::operator delete(ptr);
203 }
204 
205 
206 #if !__MWERKS__
207 //	there's a bug in MWCC under R4.1 and earlier
208 void
209 BGameSound::operator delete(void *ptr, const std::nothrow_t &nt) throw()
210 {
211 	::operator delete(ptr, nt);
212 }
213 #endif
214 
215 
216 status_t
217 BGameSound::SetMemoryPoolSize(size_t in_poolSize)
218 {
219 	return B_ERROR;
220 }
221 
222 
223 status_t
224 BGameSound::LockMemoryPool(bool in_lockInCore)
225 {
226 	return B_ERROR;
227 }
228 
229 
230 int32
231 BGameSound::SetMaxSoundCount(int32 in_maxCount)
232 {
233 	return in_maxCount;
234 }
235 
236 
237 status_t
238 BGameSound::SetInitError(status_t in_initError)
239 {
240 	fInitError = in_initError;
241 	return B_OK;
242 }
243 
244 
245 status_t
246 BGameSound::Init(gs_id handle)
247 {
248 	if (fSound < 0) fSound = handle;
249 
250 	return B_OK;
251 }
252 
253 /*
254 BGameSound &
255 BGameSound::operator=(const BGameSound &other)
256 {
257 	if (fSound)
258 		fDevice->ReleaseBuffer(fSound);
259 
260 	fSound = other.fSound;
261 	fInitError = other.fInitError;
262 
263 	return this;
264 }
265 */
266 
267 /* unimplemented for protection of the user:
268  *
269  * BGameSound::BGameSound()
270  */
271 
272 
273 status_t
274 BGameSound::_Reserved_BGameSound_0(int32 arg, ...)
275 {
276 	return B_ERROR;
277 }
278 
279 
280 status_t
281 BGameSound::_Reserved_BGameSound_1(int32 arg, ...)
282 {
283 	return B_ERROR;
284 }
285 
286 
287 status_t
288 BGameSound::_Reserved_BGameSound_2(int32 arg, ...)
289 {
290 	return B_ERROR;
291 }
292 
293 
294 status_t
295 BGameSound::_Reserved_BGameSound_3(int32 arg, ...)
296 {
297 	return B_ERROR;
298 }
299 
300 
301 status_t
302 BGameSound::_Reserved_BGameSound_4(int32 arg, ...)
303 {
304 	return B_ERROR;
305 }
306 
307 
308 status_t
309 BGameSound::_Reserved_BGameSound_5(int32 arg, ...)
310 {
311 	return B_ERROR;
312 }
313 
314 
315 status_t
316 BGameSound::_Reserved_BGameSound_6(int32 arg, ...)
317 {
318 	return B_ERROR;
319 }
320 
321 
322 status_t
323 BGameSound::_Reserved_BGameSound_7(int32 arg, ...)
324 {
325 	return B_ERROR;
326 }
327 
328 
329 status_t
330 BGameSound::_Reserved_BGameSound_8(int32 arg, ...)
331 {
332 	return B_ERROR;
333 }
334 
335 
336 status_t
337 BGameSound::_Reserved_BGameSound_9(int32 arg, ...)
338 {
339 	return B_ERROR;
340 }
341 
342 
343 status_t
344 BGameSound::_Reserved_BGameSound_10(int32 arg, ...)
345 {
346 	return B_ERROR;
347 }
348 
349 
350 status_t
351 BGameSound::_Reserved_BGameSound_11(int32 arg, ...)
352 {
353 	return B_ERROR;
354 }
355 
356 
357 status_t
358 BGameSound::_Reserved_BGameSound_12(int32 arg, ...)
359 {
360 	return B_ERROR;
361 }
362 
363 
364 status_t
365 BGameSound::_Reserved_BGameSound_13(int32 arg, ...)
366 {
367 	return B_ERROR;
368 }
369 
370 
371 status_t
372 BGameSound::_Reserved_BGameSound_14(int32 arg, ...)
373 {
374 	return B_ERROR;
375 }
376 
377 
378 status_t
379 BGameSound::_Reserved_BGameSound_15(int32 arg, ...)
380 {
381 	return B_ERROR;
382 }
383 
384 
385 status_t
386 BGameSound::_Reserved_BGameSound_16(int32 arg, ...)
387 {
388 	return B_ERROR;
389 }
390 
391 
392 status_t
393 BGameSound::_Reserved_BGameSound_17(int32 arg, ...)
394 {
395 	return B_ERROR;
396 }
397 
398 
399 status_t
400 BGameSound::_Reserved_BGameSound_18(int32 arg, ...)
401 {
402 	return B_ERROR;
403 }
404 
405 
406 status_t
407 BGameSound::_Reserved_BGameSound_19(int32 arg, ...)
408 {
409 	return B_ERROR;
410 }
411 
412 
413 status_t
414 BGameSound::_Reserved_BGameSound_20(int32 arg, ...)
415 {
416 	return B_ERROR;
417 }
418 
419 
420 status_t
421 BGameSound::_Reserved_BGameSound_21(int32 arg, ...)
422 {
423 	return B_ERROR;
424 }
425 
426 
427 status_t
428 BGameSound::_Reserved_BGameSound_22(int32 arg, ...)
429 {
430 	return B_ERROR;
431 }
432 
433 
434 status_t
435 BGameSound::_Reserved_BGameSound_23(int32 arg, ...)
436 {
437 	return B_ERROR;
438 }
439 
440 
441 status_t
442 BGameSound::_Reserved_BGameSound_24(int32 arg, ...)
443 {
444 	return B_ERROR;
445 }
446 
447 
448 status_t
449 BGameSound::_Reserved_BGameSound_25(int32 arg, ...)
450 {
451 	return B_ERROR;
452 }
453 
454 
455 status_t
456 BGameSound::_Reserved_BGameSound_26(int32 arg, ...)
457 {
458 	return B_ERROR;
459 }
460 
461 
462 status_t
463 BGameSound::_Reserved_BGameSound_27(int32 arg, ...)
464 {
465 	return B_ERROR;
466 }
467 
468 
469 status_t
470 BGameSound::_Reserved_BGameSound_28(int32 arg, ...)
471 {
472 	return B_ERROR;
473 }
474 
475 
476 status_t
477 BGameSound::_Reserved_BGameSound_29(int32 arg, ...)
478 {
479 	return B_ERROR;
480 }
481 
482 
483 status_t
484 BGameSound::_Reserved_BGameSound_30(int32 arg, ...)
485 {
486 	return B_ERROR;
487 }
488 
489 
490 status_t
491 BGameSound::_Reserved_BGameSound_31(int32 arg, ...)
492 {
493 	return B_ERROR;
494 }
495 
496 
497 status_t
498 BGameSound::_Reserved_BGameSound_32(int32 arg, ...)
499 {
500 	return B_ERROR;
501 }
502 
503 
504 status_t
505 BGameSound::_Reserved_BGameSound_33(int32 arg, ...)
506 {
507 	return B_ERROR;
508 }
509 
510 
511 status_t
512 BGameSound::_Reserved_BGameSound_34(int32 arg, ...)
513 {
514 	return B_ERROR;
515 }
516 
517 
518 status_t
519 BGameSound::_Reserved_BGameSound_35(int32 arg, ...)
520 {
521 	return B_ERROR;
522 }
523 
524 
525 status_t
526 BGameSound::_Reserved_BGameSound_36(int32 arg, ...)
527 {
528 	return B_ERROR;
529 }
530 
531 
532 status_t
533 BGameSound::_Reserved_BGameSound_37(int32 arg, ...)
534 {
535 	return B_ERROR;
536 }
537 
538 
539 status_t
540 BGameSound::_Reserved_BGameSound_38(int32 arg, ...)
541 {
542 	return B_ERROR;
543 }
544 
545 
546 status_t
547 BGameSound::_Reserved_BGameSound_39(int32 arg, ...)
548 {
549 	return B_ERROR;
550 }
551 
552 
553 status_t
554 BGameSound::_Reserved_BGameSound_40(int32 arg, ...)
555 {
556 	return B_ERROR;
557 }
558 
559 
560 status_t
561 BGameSound::_Reserved_BGameSound_41(int32 arg, ...)
562 {
563 	return B_ERROR;
564 }
565 
566 
567 status_t
568 BGameSound::_Reserved_BGameSound_42(int32 arg, ...)
569 {
570 	return B_ERROR;
571 }
572 
573 
574 status_t
575 BGameSound::_Reserved_BGameSound_43(int32 arg, ...)
576 {
577 	return B_ERROR;
578 }
579 
580 
581 status_t
582 BGameSound::_Reserved_BGameSound_44(int32 arg, ...)
583 {
584 	return B_ERROR;
585 }
586 
587 
588 status_t
589 BGameSound::_Reserved_BGameSound_45(int32 arg, ...)
590 {
591 	return B_ERROR;
592 }
593 
594 
595 status_t
596 BGameSound::_Reserved_BGameSound_46(int32 arg, ...)
597 {
598 	return B_ERROR;
599 }
600 
601 
602 status_t
603 BGameSound::_Reserved_BGameSound_47(int32 arg, ...)
604 {
605 	return B_ERROR;
606 }
607 
608 
609