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