Skip to content

Commit

Permalink
Refactor|Audio: Locate audio drivers using de::FS
Browse files Browse the repository at this point in the history
The audio plugins are now located using the same
Library_IterateAvailableLibraries() function that is used for finding
other kind of plugins.

Mac OS X: Fixed the dynamic linkage of the fmod driver.
  • Loading branch information
skyjake committed Oct 15, 2012
1 parent f5c44e3 commit 9dbdc1e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 36 deletions.
58 changes: 27 additions & 31 deletions doomsday/engine/portable/src/audiodriver.c
Expand Up @@ -122,35 +122,48 @@ static void importInterfaces(driver_t* d)
#undef Imp
}

static int audioPluginFinder(const char* fileName, const char* absPath, void* ptr)
{
Str* path = (Str*) ptr;
if(!strncmp(fileName, Str_Text(path), Str_Length(path)) /* matching name? */ &&
(strlen(fileName) == Str_Length(path) /* no extension? */
|| fileName[Str_Length(path)] == '.' /* extension follows right away? */))
{
Str_Set(path, absPath);
return true; // Found it!
}
return false; // Keep looking...
}

static AutoStr* findAudioPluginPath(const char* name)
{
AutoStr* path = Str_Appendf(AutoStr_New(), "audio_%s", name);
if(Library_IterateAvailableLibraries(audioPluginFinder, path))
{
// The full path of the library was returned in @a path.
return path;
}
return 0;
}

static boolean loadAudioDriver(driver_t* driver, const char* name)
{
boolean ok = false;

if(name && name[0])
{
Str libPath;

// Compose the name using the prefix "ds".
Str_InitStd(&libPath);
#ifdef WIN32
Str_Appendf(&libPath, "%sds%s.dll", ddBinPath, name);
#elif defined(MACOSX)
Str_Appendf(&libPath, "ds%s.bundle", name);
#else
Str_Appendf(&libPath, "libds%s.so", name);
#endif
AutoStr* libPath = findAudioPluginPath(name);

// Load the audio driver library and import symbols.
if((driver->library = Library_New(Str_Text(&libPath))) != 0)
if(libPath && (driver->library = Library_New(Str_Text(libPath))) != 0)
{
importInterfaces(driver);
ok = true;
}
else
{
Con_Message("Warning: loadAudioDriver: Loading of \"%s\" failed.\n", Str_Text(&libPath));
Con_Message("Warning: loadAudioDriver: Loading of \"%s\" failed.\n", name);
}
Str_Free(&libPath);
}
return ok;
}
Expand Down Expand Up @@ -222,22 +235,6 @@ static boolean initDriver(audiodriverid_t id)
break;
#endif

#ifdef MACOSX
case AUDIOD_OPENAL:
if(!loadAudioDriver(d, "OpenAL"))
return false;
break;

case AUDIOD_FMOD:
if(!loadAudioDriver(d, "FMOD"))
return false;
break;

case AUDIOD_FLUIDSYNTH:
if(!loadAudioDriver(d, "FluidSynth"))
return false;
break;
#else
case AUDIOD_OPENAL:
if(!loadAudioDriver(d, "openal"))
return false;
Expand All @@ -252,7 +249,6 @@ static boolean initDriver(audiodriverid_t id)
if(!loadAudioDriver(d, "fluidsynth"))
return false;
break;
#endif

#ifdef WIN32
case AUDIOD_DSOUND:
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/dd_plugin.c
Expand Up @@ -105,7 +105,7 @@ static int loadPlugin(const char* fileName, const char* pluginPath, void* param)

// This seems to be a Doomsday plugin.
_splitpath(pluginPath, NULL, NULL, name, NULL);
Con_Message(" %s (id:%i)\n", name, plugId);
Con_Message(" (id:%i) %s\n", plugId, name);

*handle = plugin;

Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/portable/src/library.cpp
Expand Up @@ -223,7 +223,7 @@ Library* Library_New(const char *filePath)
if(!handle)
{
Str_Set(lastError, dlerror());
printf("Library_New: Error opening \"%s\" (%s).\n", filePath, Library_LastError());
LOG_WARNING("Library_New: Error opening \"%s\" (%s).") << filePath << Library_LastError();
return 0;
}
#endif
Expand All @@ -233,7 +233,7 @@ Library* Library_New(const char *filePath)
if(!handle)
{
Str_Set(lastError, DD_Win32_GetLastErrorMessage());
printf("Library_New: Error opening \"%s\" (%s).\n", filePath, Library_LastError());
LOG_WARNING("Library_New: Error opening \"%s\" (%s).") << filePath << Library_LastError();
return 0;
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions doomsday/plugins/fmod/fmod.pro
Expand Up @@ -39,8 +39,8 @@ win32 {
else:macx {
# Bundle the FMOD shared library in dsFMOD.bundle.
doPostLink("cp -f \"$$FMOD_DIR/api/lib/libfmodex.dylib\" audio_fmod.bundle/")
doPostLink("install_name_tool -id @executable_path/../../../audio_fmod.bundle/libfmodex.dylib audio_fmod.bundle/libfmodex.dylib")
doPostLink("install_name_tool -change ./libfmodex.dylib @executable_path/../../../audio_fmod.bundle/libfmodex.dylib audio_fmod.bundle/audio_fmod")
doPostLink("install_name_tool -id @executable_path/../DengPlugins/audio_fmod.bundle/libfmodex.dylib audio_fmod.bundle/libfmodex.dylib")
doPostLink("install_name_tool -change ./libfmodex.dylib @executable_path/../DengPlugins/audio_fmod.bundle/libfmodex.dylib audio_fmod.bundle/audio_fmod")
}
else {
INSTALLS += target
Expand Down

0 comments on commit 9dbdc1e

Please sign in to comment.