2 * Copyright 2002-2012 Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Christopher ML Zumwalt May (zummy@users.sf.net)
11 #include <GameSound.h>
16 #include "GameSoundBuffer.h"
17 #include "GameSoundDevice.h"
23 // Local Defines ---------------------------------------------------------------
25 // BGameSound class ------------------------------------------------------------
26 BGameSound::BGameSound(BGameSoundDevice
*device
)
30 // TODO: device is ignored!
31 // NOTE: BeBook documents that BGameSoundDevice must currently always
33 fDevice
= GetDefaultDevice();
34 fInitError
= fDevice
->InitCheck();
38 BGameSound::BGameSound(const BGameSound
&other
)
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()
53 fDevice
->ReleaseBuffer(fSound
);
60 BGameSound::InitCheck() const
67 BGameSound::Device() const
69 // TODO: Must return NULL if default device is being used!
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.
83 const gs_audio_format
&
84 BGameSound::Format() const
86 return fDevice
->Format(fSound
);
91 BGameSound::StartPlaying()
93 fDevice
->StartPlaying(fSound
);
99 BGameSound::IsPlaying()
101 return fDevice
->IsPlaying(fSound
);
106 BGameSound::StopPlaying()
108 fDevice
->StopPlaying(fSound
);
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
;
123 return fDevice
->SetAttributes(fSound
, &attribute
, 1);
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
;
137 return fDevice
->SetAttributes(fSound
, &attribute
, 1);
144 gs_attribute attribute
;
146 attribute
.attribute
= B_GS_GAIN
;
149 if (fDevice
->GetAttributes(fSound
, &attribute
, 1) != B_OK
)
152 return attribute
.value
;
159 gs_attribute attribute
;
161 attribute
.attribute
= B_GS_PAN
;
164 if (fDevice
->GetAttributes(fSound
, &attribute
, 1) != B_OK
)
167 return attribute
.value
;
172 BGameSound::SetAttributes(gs_attribute
*inAttributes
, size_t inAttributeCount
)
174 return fDevice
->SetAttributes(fSound
, inAttributes
, inAttributeCount
);
179 BGameSound::GetAttributes(gs_attribute
*outAttributes
, size_t inAttributeCount
)
181 return fDevice
->GetAttributes(fSound
, outAttributes
, inAttributeCount
);
186 BGameSound::Perform(int32 selector
,
194 BGameSound::operator new(size_t size
)
196 return ::operator new(size
);
201 BGameSound::operator new(size_t size
, const std::nothrow_t
&nt
) throw()
203 return ::operator new(size
, nt
);
208 BGameSound::operator delete(void *ptr
)
210 ::operator delete(ptr
);
215 // there's a bug in MWCC under R4.1 and earlier
217 BGameSound::operator delete(void *ptr
, const std::nothrow_t
&nt
) throw()
219 ::operator delete(ptr
, nt
);
225 BGameSound::SetMemoryPoolSize(size_t in_poolSize
)
232 BGameSound::LockMemoryPool(bool in_lockInCore
)
239 BGameSound::SetMaxSoundCount(int32 in_maxCount
)
246 BGameSound::SetInitError(status_t in_initError
)
248 fInitError
= in_initError
;
254 BGameSound::Init(gs_id handle
)
265 BGameSound::operator=(const BGameSound
&other
)
268 fDevice
->ReleaseBuffer(fSound
);
270 fSound
= other
.fSound
;
271 fInitError
= other
.fInitError
;
273 // TODO: This would need to acquire the sound another time!
280 /* unimplemented for protection of the user:
282 * BGameSound::BGameSound()
287 BGameSound::_Reserved_BGameSound_0(int32 arg
, ...)
294 BGameSound::_Reserved_BGameSound_1(int32 arg
, ...)
301 BGameSound::_Reserved_BGameSound_2(int32 arg
, ...)
308 BGameSound::_Reserved_BGameSound_3(int32 arg
, ...)
315 BGameSound::_Reserved_BGameSound_4(int32 arg
, ...)
322 BGameSound::_Reserved_BGameSound_5(int32 arg
, ...)
329 BGameSound::_Reserved_BGameSound_6(int32 arg
, ...)
336 BGameSound::_Reserved_BGameSound_7(int32 arg
, ...)
343 BGameSound::_Reserved_BGameSound_8(int32 arg
, ...)
350 BGameSound::_Reserved_BGameSound_9(int32 arg
, ...)
357 BGameSound::_Reserved_BGameSound_10(int32 arg
, ...)
364 BGameSound::_Reserved_BGameSound_11(int32 arg
, ...)
371 BGameSound::_Reserved_BGameSound_12(int32 arg
, ...)
378 BGameSound::_Reserved_BGameSound_13(int32 arg
, ...)
385 BGameSound::_Reserved_BGameSound_14(int32 arg
, ...)
392 BGameSound::_Reserved_BGameSound_15(int32 arg
, ...)
399 BGameSound::_Reserved_BGameSound_16(int32 arg
, ...)
406 BGameSound::_Reserved_BGameSound_17(int32 arg
, ...)
413 BGameSound::_Reserved_BGameSound_18(int32 arg
, ...)
420 BGameSound::_Reserved_BGameSound_19(int32 arg
, ...)
427 BGameSound::_Reserved_BGameSound_20(int32 arg
, ...)
434 BGameSound::_Reserved_BGameSound_21(int32 arg
, ...)
441 BGameSound::_Reserved_BGameSound_22(int32 arg
, ...)
448 BGameSound::_Reserved_BGameSound_23(int32 arg
, ...)
455 BGameSound::_Reserved_BGameSound_24(int32 arg
, ...)
462 BGameSound::_Reserved_BGameSound_25(int32 arg
, ...)
469 BGameSound::_Reserved_BGameSound_26(int32 arg
, ...)
476 BGameSound::_Reserved_BGameSound_27(int32 arg
, ...)
483 BGameSound::_Reserved_BGameSound_28(int32 arg
, ...)
490 BGameSound::_Reserved_BGameSound_29(int32 arg
, ...)
497 BGameSound::_Reserved_BGameSound_30(int32 arg
, ...)
504 BGameSound::_Reserved_BGameSound_31(int32 arg
, ...)
511 BGameSound::_Reserved_BGameSound_32(int32 arg
, ...)
518 BGameSound::_Reserved_BGameSound_33(int32 arg
, ...)
525 BGameSound::_Reserved_BGameSound_34(int32 arg
, ...)
532 BGameSound::_Reserved_BGameSound_35(int32 arg
, ...)
539 BGameSound::_Reserved_BGameSound_36(int32 arg
, ...)
546 BGameSound::_Reserved_BGameSound_37(int32 arg
, ...)
553 BGameSound::_Reserved_BGameSound_38(int32 arg
, ...)
560 BGameSound::_Reserved_BGameSound_39(int32 arg
, ...)
567 BGameSound::_Reserved_BGameSound_40(int32 arg
, ...)
574 BGameSound::_Reserved_BGameSound_41(int32 arg
, ...)
581 BGameSound::_Reserved_BGameSound_42(int32 arg
, ...)
588 BGameSound::_Reserved_BGameSound_43(int32 arg
, ...)
595 BGameSound::_Reserved_BGameSound_44(int32 arg
, ...)
602 BGameSound::_Reserved_BGameSound_45(int32 arg
, ...)
609 BGameSound::_Reserved_BGameSound_46(int32 arg
, ...)
616 BGameSound::_Reserved_BGameSound_47(int32 arg
, ...)