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