BPicture: Fix archive constructor.
[haiku.git] / src / kits / game / GameSound.cpp
blob935121674f03fb15416a25965d9a0c8be5b56c98
1 /*
2 * Copyright 2002-2012 Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Christopher ML Zumwalt May (zummy@users.sf.net)
8 */
11 #include <GameSound.h>
13 #include <stdio.h>
14 #include <string.h>
16 #include "GameSoundBuffer.h"
17 #include "GameSoundDevice.h"
20 using std::nothrow;
23 // Local Defines ---------------------------------------------------------------
25 // BGameSound class ------------------------------------------------------------
26 BGameSound::BGameSound(BGameSoundDevice *device)
28 fSound(-1)
30 // TODO: device is ignored!
31 // NOTE: BeBook documents that BGameSoundDevice must currently always
32 // be NULL...
33 fDevice = GetDefaultDevice();
34 fInitError = fDevice->InitCheck();
38 BGameSound::BGameSound(const BGameSound &other)
40 fSound(-1)
42 memcpy(&fFormat, &other.fFormat, sizeof(gs_audio_format));
43 // TODO: device from other is ignored!
44 fDevice = GetDefaultDevice();
46 fInitError = fDevice->InitCheck();
50 BGameSound::~BGameSound()
52 if (fSound >= 0)
53 fDevice->ReleaseBuffer(fSound);
55 ReleaseDevice();
59 status_t
60 BGameSound::InitCheck() const
62 return fInitError;
66 BGameSoundDevice *
67 BGameSound::Device() const
69 // TODO: Must return NULL if default device is being used!
70 return fDevice;
74 gs_id
75 BGameSound::ID() const
77 // TODO: Should be 0 if no sound has been selected! But fSound
78 // is initialized with -1 in the constructors.
79 return fSound;
83 const gs_audio_format &
84 BGameSound::Format() const
86 return fDevice->Format(fSound);
90 status_t
91 BGameSound::StartPlaying()
93 fDevice->StartPlaying(fSound);
94 return B_OK;
98 bool
99 BGameSound::IsPlaying()
101 return fDevice->IsPlaying(fSound);
105 status_t
106 BGameSound::StopPlaying()
108 fDevice->StopPlaying(fSound);
109 return B_OK;
113 status_t
114 BGameSound::SetGain(float gain, bigtime_t duration)
116 gs_attribute attribute;
118 attribute.attribute = B_GS_GAIN;
119 attribute.value = gain;
120 attribute.duration = duration;
121 attribute.flags = 0;
123 return fDevice->SetAttributes(fSound, &attribute, 1);
127 status_t
128 BGameSound::SetPan(float pan, bigtime_t duration)
130 gs_attribute attribute;
132 attribute.attribute = B_GS_PAN;
133 attribute.value = pan;
134 attribute.duration = duration;
135 attribute.flags = 0;
137 return fDevice->SetAttributes(fSound, &attribute, 1);
141 float
142 BGameSound::Gain()
144 gs_attribute attribute;
146 attribute.attribute = B_GS_GAIN;
147 attribute.flags = 0;
149 if (fDevice->GetAttributes(fSound, &attribute, 1) != B_OK)
150 return 0.0;
152 return attribute.value;
156 float
157 BGameSound::Pan()
159 gs_attribute attribute;
161 attribute.attribute = B_GS_PAN;
162 attribute.flags = 0;
164 if (fDevice->GetAttributes(fSound, &attribute, 1) != B_OK)
165 return 0.0;
167 return attribute.value;
171 status_t
172 BGameSound::SetAttributes(gs_attribute *inAttributes, size_t inAttributeCount)
174 return fDevice->SetAttributes(fSound, inAttributes, inAttributeCount);
178 status_t
179 BGameSound::GetAttributes(gs_attribute *outAttributes, size_t inAttributeCount)
181 return fDevice->GetAttributes(fSound, outAttributes, inAttributeCount);
185 status_t
186 BGameSound::Perform(int32 selector,
187 void *data)
189 return B_ERROR;
193 void *
194 BGameSound::operator new(size_t size)
196 return ::operator new(size);
200 void *
201 BGameSound::operator new(size_t size, const std::nothrow_t &nt) throw()
203 return ::operator new(size, nt);
207 void
208 BGameSound::operator delete(void *ptr)
210 ::operator delete(ptr);
214 #if !__MWERKS__
215 // there's a bug in MWCC under R4.1 and earlier
216 void
217 BGameSound::operator delete(void *ptr, const std::nothrow_t &nt) throw()
219 ::operator delete(ptr, nt);
221 #endif
224 status_t
225 BGameSound::SetMemoryPoolSize(size_t in_poolSize)
227 return B_ERROR;
231 status_t
232 BGameSound::LockMemoryPool(bool in_lockInCore)
234 return B_ERROR;
238 int32
239 BGameSound::SetMaxSoundCount(int32 in_maxCount)
241 return in_maxCount;
245 status_t
246 BGameSound::SetInitError(status_t in_initError)
248 fInitError = in_initError;
249 return B_OK;
253 status_t
254 BGameSound::Init(gs_id handle)
256 if (fSound < 0)
257 fSound = handle;
259 return B_OK;
263 #if 0
264 BGameSound &
265 BGameSound::operator=(const BGameSound &other)
267 if (fSound)
268 fDevice->ReleaseBuffer(fSound);
270 fSound = other.fSound;
271 fInitError = other.fInitError;
273 // TODO: This would need to acquire the sound another time!
275 return this;
277 #endif
280 /* unimplemented for protection of the user:
282 * BGameSound::BGameSound()
286 status_t
287 BGameSound::_Reserved_BGameSound_0(int32 arg, ...)
289 return B_ERROR;
293 status_t
294 BGameSound::_Reserved_BGameSound_1(int32 arg, ...)
296 return B_ERROR;
300 status_t
301 BGameSound::_Reserved_BGameSound_2(int32 arg, ...)
303 return B_ERROR;
307 status_t
308 BGameSound::_Reserved_BGameSound_3(int32 arg, ...)
310 return B_ERROR;
314 status_t
315 BGameSound::_Reserved_BGameSound_4(int32 arg, ...)
317 return B_ERROR;
321 status_t
322 BGameSound::_Reserved_BGameSound_5(int32 arg, ...)
324 return B_ERROR;
328 status_t
329 BGameSound::_Reserved_BGameSound_6(int32 arg, ...)
331 return B_ERROR;
335 status_t
336 BGameSound::_Reserved_BGameSound_7(int32 arg, ...)
338 return B_ERROR;
342 status_t
343 BGameSound::_Reserved_BGameSound_8(int32 arg, ...)
345 return B_ERROR;
349 status_t
350 BGameSound::_Reserved_BGameSound_9(int32 arg, ...)
352 return B_ERROR;
356 status_t
357 BGameSound::_Reserved_BGameSound_10(int32 arg, ...)
359 return B_ERROR;
363 status_t
364 BGameSound::_Reserved_BGameSound_11(int32 arg, ...)
366 return B_ERROR;
370 status_t
371 BGameSound::_Reserved_BGameSound_12(int32 arg, ...)
373 return B_ERROR;
377 status_t
378 BGameSound::_Reserved_BGameSound_13(int32 arg, ...)
380 return B_ERROR;
384 status_t
385 BGameSound::_Reserved_BGameSound_14(int32 arg, ...)
387 return B_ERROR;
391 status_t
392 BGameSound::_Reserved_BGameSound_15(int32 arg, ...)
394 return B_ERROR;
398 status_t
399 BGameSound::_Reserved_BGameSound_16(int32 arg, ...)
401 return B_ERROR;
405 status_t
406 BGameSound::_Reserved_BGameSound_17(int32 arg, ...)
408 return B_ERROR;
412 status_t
413 BGameSound::_Reserved_BGameSound_18(int32 arg, ...)
415 return B_ERROR;
419 status_t
420 BGameSound::_Reserved_BGameSound_19(int32 arg, ...)
422 return B_ERROR;
426 status_t
427 BGameSound::_Reserved_BGameSound_20(int32 arg, ...)
429 return B_ERROR;
433 status_t
434 BGameSound::_Reserved_BGameSound_21(int32 arg, ...)
436 return B_ERROR;
440 status_t
441 BGameSound::_Reserved_BGameSound_22(int32 arg, ...)
443 return B_ERROR;
447 status_t
448 BGameSound::_Reserved_BGameSound_23(int32 arg, ...)
450 return B_ERROR;
454 status_t
455 BGameSound::_Reserved_BGameSound_24(int32 arg, ...)
457 return B_ERROR;
461 status_t
462 BGameSound::_Reserved_BGameSound_25(int32 arg, ...)
464 return B_ERROR;
468 status_t
469 BGameSound::_Reserved_BGameSound_26(int32 arg, ...)
471 return B_ERROR;
475 status_t
476 BGameSound::_Reserved_BGameSound_27(int32 arg, ...)
478 return B_ERROR;
482 status_t
483 BGameSound::_Reserved_BGameSound_28(int32 arg, ...)
485 return B_ERROR;
489 status_t
490 BGameSound::_Reserved_BGameSound_29(int32 arg, ...)
492 return B_ERROR;
496 status_t
497 BGameSound::_Reserved_BGameSound_30(int32 arg, ...)
499 return B_ERROR;
503 status_t
504 BGameSound::_Reserved_BGameSound_31(int32 arg, ...)
506 return B_ERROR;
510 status_t
511 BGameSound::_Reserved_BGameSound_32(int32 arg, ...)
513 return B_ERROR;
517 status_t
518 BGameSound::_Reserved_BGameSound_33(int32 arg, ...)
520 return B_ERROR;
524 status_t
525 BGameSound::_Reserved_BGameSound_34(int32 arg, ...)
527 return B_ERROR;
531 status_t
532 BGameSound::_Reserved_BGameSound_35(int32 arg, ...)
534 return B_ERROR;
538 status_t
539 BGameSound::_Reserved_BGameSound_36(int32 arg, ...)
541 return B_ERROR;
545 status_t
546 BGameSound::_Reserved_BGameSound_37(int32 arg, ...)
548 return B_ERROR;
552 status_t
553 BGameSound::_Reserved_BGameSound_38(int32 arg, ...)
555 return B_ERROR;
559 status_t
560 BGameSound::_Reserved_BGameSound_39(int32 arg, ...)
562 return B_ERROR;
566 status_t
567 BGameSound::_Reserved_BGameSound_40(int32 arg, ...)
569 return B_ERROR;
573 status_t
574 BGameSound::_Reserved_BGameSound_41(int32 arg, ...)
576 return B_ERROR;
580 status_t
581 BGameSound::_Reserved_BGameSound_42(int32 arg, ...)
583 return B_ERROR;
587 status_t
588 BGameSound::_Reserved_BGameSound_43(int32 arg, ...)
590 return B_ERROR;
594 status_t
595 BGameSound::_Reserved_BGameSound_44(int32 arg, ...)
597 return B_ERROR;
601 status_t
602 BGameSound::_Reserved_BGameSound_45(int32 arg, ...)
604 return B_ERROR;
608 status_t
609 BGameSound::_Reserved_BGameSound_46(int32 arg, ...)
611 return B_ERROR;
615 status_t
616 BGameSound::_Reserved_BGameSound_47(int32 arg, ...)
618 return B_ERROR;