diff --git a/source/src/audiomanager.cpp b/source/src/audiomanager.cpp index a309b8bb..f6885d2a 100644 --- a/source/src/audiomanager.cpp +++ b/source/src/audiomanager.cpp @@ -76,7 +76,7 @@ void audiomanager::initsound() conoutf("Driver: %s", alGetString(AL_VERSION)); // allocate OpenAL resources - scheduler.init(); + sourcescheduler::default().init(); // let the stream get the first source from the scheduler gamemusic = new oggstream(); @@ -230,7 +230,7 @@ void audiomanager::soundcleanup() bufferpool.clear(); // kill scheduler - scheduler.reset(); + sourcescheduler::default().reset(); // shutdown openal alcMakeContextCurrent(NULL); @@ -736,7 +736,7 @@ COMMANDF(mapsoundreset, ARG_NONE, () audiomgr.mapsoundreset(); }); -VARF(soundchannels, 4, 32, 1024, { if(!audiomgr.nosound) scheduler.init(); }); +VARF(soundchannels, 4, 32, 1024, { if(!audiomgr.nosound) sourcescheduler::default().init(); }); VARFP(soundvol, 0, 128, 255, { diff --git a/source/src/oggstream.cpp b/source/src/oggstream.cpp index aa1e8807..1d7a8995 100644 --- a/source/src/oggstream.cpp +++ b/source/src/oggstream.cpp @@ -27,7 +27,7 @@ oggstream::oggstream() : valid(false), isopen(false), src(NULL) reset(); // grab a source and keep it during the whole lifetime - src = scheduler.newsource(SP_HIGHEST, camera1->o); + src = sourcescheduler::default().newsource(SP_HIGHEST, camera1->o); if(src) { if(src->valid) @@ -37,7 +37,7 @@ oggstream::oggstream() : valid(false), isopen(false), src(NULL) } else { - scheduler.releasesource(src); + sourcescheduler::default().releasesource(src); src = NULL; } } @@ -53,7 +53,7 @@ oggstream::~oggstream() { reset(); - if(src) scheduler.releasesource(src); + if(src) sourcescheduler::default().releasesource(src); if(alIsBuffer(bufferids[0]) || alIsBuffer(bufferids[1])) { diff --git a/source/src/sound.h b/source/src/sound.h index df4606b0..06d65080 100644 --- a/source/src/sound.h +++ b/source/src/sound.h @@ -154,14 +154,17 @@ public: virtual sbuffer *find(char *name); }; -// manages sources +// manages available sources, abstracts audio channels +// is a singleton class sourcescheduler { -public: + static sourcescheduler *instance; vector sources; +public: sourcescheduler(); + static sourcescheduler &default(); // singleton access void init(); void reset(); @@ -405,7 +408,6 @@ extern ov_callbacks oggcallbacks; extern int soundvol; extern int audiodebug; -extern sourcescheduler scheduler; // FIXME extern audiomanager audiomgr; diff --git a/source/src/soundlocation.cpp b/source/src/soundlocation.cpp index df3c816e..920c3198 100644 --- a/source/src/soundlocation.cpp +++ b/source/src/soundlocation.cpp @@ -35,7 +35,7 @@ location::location(int sound, const worldobjreference &r, int priority) : cfg(NU } // obtain source - src = scheduler.newsource(priority, r.currentposition()); + src = sourcescheduler::default().newsource(priority, r.currentposition()); // apply configuration if(!src || !src->valid || !src->buffer(cfg->buf->id) || !src->looping(cfg->loop) || !src->gain(cfg->vol/100.0f*((float)gainscale)/100.0f)) { @@ -50,7 +50,7 @@ location::location(int sound, const worldobjreference &r, int priority) : cfg(NU location::~location() { - if(src) scheduler.releasesource(src); + if(src) sourcescheduler::default().releasesource(src); if(cfg) cfg->ondetach(); if(ref) { diff --git a/source/src/soundscheduler.cpp b/source/src/soundscheduler.cpp index 6074f6d1..292b07d7 100644 --- a/source/src/soundscheduler.cpp +++ b/source/src/soundscheduler.cpp @@ -14,10 +14,18 @@ VARP(soundscheddistancescore, 0, 5, 1000); VARP(soundschedoldbonus, 0, 100, 1000); VARP(soundschedreserve, 0, 2, 100); +sourcescheduler *sourcescheduler::instance; + sourcescheduler::sourcescheduler() { } +sourcescheduler &sourcescheduler::default() +{ + if(instance==NULL) instance = new sourcescheduler(); + return *instance; +} + void sourcescheduler::init() { int newchannels = soundchannels - sources.length(); @@ -150,5 +158,4 @@ void sourcescheduler::releasesource(source *src) } } -sourcescheduler scheduler; // FIXME, move to audiomanager