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