1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853
|
/*
* OpenSLUDGE - sound_openal.cpp
* Copyright (C) 2000 - 2010 Tim Furnish, Rikard Peterson, Tobias Hansen
* OpenAL version created 2010 by Tobias Hansen <tobias.han@gmx.de>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License, version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdint.h>
#include <stdio.h>
#include "AL/alure.h"
#include <dumb.h>
#include "allfiles.h"
#include "debug.h"
#include "newfatal.h"
#include "sound.h"
#include "moreio.h"
#include "fileset.h"
#define MAX_SAMPLES 8
#define MAX_MODS 3
#define NUM_BUFS 3
bool soundOK = false;
bool cacheLoopySound = false;
bool SilenceIKillYou = false;
struct soundThing {
alureStream *stream;
ALuint playingOnSource;
bool playing;
int fileLoaded, vol; //Used for sounds only.
bool looping; //Used for sounds only.
DUH_SIGRENDERER *sr; //Used for MODs only.
};
soundThing soundCache[MAX_SAMPLES];
soundThing modCache[MAX_MODS];
int intpointers[MAX_SAMPLES];
int defVol = 128;
int defSoundVol = 255;
const float modLoudness = 0.95f;
/*
* Functions for Alure to access DUMB:
*/
// Values to choose from:
const float DUMB_volume = 0.95f; // between 0.0f and 1.0f
const int DUMB_freq = 44100;
const int DUMB_n_channels = 2; // 1 or 2
const int DUMB_depth = 16; // 8 or 16
const int DUMB_unsign = 0;
const ALenum DUMB_format = AL_FORMAT_STEREO16; // Match this to DUMB_depth
// and DUMB_n_channels.
DUH_SIGRENDERER * DUMBopen_memory(const ALubyte *data, ALuint length, int fromTrack) {
DUMBFILE *df;
DUH *duh;
DUH_SIGRENDERER *sr;
int i;
for (i = 0; i < 4; i++) {
df = dumbfile_open_memory((const char *)data, length);
switch (i) {
case 0:
duh = dumb_read_xm_quick(df);
break;
case 1:
duh = dumb_read_it_quick(df);
break;
case 2:
duh = dumb_read_s3m_quick(df);
break;
case 3:
#if (DUMB_MAJOR_VERSION) >= 2
duh = dumb_read_mod_quick(df, 0);
#else
duh = dumb_read_mod_quick(df);
#endif
break;
default:
break;
}
if (duh)
break;
dumbfile_close(df);
if (i == 3) {
return NULL;
}
}
sr = dumb_it_start_at_order(duh, DUMB_n_channels, fromTrack);
return sr;
}
ALuint DUMBdecode(void *instance, ALubyte *data, ALuint bytes) {
float delta;
int bufsize;
delta = 65536.0f / DUMB_freq;
bufsize = DUMB_depth == 16 ? bytes/2 : bytes;
bufsize /= DUMB_n_channels;
int l = duh_render((DUH_SIGRENDERER *)instance, DUMB_depth, DUMB_unsign,
DUMB_volume, delta, bufsize, data);
l *= DUMB_n_channels;
l = DUMB_depth == 16 ? l*2 : l;
return l;
}
/*
* Set up, tear down:
*/
bool initSoundStuff (HWND hwnd) {
if(!alureInitDevice(NULL, NULL))
{
debugOut( "Failed to open OpenAL device: %s\n",
alureGetErrorString());
return 1;
}
int a;
for (a = 0; a < MAX_SAMPLES; a ++) {
soundCache[a].stream = NULL;
soundCache[a].playing = false;
soundCache[a].fileLoaded = -1;
soundCache[a].looping = false;
intpointers[a] = a;
}
for (a = 0; a < MAX_MODS; a ++) {
modCache[a].stream = NULL;
modCache[a].playing = false;
}
if (! alureUpdateInterval(0.01))
{
debugOut("Failed to set Alure update interval: %s\n",
alureGetErrorString());
return 1;
}
atexit(&dumb_exit);
return soundOK = true;
}
void killSoundStuff () {
if (! soundOK) return;
SilenceIKillYou = true;
for (int i = 0; i < MAX_SAMPLES; i ++) {
if (soundCache[i].playing) {
if (! alureStopSource(soundCache[i].playingOnSource, AL_TRUE)) {
debugOut( "Failed to stop source: %s\n",
alureGetErrorString());
}
}
if (soundCache[i].stream != NULL) {
if (! alureDestroyStream(soundCache[i].stream, 0, NULL)) {
debugOut("Failed to destroy stream: %s\n",
alureGetErrorString());
}
}
}
for (int i = 0; i < MAX_MODS; i ++) {
if (modCache[i].playing) {
if (! alureStopSource(modCache[i].playingOnSource, AL_TRUE)) {
debugOut( "Failed to stop source: %s\n",
alureGetErrorString());
}
}
if (modCache[i].stream != NULL) {
if (! alureDestroyStream(modCache[i].stream, 0, NULL)) {
debugOut("Failed to destroy stream: %s\n",
alureGetErrorString());
}
}
}
SilenceIKillYou = false;
alureShutdownDevice();
dumb_exit();
}
/*
* Some setters:
*/
void setMusicVolume (int a, int v) {
if (! soundOK) return;
if (modCache[a].playing) {
alSourcef (modCache[a].playingOnSource, AL_GAIN, (float) modLoudness * v / 255);
}
}
void setDefaultMusicVolume (int v) {
defVol = v;
}
void setSoundVolume (int a, int v) {
if (! soundOK) return;
int ch = findInSoundCache (a);
if (ch != -1) {
if (soundCache[ch].playing) {
soundCache[ch].vol = v;
alSourcef (soundCache[ch].playingOnSource,
AL_GAIN, (float) v / 255);
}
}
}
void setDefaultSoundVolume (int v) {
defSoundVol = v;
}
void setSoundLoop (int a, int s, int e) {
//#pragma unused (a,s,e)
}
/*
* End of stream callbacks:
*/
static void sound_eos_callback(void *cacheIndex, ALuint source)
{
int *a = (int*)cacheIndex;
alDeleteSources(1, &source);
if(alGetError() != AL_NO_ERROR)
{
debugOut("Failed to delete OpenAL source!\n");
}
soundCache[*a].playingOnSource = 0;
soundCache[*a].playing = false;
soundCache[*a].looping = false;
}
static void mod_eos_callback(void *cacheIndex, ALuint source)
{
int *a = (int*)cacheIndex;
alDeleteSources(1, &source);
if(alGetError() != AL_NO_ERROR)
{
debugOut("Failed to delete OpenAL source!\n");
}
modCache[*a].playingOnSource = 0;
if (! alureDestroyStream(modCache[*a].stream, 0, NULL)) {
debugOut("Failed to destroy stream: %s\n",
alureGetErrorString());
}
duh_end_sigrenderer((DUH_SIGRENDERER *)modCache[*a].sr);
modCache[*a].sr = NULL;
modCache[*a].stream = NULL;
modCache[*a].playing = false;
}
/*
* Stopping things:
*/
int findInSoundCache (int a) {
int i;
for (i = 0; i < MAX_SAMPLES; i ++) {
if (soundCache[i].fileLoaded == a) {
return i;
}
}
return -1;
}
void stopMOD (int i) {
if (! soundOK) return;
alGetError();
if (modCache[i].playing) {
if (! alureStopSource(modCache[i].playingOnSource, AL_TRUE)) {
debugOut("Failed to stop source: %s\n",
alureGetErrorString());
}
}
}
void huntKillSound (int filenum) {
if (! soundOK) return;
// Clear OpenAL errors to make sure they don't block anything:
alGetError();
int gotSlot = findInSoundCache (filenum);
if (gotSlot == -1) return;
SilenceIKillYou = true;
if (soundCache[gotSlot].playing) {
if (! alureStopSource(soundCache[gotSlot].playingOnSource, AL_TRUE)) {
debugOut("Failed to stop source: %s\n",
alureGetErrorString());
}
}
SilenceIKillYou = false;
}
void freeSound (int a) {
if (! soundOK) return;
// Clear OpenAL errors to make sure they don't block anything:
alGetError();
SilenceIKillYou = true;
if (soundCache[a].playing) {
if (! alureStopSource(soundCache[a].playingOnSource, AL_TRUE)) {
debugOut( "Failed to stop source: %s\n",
alureGetErrorString());
}
}
if (! alureDestroyStream(soundCache[a].stream, 0, NULL)) {
debugOut("Failed to destroy stream: %s\n",
alureGetErrorString());
}
soundCache[a].stream = NULL;
soundCache[a].fileLoaded = -1;
SilenceIKillYou = false;
}
void huntKillFreeSound (int filenum) {
if (! soundOK) return;
int gotSlot = findInSoundCache (filenum);
if (gotSlot == -1) return;
freeSound (gotSlot);
}
/*
* Loading and playing:
*/
void playStream (int a, bool isMOD, bool loopy) {
if (! soundOK) return;
ALboolean ok;
ALuint src;
soundThing *st;
void (*eos_callback)(void *userdata, ALuint source);
if (isMOD) {
st = &modCache[a];
eos_callback = mod_eos_callback;
}
else {
st = &soundCache[a];
eos_callback = sound_eos_callback;
}
alGenSources(1, &src);
if(alGetError() != AL_NO_ERROR)
{
debugOut( "Failed to create OpenAL source!\n");
return;
}
if (isMOD) {
alSourcef (src, AL_GAIN, (float) modLoudness * defVol / 255);
} else {
alSourcef (src, AL_GAIN, (float) soundCache[a].vol / 255);
}
if (loopy) {
ok = alurePlaySourceStream(src, (*st).stream,
NUM_BUFS, -1, eos_callback, &intpointers[a]);
} else {
ok = alurePlaySourceStream(src, (*st).stream,
NUM_BUFS, 0, eos_callback, &intpointers[a]);
}
if(!ok) {
debugOut("Failed to play stream: %s\n", alureGetErrorString());
alDeleteSources(1, &src);
if(alGetError() != AL_NO_ERROR)
{
debugOut("Failed to delete OpenAL source!\n");
}
(*st).playingOnSource = 0;
} else {
(*st).playingOnSource = src;
(*st).playing = true;
}
}
char * loadEntireFileToMemory (FILE * inputFile, uint32_t size) {
char * allData = new char[size];
if (! allData) return NULL;
size_t bytes_read = fread (allData, size, 1, inputFile);
if (bytes_read != size && ferror (inputFile)) {
debugOut("Reading error in loadEntireFileToMemory.\n");
}
finishAccess ();
return allData;
}
bool playMOD (int f, int a, int fromTrack) {
if (! soundOK) return true;
stopMOD (a);
setResourceForFatal (f);
uint32_t length = openFileFromNum (f);
if (length == 0) {
finishAccess();
setResourceForFatal (-1);
return false;
}
unsigned char * memImage;
memImage = (unsigned char *) loadEntireFileToMemory (bigDataFile, length);
if (! memImage) return fatal (ERROR_MUSIC_MEMORY_LOW);
modCache[a].sr = DUMBopen_memory(memImage, length, fromTrack);
delete memImage;
modCache[a].stream = alureCreateStreamFromCallback(
&DUMBdecode,
modCache[a].sr, DUMB_format, DUMB_freq,
19200, 0, NULL);
if (modCache[a].stream != NULL) {
setMusicVolume (a, defVol);
if (! alureSetStreamOrder (modCache[a].stream, fromTrack)) {
debugOut( "Failed to set stream order: %s\n",
alureGetErrorString());
}
playStream (a, true, true);
} else {
debugOut("Failed to create stream from MOD: %s\n",
alureGetErrorString());
warning (ERROR_MUSIC_ODDNESS);
soundCache[a].stream = NULL;
soundCache[a].playing = false;
soundCache[a].playingOnSource = 0;
}
setResourceForFatal (-1);
return true;
}
bool stillPlayingSound (int ch) {
if (soundOK)
if (ch != -1)
if (soundCache[ch].fileLoaded != -1)
if (soundCache[ch].playing)
return true;
return false;
}
bool forceRemoveSound () {
for (int a = 0; a < MAX_SAMPLES; a ++) {
if (soundCache[a].fileLoaded != -1 && ! stillPlayingSound (a)) {
// soundWarning ("Deleting silent sound", a);
freeSound (a);
return 1;
}
}
for (int a = 0; a < MAX_SAMPLES; a ++) {
if (soundCache[a].fileLoaded != -1) {
// soundWarning ("Deleting playing sound", a);
freeSound (a);
return 1;
}
}
// soundWarning ("Cache is empty!", 0);
return 0;
}
int emptySoundSlot = 0;
int findEmptySoundSlot () {
int t;
for (t = 0; t < MAX_SAMPLES; t ++) {
emptySoundSlot ++;
emptySoundSlot %= MAX_SAMPLES;
if (soundCache[emptySoundSlot].stream == NULL)
return emptySoundSlot;
}
for (t = 0; t < MAX_SAMPLES; t ++) {
emptySoundSlot ++;
emptySoundSlot %= MAX_SAMPLES;
if (!soundCache[emptySoundSlot].playing)
return emptySoundSlot;
}
// Argh! They're all playing! Let's trash the oldest that's not looping...
for (t = 0; t < MAX_SAMPLES; t ++) {
emptySoundSlot ++;
emptySoundSlot %= MAX_SAMPLES;
if (! soundCache[emptySoundSlot].looping) return emptySoundSlot;
}
// Holy crap, they're all looping! What's this twat playing at?
emptySoundSlot ++;
emptySoundSlot %= MAX_SAMPLES;
return emptySoundSlot;
}
int cacheSound (int f) {
if (! soundOK) return -1;
unsigned int chunkLength;
int retval;
bool loopy;
loopy = cacheLoopySound;
cacheLoopySound = false;
setResourceForFatal (f);
if (! soundOK) return 0;
int a = findInSoundCache (f);
if (a != -1) {
if (soundCache[a].playing) {
if (! alureStopSource(soundCache[a].playingOnSource, AL_TRUE)) {
debugOut( "Failed to stop source: %s\n",
alureGetErrorString());
}
}
if (! alureRewindStream (soundCache[a].stream)) {
debugOut( "Failed to rewind stream: %s\n",
alureGetErrorString());
}
return a;
}
if (f == -2) return -1;
a = findEmptySoundSlot ();
freeSound (a);
uint32_t length = openFileFromNum (f);
if (! length) return -1;
unsigned char * memImage;
bool tryAgain = true;
while (tryAgain) {
memImage = (unsigned char*)loadEntireFileToMemory (bigDataFile, length);
tryAgain = memImage == NULL;
if (tryAgain) {
if (! forceRemoveSound ()) {
fatal (ERROR_SOUND_MEMORY_LOW);
return -1;
}
}
}
chunkLength = 19200;
// Small looping sounds need small chunklengths.
if (loopy) {
if (length < NUM_BUFS * chunkLength) {
chunkLength = length / NUM_BUFS;
}
} else if (length < chunkLength) {
chunkLength = length;
}
soundCache[a].stream = alureCreateStreamFromMemory(memImage, length, chunkLength, 0, NULL);
delete[] memImage;
if (soundCache[a].stream != NULL) {
soundCache[a].fileLoaded = f;
setResourceForFatal (-1);
retval = a;
} else {
debugOut("Failed to create stream from sound: %s\n",
alureGetErrorString());
warning (ERROR_SOUND_ODDNESS);
soundCache[a].stream = NULL;
soundCache[a].playing = false;
soundCache[a].playingOnSource = 0;
soundCache[a].fileLoaded = -1;
soundCache[a].looping = false;
retval = -1;
}
return retval;
}
bool startSound (int f, bool loopy) {
if (soundOK) {
cacheLoopySound = loopy;
int a = cacheSound (f);
if (a == -1) {
debugOut( "Failed to cache sound!\n");
return false;
}
soundCache[a].looping = loopy;
soundCache[a].vol = defSoundVol;
playStream (a, false, loopy);
}
return true;
}
void saveSounds (FILE * fp) {
if (soundOK) {
for (int i = 0; i < MAX_SAMPLES; i ++) {
if (soundCache[i].looping) {
fputc (1, fp);
put2bytes (soundCache[i].fileLoaded, fp);
put2bytes (soundCache[i].vol, fp);
}
}
}
fputc (0, fp);
put2bytes (defSoundVol, fp);
put2bytes (defVol, fp);
}
void loadSounds (FILE * fp) {
for (int i = 0; i < MAX_SAMPLES; i ++) freeSound (i);
while (fgetc (fp)) {
int fileLoaded = get2bytes (fp);
defSoundVol = get2bytes (fp);
startSound (fileLoaded, 1);
}
defSoundVol = get2bytes (fp);
defVol = get2bytes (fp);
}
bool getSoundCacheStack (stackHandler * sH) {
variable newFileHandle;
newFileHandle.varType = SVT_NULL;
for (int a = 0; a < MAX_SAMPLES; a ++) {
if (soundCache[a].fileLoaded != -1) {
setVariable (newFileHandle, SVT_FILE, soundCache[a].fileLoaded);
if (! addVarToStackQuick (newFileHandle, sH -> first)) return false;
if (sH -> last == NULL) sH -> last = sH -> first;
}
}
return true;
}
soundList *deleteSoundFromList (soundList *s) {
// Don't delete a playing sound.
if (s->cacheIndex) return NULL;
soundList * o = NULL;
if (! s->next) {
o = s->prev;
if (o) o-> next = NULL;
delete s;
return o;
}
if (s != s->next) {
o = s->next;
o->prev = s->prev;
if (o->prev) o->prev->next = o;
}
delete s;
return o;
}
static void list_eos_callback(void *list, ALuint source)
{
soundList *s = (soundList *) list;
int a = s->cacheIndex;
alDeleteSources(1, &source);
if(alGetError() != AL_NO_ERROR)
{
debugOut( "Failed to delete OpenAL source!\n");
}
soundCache[a].playingOnSource = 0;
soundCache[a].playing = false;
soundCache[a].looping = false;
s-> cacheIndex = false;
if (SilenceIKillYou) {
while (s = deleteSoundFromList(s));
} else {
if (s->next) {
if (s->next == s) {
int v = defSoundVol;
defSoundVol = soundCache[a].vol;
startSound (s->sound, true);
defSoundVol = v;
while (s = deleteSoundFromList(s));
return;
}
s->next->vol = soundCache[a].vol;
playSoundList(s->next);
} else {
while (s = deleteSoundFromList(s));
}
}
}
void playSoundList(soundList *s) {
if (soundOK) {
cacheLoopySound = true;
int a = cacheSound (s->sound);
if (a == -1) {
debugOut("Failed to cache sound!\n");
return;
}
soundCache[a].looping = false;
if (s->vol < 0)
soundCache[a].vol = defSoundVol;
else
soundCache[a].vol = s->vol;
s-> cacheIndex = a;
ALboolean ok;
ALuint src;
soundThing *st;
st = &soundCache[a];
alGenSources(1, &src);
if(alGetError() != AL_NO_ERROR)
{
debugOut("Failed to create OpenAL source!\n");
return;
}
alSourcef (src, AL_GAIN, (float) soundCache[a].vol / 255);
ok = alurePlaySourceStream(src, (*st).stream,
NUM_BUFS, 0, list_eos_callback, s);
if(!ok) {
debugOut("Failed to play stream: %s\n", alureGetErrorString());
alDeleteSources(1, &src);
if(alGetError() != AL_NO_ERROR)
{
debugOut("Failed to delete OpenAL source!\n");
}
(*st).playingOnSource = 0;
} else {
(*st).playingOnSource = src;
(*st).playing = true;
}
}
}
void playMovieStream (int a) {
if (! soundOK) return;
ALboolean ok;
ALuint src;
alGenSources(1, &src);
if(alGetError() != AL_NO_ERROR)
{
debugOut( "Failed to create OpenAL source!\n");
return;
}
alSourcef (src, AL_GAIN, (float) soundCache[a].vol / 255);
ok = alurePlaySourceStream(src, soundCache[a].stream,
10, 0, sound_eos_callback, &intpointers[a]);
if(!ok) {
debugOut("Failed to play stream: %s\n", alureGetErrorString());
alDeleteSources(1, &src);
if(alGetError() != AL_NO_ERROR)
{
debugOut("Failed to delete OpenAL source!\n");
}
soundCache[a].playingOnSource = 0;
} else {
soundCache[a].playingOnSource = src;
soundCache[a].playing = true;
}
}
int initMovieSound(int f, ALenum format, int audioChannels, ALuint samplerate,
ALuint (*callback)(void *userdata, ALubyte *data, ALuint bytes)) {
if (! soundOK) return 0;
int retval;
int a = findEmptySoundSlot ();
freeSound (a);
soundCache[a].looping = false;
// audioChannel * sampleRate gives us a buffer of half a second. Not much, but it should be enough.
soundCache[a].stream = alureCreateStreamFromCallback(
callback,
&intpointers[a], format, samplerate,
audioChannels*samplerate, 0, NULL);
if (soundCache[a].stream != NULL) {
soundCache[a].fileLoaded = f;
soundCache[a].vol = defSoundVol;
retval = a;
} else {
debugOut("Failed to create stream from sound: %s\n",
alureGetErrorString());
warning (ERROR_SOUND_ODDNESS);
soundCache[a].stream = NULL;
soundCache[a].playing = false;
soundCache[a].playingOnSource = 0;
soundCache[a].fileLoaded = -1;
retval = -1;
}
//fprintf (stderr, "Stream %d created. Sample rate: %d Channels: %d\n", retval, samplerate, audioChannels);
return retval;
}
unsigned int getSoundSource(int index) {
return soundCache[index].playingOnSource;
}
|