char CFMOD::InitializeSound() { char x; FSOUND_SetMinHardwareChannels(8); FSOUND_SetMaxHardwareChannels(MAX_SND_CHANNELS); x = FSOUND_Init(44100, MAX_SND_CHANNELS, 0); Log->AddEntry(va("FMOD Version: %.2f started",FSOUND_GetVersion())); if(x) { bfmod=1; maxchannels=FSOUND_GetMaxChannels(); Log->AddEntry(va("FMOD Max Channels [%d]",maxchannels)); } else { bfmod=0; return 0; } SetSoundVolume(svol); return x; }
bool LLAudioEngine_FMOD::init(const S32 num_channels, void* userdata) { LLAudioEngine::init(num_channels, userdata); // Reserve one extra channel for the http stream. if (!FSOUND_SetMinHardwareChannels(num_channels + 1)) { LL_WARNS("AppInit") << "FMOD::init[0](), error: " << FMOD_ErrorString(FSOUND_GetError()) << LL_ENDL; } LL_DEBUGS("AppInit") << "LLAudioEngine_FMOD::init() initializing FMOD" << LL_ENDL; F32 version = FSOUND_GetVersion(); if (version < FMOD_VERSION) { LL_WARNS("AppInit") << "Error : You are using the wrong FMOD version (" << version << ")! You should be using FMOD " << FMOD_VERSION << LL_ENDL; //return false; } U32 fmod_flags = 0x0; #if LL_WINDOWS // Windows needs to know which window is frontmost. // This must be called before FSOUND_Init() per the FMOD docs. // This could be used to let FMOD handle muting when we lose focus, // but we don't actually want to do that because we want to distinguish // between minimized and not-focused states. if (!FSOUND_SetHWND(userdata)) { LL_WARNS("AppInit") << "Error setting FMOD window: " << FMOD_ErrorString(FSOUND_GetError()) << LL_ENDL; return false; } // Play audio when we don't have focus. // (For example, IM client on top of us.) // This means we also try to play audio when minimized, // so we manually handle muting in that case. JC fmod_flags |= FSOUND_INIT_GLOBALFOCUS; fmod_flags |= FSOUND_INIT_DSOUND_HRTF_FULL; #endif #if LL_LINUX // initialize the FMOD engine // This is a hack to use only FMOD's basic FPU mixer // when the LL_VALGRIND environmental variable is set, // otherwise valgrind will fall over on FMOD's MMX detection if (getenv("LL_VALGRIND")) /*Flawfinder: ignore*/ { LL_INFOS("AppInit") << "Pacifying valgrind in FMOD init." << LL_ENDL; FSOUND_SetMixer(FSOUND_MIXER_QUALITY_FPU); } // If we don't set an output method, Linux FMOD always // decides on OSS and fails otherwise. So we'll manually // try ESD, then OSS, then ALSA. // Why this order? See SL-13250, but in short, OSS emulated // on top of ALSA is ironically more reliable than raw ALSA. // Ack, and ESD has more reliable failure modes - but has worse // latency - than all of them, so wins for now. bool audio_ok = false; if (!audio_ok) { if (NULL == getenv("LL_BAD_FMOD_ESD")) /*Flawfinder: ignore*/ { LL_DEBUGS("AppInit") << "Trying ESD audio output..." << LL_ENDL; if(FSOUND_SetOutput(FSOUND_OUTPUT_ESD) && FSOUND_Init(44100, num_channels, fmod_flags)) { LL_DEBUGS("AppInit") << "ESD audio output initialized OKAY" << LL_ENDL; audio_ok = true; } else { LL_WARNS("AppInit") << "ESD audio output FAILED to initialize: " << FMOD_ErrorString(FSOUND_GetError()) << LL_ENDL; } } else { LL_DEBUGS("AppInit") << "ESD audio output SKIPPED" << LL_ENDL; } } if (!audio_ok) { if (NULL == getenv("LL_BAD_FMOD_OSS")) /*Flawfinder: ignore*/ { LL_DEBUGS("AppInit") << "Trying OSS audio output..." << LL_ENDL; if(FSOUND_SetOutput(FSOUND_OUTPUT_OSS) && FSOUND_Init(44100, num_channels, fmod_flags)) { LL_DEBUGS("AppInit") << "OSS audio output initialized OKAY" << LL_ENDL; audio_ok = true; } else { LL_WARNS("AppInit") << "OSS audio output FAILED to initialize: " << FMOD_ErrorString(FSOUND_GetError()) << LL_ENDL; } } else { LL_DEBUGS("AppInit") << "OSS audio output SKIPPED" << LL_ENDL; } } if (!audio_ok) { if (NULL == getenv("LL_BAD_FMOD_ALSA")) /*Flawfinder: ignore*/ { LL_DEBUGS("AppInit") << "Trying ALSA audio output..." << LL_ENDL; if(FSOUND_SetOutput(FSOUND_OUTPUT_ALSA) && FSOUND_Init(44100, num_channels, fmod_flags)) { LL_DEBUGS("AppInit") << "ALSA audio output initialized OKAY" << LL_ENDL; audio_ok = true; } else { LL_WARNS("AppInit") << "ALSA audio output FAILED to initialize: " << FMOD_ErrorString(FSOUND_GetError()) << LL_ENDL; } } else { LL_DEBUGS("AppInit") << "OSS audio output SKIPPED" << LL_ENDL; } } if (!audio_ok) { LL_WARNS("AppInit") << "Overall audio init failure." << LL_ENDL; return false; } // On Linux, FMOD causes a SIGPIPE for some netstream error // conditions (an FMOD bug); ignore SIGPIPE so it doesn't crash us. // NOW FIXED in FMOD 3.x since 2006-10-01. //signal(SIGPIPE, SIG_IGN); // We're interested in logging which output method we // ended up with, for QA purposes. switch (FSOUND_GetOutput()) { case FSOUND_OUTPUT_NOSOUND: LL_DEBUGS("AppInit") << "Audio output: NoSound" << LL_ENDL; break; case FSOUND_OUTPUT_OSS: LL_DEBUGS("AppInit") << "Audio output: OSS" << LL_ENDL; break; case FSOUND_OUTPUT_ESD: LL_DEBUGS("AppInit") << "Audio output: ESD" << LL_ENDL; break; case FSOUND_OUTPUT_ALSA: LL_DEBUGS("AppInit") << "Audio output: ALSA" << LL_ENDL; break; default: LL_INFOS("AppInit") << "Audio output: Unknown!" << LL_ENDL; break; }; #else // LL_LINUX // initialize the FMOD engine if (!FSOUND_Init(44100, num_channels, fmod_flags)) { LL_WARNS("AppInit") << "Error initializing FMOD: " << FMOD_ErrorString(FSOUND_GetError()) << LL_ENDL; return false; } #endif // set up our favourite FMOD-native streaming audio implementation if none has already been added if (!getStreamingAudioImpl()) // no existing implementation added setStreamingAudioImpl(new LLStreamingAudio_FMOD()); LL_DEBUGS("AppInit") << "LLAudioEngine_FMOD::init() FMOD initialized correctly" << LL_ENDL; mInited = true; return true; }
/****************************************************************************** * * Initialise driver and listener * *****************************************************************************/ EXPORT INT32 HWRAPI(Startup) (I_Error_t FatalErrorFunction, snddev_t *snd_dev) { boolean inited = false; INT32 i = 0; I_ErrorFMOD = FatalErrorFunction; if (FSOUND_GetVersion() < FMOD_VERSION) { DBG_Printf("Error : You are using the wrong DLL version!\nYou should be using FMOD %.02f\n", FMOD_VERSION); return inited; } else DBG_Printf("S_FMOD Init(): FMOD_SOUND driver for SRB2 %s\n",VERSIONSTRING); if (!FSOUND_SetMinHardwareChannels(STATIC_SOURCES_NUM*4)) DBG_Printf("FMOD(Startup,FSOUND_SetMinHardwareChannels,# of Channels Min: %i): %s\n",STATIC_SOURCES_NUM*4, FMOD_ErrorString(FSOUND_GetError())); if (!FSOUND_SetMaxHardwareChannels(0)) DBG_Printf("FMOD(Startup,FSOUND_SetMaxHardwareChannels,# of Channels Min: %i): %s\n",0, FMOD_ErrorString(FSOUND_GetError())); for (i = 0; i < FSOUND_GetNumDrivers(); i++) { UINT32 caps = 0; DBG_Printf("Driver Caps, if any\n"); if (FSOUND_GetDriverCaps(i, &caps)) { DBG_Printf("FMOD: Driver# %d - %s\n", i+1, FSOUND_GetDriverName(i)); // print driver names if (caps & FSOUND_CAPS_HARDWARE) DBG_Printf("This sound hardware supports hardware accelerated 3d sound.\n"); if (caps & FSOUND_CAPS_EAX2) DBG_Printf("This sound hardware supports hardware accelerated 3d sound with EAX 2 reverb.\n"); if (caps & FSOUND_CAPS_EAX3) DBG_Printf("This sound hardware supports hardware accelerated 3d sound with EAX 3 reverb.\n"); } else DBG_Printf("FMOD(Startup,FSOUND_GetDriverCaps,%s): %s\n",FSOUND_GetDriverName(i), FMOD_ErrorString(FSOUND_GetError())); } #if defined (_WIN32) || defined (_WIN64) if (!FSOUND_SetHWND(snd_dev->hWnd)) { DBG_Printf("FMOD(Startup,FSOUND_SetHWND): %s\n", FMOD_ErrorString(FSOUND_GetError())); return inited; } else #endif { DBG_Printf("Initialising FMOD %.02f\n",FMOD_VERSION); inited = FSOUND_Init(snd_dev->sample_rate,MAXCHANNEL,0); } if (!inited) { DBG_Printf("FMOD(Startup,Main): %s\n", FMOD_ErrorString(FSOUND_GetError())); } else { #ifdef OLDFMOD DBG_Printf(" Maximum hardware mixing buffers %d\n", FSOUND_GetNumHardwareChannels()); #else INT32 num2DC, num3DC, numDC; if (FSOUND_GetNumHWChannels(&num2DC,&num3DC,&numDC)) { DBG_Printf(" Maximum hardware 2D buffers %d\n", num2DC); DBG_Printf(" Maximum hardware 3D buffers %d\n", num3DC); DBG_Printf(" Maximum hardware mixing buffers %d\n", numDC); } else DBG_Printf("FMOD(Startup,FSOUND_GetNumHWChannels): %s\n", FMOD_ErrorString(FSOUND_GetError())); #endif DBG_Printf("FMOD is up and running at %i KHZ\n",FSOUND_GetOutputRate()); DBG_Printf("Sound hardware capabilities:\n"); if (FSOUND_GetDriverName(FSOUND_GetDriver())) DBG_Printf(" Driver is %s\n",FSOUND_GetDriverName(FSOUND_GetDriver())); else DBG_Printf("FMOD(Startup,FSOUND_GetDriverName): %s\n", FMOD_ErrorString(FSOUND_GetError())); FSOUND_3D_SetDistanceFactor(1.0f/72.0f); FSOUND_3D_SetRolloffFactor(0); FSOUND_3D_SetRolloffFactor(1.6f); #ifdef MORESTUFF FSOUND_3D_SetDopplerFactor(0); #endif switch (FSOUND_GetOutput()) { case FSOUND_OUTPUT_NOSOUND: DBG_Printf("FMOD driver: NoSound driver, all calls to this succeed but do nothing.\n"); break; case FSOUND_OUTPUT_WINMM: DBG_Printf("FMOD driver: Windows Multimedia driver.\n"); break; case FSOUND_OUTPUT_DSOUND: DBG_Printf("FMOD driver: DirectSound driver. You need this to get EAX2 or EAX3 support, or FX api support.\n"); break; case FSOUND_OUTPUT_A3D: DBG_Printf("FMOD driver: A3D driver.\n"); break; case FSOUND_OUTPUT_XBOX: DBG_Printf("FMOD driver: Xbox driver\n"); break; case FSOUND_OUTPUT_OSS: DBG_Printf("FMOD driver: Linux/Unix OSS (Open Sound System) driver, i.e. the kernel sound drivers.\n"); break; case FSOUND_OUTPUT_ESD: DBG_Printf("FMOD driver: Linux/Unix ESD (Enlightment Sound Daemon) driver.\n"); break; case FSOUND_OUTPUT_ALSA: DBG_Printf("FMOD driver: Linux Alsa driver.\n"); break; case FSOUND_OUTPUT_MAC: DBG_Printf("FMOD driver: Mac SoundManager driver\n"); break; case FSOUND_OUTPUT_PS2: DBG_Printf("FMOD driver: PlayStation 2 driver\n"); break; case FSOUND_OUTPUT_GC: DBG_Printf("FMOD driver: Gamecube driver\n"); break; case FSOUND_OUTPUT_NOSOUND_NONREALTIME: DBG_Printf("FMOD driver: This is the same as nosound, but the sound generation is driven by FSOUND_Update\n"); break; case FSOUND_OUTPUT_ASIO: DBG_Printf("FMOD driver: Low latency ASIO driver\n"); break; default: DBG_Printf("FMOD driver: Unknown Sound Driver\n"); break; } relsetup(); blankfmsample = FSOUND_Sample_Alloc(FSOUND_UNMANAGED,1,FSOUND_UNORMAL,11025,127,FSOUND_STEREOPAN,127); if (!blankfmsample) DBG_Printf("FMOD(Startup,FSOUND_Sample_Alloc): %s\n", FMOD_ErrorString(FSOUND_GetError())); else if (!FSOUND_Sample_SetMaxPlaybacks(blankfmsample,STATIC_SOURCES_NUM*2)) DBG_Printf("FMOD(Startup,FSOUND_Sample_SetMaxPlaybacks): %s\n", FMOD_ErrorString(FSOUND_GetError())); } return inited; }