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