X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fsound%2Fsoundmgr_openal.cxx;h=d29b7fb1ae01d404df063dfd961c2f5f9bfea336;hb=f8303b46230120408fc3b0d7df3091b9abdef493;hp=e9e2dfbcdac0e757d701591303e8259ca5f8de45;hpb=055e969e7a9b19792945d12f8850ba4b55cba85d;p=simgear.git diff --git a/simgear/sound/soundmgr_openal.cxx b/simgear/sound/soundmgr_openal.cxx index e9e2dfbc..d29b7fb1 100644 --- a/simgear/sound/soundmgr_openal.cxx +++ b/simgear/sound/soundmgr_openal.cxx @@ -19,37 +19,55 @@ // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software -// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // // $Id$ +#ifdef HAVE_CONFIG_H +# include +#endif + #include #if defined(__APPLE__) # include -# include # include #else # include -# include # include #endif #if defined (__APPLE__) -// any C++ header file undefines isinf and isnan -// so this should be included before -inline int (isinf)(double r) { return isinf(r); } -inline int (isnan)(double r) { return isnan(r); } +# ifdef __GNUC__ +# if ( __GNUC__ >= 3 ) && ( __GNUC_MINOR__ >= 3 ) +// # include +inline int (isnan)(double r) { return !(r <= 0 || r >= 0); } +# else + // any C++ header file undefines isinf and isnan + // so this should be included before + // the functions are STILL in libm (libSystem on mac os x) +extern "C" int isnan (double); +extern "C" int isinf (double); +# endif +# else +// inline int (isinf)(double r) { return isinf(r); } +// inline int (isnan)(double r) { return isnan(r); } +# endif #endif -#if defined(__MINGW32__) -#define isnan(x) _isnan(x) +#if defined (__FreeBSD__) +# if __FreeBSD_version < 500000 + extern "C" { + inline int isnan(double r) { return !(r <= 0 || r >= 0); } + } +# endif #endif -#if defined (__FreeBSD__) -inline int isnan(double r) { return !(r <= 0 || r >= 0); } +#if defined (__CYGWIN__) +#include #endif + #include STL_IOSTREAM #include @@ -57,6 +75,9 @@ inline int isnan(double r) { return !(r <= 0 || r >= 0); } #include "soundmgr_openal.hxx" +#if defined(__MINGW32__) +#define isnan(x) _isnan(x) +#endif // // Sound Manager @@ -68,15 +89,31 @@ SGSoundMgr::SGSoundMgr() { SG_LOG( SG_GENERAL, SG_INFO, "Initializing OpenAL sound manager" ); // initialize OpenAL - alutInit( 0, NULL ); - atexit(alutExit); - - if ( alGetError() == AL_NO_ERROR) { +#if defined(ALUT_API_MAJOR_VERSION) && ALUT_API_MAJOR_VERSION >= 1 + if (!alutInit(NULL, NULL)) + { + ALenum error = alutGetError (); + SG_LOG( SG_GENERAL, SG_ALERT, "Audio initialization failed!" ); + SG_LOG( SG_GENERAL, SG_ALERT, " "+string(alutGetErrorString(error))); + working = false; + context = 0; + } + else + { working = true; + context = alcGetCurrentContext(); + } +#else + if ( (dev = alcOpenDevice( NULL )) != NULL + && ( context = alcCreateContext( dev, NULL )) != NULL ) { + working = true; + alcMakeContextCurrent( context ); } else { working = false; + context = 0; SG_LOG( SG_GENERAL, SG_ALERT, "Audio initialization failed!" ); } +#endif listener_pos[0] = 0.0; listener_pos[1] = 0.0; @@ -93,6 +130,7 @@ SGSoundMgr::SGSoundMgr() { listener_ori[4] = 1.0; listener_ori[5] = 0.0; + alListenerf( AL_GAIN, 0.0f ); alListenerfv( AL_POSITION, listener_pos ); alListenerfv( AL_VELOCITY, listener_vel ); alListenerfv( AL_ORIENTATION, listener_ori ); @@ -111,15 +149,12 @@ SGSoundMgr::SGSoundMgr() { SGSoundMgr::~SGSoundMgr() { - // - // Remove the samples from the sample manager. - // - sample_map_iterator sample_current = samples.begin(); - sample_map_iterator sample_end = samples.end(); - for ( ; sample_current != sample_end; ++sample_current ) { - SGSoundSample *sample = sample_current->second; - delete sample; - } +#if defined(ALUT_API_MAJOR_VERSION) && ALUT_API_MAJOR_VERSION >= 1 + alutExit (); +#else + if (context) + alcDestroyContext( context ); +#endif } @@ -128,12 +163,6 @@ void SGSoundMgr::init() { // // Remove the samples from the sample manager. // - sample_map_iterator sample_current = samples.begin(); - sample_map_iterator sample_end = samples.end(); - for ( ; sample_current != sample_end; ++sample_current ) { - SGSoundSample *sample = sample_current->second; - delete sample; - } samples.clear(); } @@ -158,11 +187,12 @@ void SGSoundMgr::update( double dt ) { void SGSoundMgr::pause () { - ALCcontext *pCurContext = alcGetCurrentContext(); - alcSuspendContext( pCurContext ); - if ( alGetError() != AL_NO_ERROR) { - SG_LOG( SG_GENERAL, SG_ALERT, - "Oops AL error after soundmgr pause()!" ); + if (context) { + alcSuspendContext( context ); + if ( alGetError() != AL_NO_ERROR) { + SG_LOG( SG_GENERAL, SG_ALERT, + "Oops AL error after soundmgr pause()!" ); + } } } @@ -170,11 +200,12 @@ SGSoundMgr::pause () void SGSoundMgr::resume () { - ALCcontext *pCurContext = alcGetCurrentContext(); - alcProcessContext( pCurContext ); - if ( alGetError() != AL_NO_ERROR) { - SG_LOG( SG_GENERAL, SG_ALERT, - "Oops AL error after soundmgr resume()!" ); + if (context) { + alcProcessContext( context ); + if ( alGetError() != AL_NO_ERROR) { + SG_LOG( SG_GENERAL, SG_ALERT, + "Oops AL error after soundmgr resume()!" ); + } } } @@ -201,8 +232,6 @@ bool SGSoundMgr::remove( const string &refname ) { if ( sample_it != samples.end() ) { // first stop the sound from playing (so we don't bomb the // audio scheduler) - SGSoundSample *sample = sample_it->second; - delete sample; samples.erase( sample_it ); // cout << "sndmgr: removed -> " << refname << endl;