Skip to content

Commit

Permalink
Audio|FMOD|UI: Added a widget for changing FMOD speaker mode
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Jan 19, 2017
1 parent cc38e3e commit 81e43cc
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 20 deletions.
Expand Up @@ -121,5 +121,6 @@ def setDefaults(d)
d.audio.musicPlugin = 'fmod'
d.audio.cdPlugin = 'fmod'
end
record d.audio.fmod
d.audio.fmod.speakerMode = '' # defaults to stereo
end

25 changes: 19 additions & 6 deletions doomsday/apps/client/src/ui/dialogs/audiosettingsdialog.cpp
Expand Up @@ -49,6 +49,7 @@ DENG_GUI_PIMPL(AudioSettingsDialog)
CVarNativePathWidget *musicSoundfont;
CVarToggleWidget *soundInfo;
GridPopupWidget *devPopup;
VariableChoiceWidget *fmodSpeakerMode;
VariableChoiceWidget *soundPlugin;
VariableChoiceWidget *musicPlugin;
VariableChoiceWidget *cdPlugin;
Expand Down Expand Up @@ -93,6 +94,13 @@ DENG_GUI_PIMPL(AudioSettingsDialog)
area.add(musicPlugin = new VariableChoiceWidget(App::config("audio.musicPlugin")));
area.add(cdPlugin = new VariableChoiceWidget(App::config("audio.cdPlugin")));

area.add(fmodSpeakerMode = new VariableChoiceWidget(App::config("audio.fmod.speakerMode")));
fmodSpeakerMode->items()
<< new ChoiceItem(tr("Stereo"), "")
<< new ChoiceItem(tr("5.1"), "5.1")
<< new ChoiceItem(tr("7.1"), "7.1")
<< new ChoiceItem(tr("SRS 5.1/Prologic"), "prologic");

soundPlugin->items()
<< new ChoiceItem(tr("FMOD"), "fmod")
#if !defined (DENG_DISABLE_SDLMIXER)
Expand Down Expand Up @@ -124,15 +132,17 @@ DENG_GUI_PIMPL(AudioSettingsDialog)
#endif
<< new ChoiceItem(tr("Disabled"), "dummy");

soundPlugin->updateFromVariable();
musicPlugin->updateFromVariable();
cdPlugin ->updateFromVariable();
soundPlugin ->updateFromVariable();
musicPlugin ->updateFromVariable();
cdPlugin ->updateFromVariable();
fmodSpeakerMode->updateFromVariable();

// The audio system needs reinitializing if the plugins are changed.
auto changeFunc = [this] (uint) { audioPluginsChanged = true; };
QObject::connect(soundPlugin, &ChoiceWidget::selectionChangedByUser, changeFunc);
QObject::connect(musicPlugin, &ChoiceWidget::selectionChangedByUser, changeFunc);
QObject::connect(cdPlugin, &ChoiceWidget::selectionChangedByUser, changeFunc);
QObject::connect(soundPlugin, &ChoiceWidget::selectionChangedByUser, changeFunc);
QObject::connect(musicPlugin, &ChoiceWidget::selectionChangedByUser, changeFunc);
QObject::connect(cdPlugin, &ChoiceWidget::selectionChangedByUser, changeFunc);
QObject::connect(fmodSpeakerMode, &ChoiceWidget::selectionChangedByUser, changeFunc);
}

void fetch()
Expand Down Expand Up @@ -213,6 +223,9 @@ AudioSettingsDialog::AudioSettingsDialog(String const &name)
<< *musicPluginLabel << *d->musicPlugin
<< *cdPluginLabel << *d->cdPlugin;

auto *speakerLabel = LabelWidget::newWithText(tr("FMOD Speaker Mode:"), &area());
layout << *speakerLabel << *d->fmodSpeakerMode;

area().setContentSize(layout.width(), layout.height());

buttons()
Expand Down
41 changes: 28 additions & 13 deletions doomsday/apps/plugins/fmod/src/driver_fmod.cpp
Expand Up @@ -49,6 +49,7 @@

#include "doomsday.h"
#include <de/c_wrapper.h>
#include <de/Config>

FMOD::System* fmodSystem = 0;

Expand All @@ -57,14 +58,14 @@ FMOD::System* fmodSystem = 0;
*/
int DS_Init(void)
{
if(fmodSystem)
if (fmodSystem)
{
return true; // Already initialized.
}

// Create the FMOD audio system.
FMOD_RESULT result;
if((result = FMOD::System_Create(&fmodSystem)) != FMOD_OK)
if ((result = FMOD::System_Create(&fmodSystem)) != FMOD_OK)
{
LOGDEV_AUDIO_ERROR("FMOD::System_Create failed (%d) %s") << result << FMOD_ErrorString(result);
fmodSystem = 0;
Expand All @@ -75,28 +76,42 @@ int DS_Init(void)
// Figure out the system's configured speaker mode.
FMOD_SPEAKERMODE speakerMode;
result = fmodSystem->getDriverCaps(0, 0, 0, &speakerMode);
if(result == FMOD_OK)
if (result == FMOD_OK)
{
fmodSystem->setSpeakerMode(speakerMode);
}
#endif

de::String const speakerMode = de::Config::get().gets("audio.fmod.speakerMode", "");
if (speakerMode == "5.1")
{
fmodSystem->setSpeakerMode(FMOD_SPEAKERMODE_5POINT1);
}
else if (speakerMode == "7.1")
{
fmodSystem->setSpeakerMode(FMOD_SPEAKERMODE_7POINT1);
}
else if (speakerMode == "prologic")
{
fmodSystem->setSpeakerMode(FMOD_SPEAKERMODE_SRS5_1_MATRIX);
}

// Manual overrides.
if(CommandLine_Exists("-speaker51"))
if (CommandLine_Exists("-speaker51"))
{
fmodSystem->setSpeakerMode(FMOD_SPEAKERMODE_5POINT1);
}
if(CommandLine_Exists("-speaker71"))
if (CommandLine_Exists("-speaker71"))
{
fmodSystem->setSpeakerMode(FMOD_SPEAKERMODE_7POINT1);
}
if(CommandLine_Exists("-speakerprologic"))
if (CommandLine_Exists("-speakerprologic"))
{
fmodSystem->setSpeakerMode(FMOD_SPEAKERMODE_SRS5_1_MATRIX);
}

// Initialize FMOD.
if((result = fmodSystem->init(50, FMOD_INIT_NORMAL | FMOD_INIT_3D_RIGHTHANDED | FMOD_INIT_HRTF_LOWPASS, 0)) != FMOD_OK)
if ((result = fmodSystem->init(50, FMOD_INIT_NORMAL | FMOD_INIT_3D_RIGHTHANDED | FMOD_INIT_HRTF_LOWPASS, 0)) != FMOD_OK)
{
LOGDEV_AUDIO_ERROR("FMOD init failed: (%d) %s") << result << FMOD_ErrorString(result);
fmodSystem->release();
Expand All @@ -116,7 +131,7 @@ int DS_Init(void)
int numPlugins = 0;
fmodSystem->getNumPlugins(FMOD_PLUGINTYPE_CODEC, &numPlugins);
DSFMOD_TRACE("Plugins loaded: " << numPlugins);
for(int i = 0; i < numPlugins; i++)
for (int i = 0; i < numPlugins; i++)
{
unsigned int handle;
fmodSystem->getPluginHandle(FMOD_PLUGINTYPE_CODEC, i, &handle);
Expand Down Expand Up @@ -157,9 +172,9 @@ void DS_Shutdown(void)
*/
void DS_Event(int type)
{
if(!fmodSystem) return;
if (!fmodSystem) return;

if(type == SFXEV_END)
if (type == SFXEV_END)
{
// End of frame, do an update.
fmodSystem->update();
Expand All @@ -168,14 +183,14 @@ void DS_Event(int type)

int DS_Set(int prop, const void* ptr)
{
if(!fmodSystem) return false;
if (!fmodSystem) return false;

switch(prop)
switch (prop)
{
case AUDIOP_SOUNDFONT_FILENAME: {
const char* path = reinterpret_cast<const char*>(ptr);
DSFMOD_TRACE("DS_Set: Soundfont = " << path);
if(!path || !strlen(path))
if (!path || !strlen(path))
{
// Use the default.
path = 0;
Expand Down

0 comments on commit 81e43cc

Please sign in to comment.