Skip to content

Commit

Permalink
Windows|MinGW: Further changes for MinGW
Browse files Browse the repository at this point in the history
Use the FMOD C API instead of C++.
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent a38459a commit 5aad684
Show file tree
Hide file tree
Showing 17 changed files with 130 additions and 540 deletions.
2 changes: 1 addition & 1 deletion doomsday/apps/client/CMakeLists.txt
Expand Up @@ -214,7 +214,7 @@ elseif (APPLE)
endif ()
endif ()
if (TARGET SDL2)
target_link_libraries (client PUBLIC SDL2)
target_link_libraries (client PUBLIC mingw32 SDL2)
endif ()
if (TARGET SDL2_mixer)
target_link_libraries (client PUBLIC SDL2_mixer)
Expand Down
45 changes: 0 additions & 45 deletions doomsday/apps/client/include/ui/mouse_qt.h

This file was deleted.

4 changes: 2 additions & 2 deletions doomsday/apps/client/libs/fluidsynth/CMakeLists.txt
Expand Up @@ -8,12 +8,12 @@ include (../ExtensionConfig.cmake)
set (tgt audio_fluidsynth)

# Make an embedded build by default?
if (APPLE OR MSYS2_LIBS_DIR)
if (APPLE)
set (embed ON)
elseif (UNIX)
set (embed OFF)
endif ()
if (WIN32 AND NOT MSYS2_LIBS_DIR)
if (WIN32 AND NOT MINGW)
message (STATUS "Not building ${tgt} because the MSYS2 version of glib-2.0 is required on Windows (set MSYS2_LIBS_DIR)")
return ()
endif ()
Expand Down
9 changes: 1 addition & 8 deletions doomsday/apps/client/libs/fmod/include/driver_fmod.h
Expand Up @@ -48,31 +48,24 @@
#define __DSFMOD_DRIVER_H__

#include <fmod.h>
#include <fmod.hpp>
#include <fmod_errors.h>
#include <stdio.h>
#include <cassert>
#include <iostream>
#include <de/Log>
#include "api_console.h"

//DE_ENTRYPOINT int DS_Init(void);
//DE_ENTRYPOINT void DS_Shutdown(void);
//DE_ENTRYPOINT void DS_Event(int type);
//DE_ENTRYPOINT int DS_Set(int prop, const void* ptr);

#define DSFMOD_TRACE(args) LOGDEV_AUDIO_XVERBOSE("[FMOD] ", args)

#define DSFMOD_ERRCHECK(result) \
if(result != FMOD_OK) { \
LOGDEV_AUDIO_WARNING("[FMOD] Error at %s, line %i: (%d) %s") << __FILE__ << __LINE__ << result << FMOD_ErrorString(result); \
}

extern FMOD::System *fmodSystem;
extern FMOD_SYSTEM *fmodSystem;

#include "fmod_sfx.h"
#include "fmod_music.h"
//#include "fmod_cd.h"
#include "fmod_util.h"

DE_USING_API(Con);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/libs/fmod/include/fmod_music.h
Expand Up @@ -59,7 +59,7 @@ int fmod_DM_Music_PlayFile(const char *filename, int looped);

// Internal:
void fmod_Music_Shutdown(void);
bool fmod_Music_PlaySound(FMOD::Sound* customSound, bool needRelease);
bool fmod_Music_PlaySound(FMOD_SOUND *customSound, bool needRelease);
void fmod_Music_Pause(int setPause);
void fmod_Music_Stop(void);
void fmod_Music_Set(int prop, float value);
Expand Down
57 changes: 23 additions & 34 deletions doomsday/apps/client/libs/fmod/src/driver_fmod.cpp
Expand Up @@ -46,7 +46,6 @@
#include <stdio.h>
#include <fmod.h>
#include <fmod_errors.h>
#include <fmod.hpp>

#include "doomsday.h"
#include <de/c_wrapper.h>
Expand All @@ -67,7 +66,7 @@ struct Driver
int speakerModeChannels;
};

FMOD::System * fmodSystem;
FMOD_SYSTEM * fmodSystem;
static de::List<Driver> fmodDrivers;

static const char *speakerModeText(FMOD_SPEAKERMODE mode)
Expand Down Expand Up @@ -101,7 +100,7 @@ static int DS_Init(void)

// 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 @@ -114,15 +113,15 @@ static int DS_Init(void)
// Check what kind of drivers are available.
{
int numDrivers = 0;
fmodSystem->getNumDrivers(&numDrivers);
FMOD_System_GetNumDrivers(fmodSystem, &numDrivers);
fmodDrivers.resize(numDrivers);
std::unique_ptr<de::ArrayValue> names(new de::ArrayValue);
for (int i = 0; i < numDrivers; ++i)
{
auto &drv = fmodDrivers[i];
char nameBuf[512];
zap(nameBuf);
fmodSystem->getDriverInfo(i, nameBuf, sizeof(nameBuf),
FMOD_System_GetDriverInfo(fmodSystem, i, nameBuf, sizeof(nameBuf),
&drv.guid, &drv.systemRate,
&drv.speakerMode, &drv.speakerModeChannels);
drv.name = String::format("%s (%s)", nameBuf, speakerModeText(drv.speakerMode));
Expand All @@ -143,7 +142,7 @@ static int DS_Init(void)
int configuredDriverIndex = Config::get().geti("audio.output", 0);
if (configuredDriverIndex < fmodDrivers.size())
{
result = fmodSystem->setDriver(configuredDriverIndex);
result = FMOD_System_SetDriver(fmodSystem, configuredDriverIndex);
if (result != FMOD_OK)
{
LOG_AUDIO_ERROR("Failed to select FMOD audio driver: %s")
Expand All @@ -153,54 +152,44 @@ static int DS_Init(void)
}

#if 0
#ifdef WIN32
{
// Figure out the system's configured default speaker mode.
FMOD_SPEAKERMODE speakerMode;
result = fmodSystem->getDriverCaps(0, 0, 0, &speakerMode);
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);
FMOD_System_SetSpeakerMode(fmodSystem, FMOD_SPEAKERMODE_5POINT1);
}
else if (speakerMode == "7.1")
{
fmodSystem->setSpeakerMode(FMOD_SPEAKERMODE_7POINT1);
FMOD_System_SetSpeakerMode(fmodSystem, FMOD_SPEAKERMODE_7POINT1);
}
else if (speakerMode == "prologic")
{
fmodSystem->setSpeakerMode(FMOD_SPEAKERMODE_SRS5_1_MATRIX);
FMOD_System_SetSpeakerMode(fmodSystem, FMOD_SPEAKERMODE_SRS5_1_MATRIX);
}

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

// Initialize FMOD.
if ((result = fmodSystem->init(
50, FMOD_INIT_NORMAL | FMOD_INIT_3D_RIGHTHANDED | FMOD_INIT_CHANNEL_LOWPASS, 0)) !=
FMOD_OK)
if ((result = FMOD_System_Init(fmodSystem,
50,
FMOD_INIT_NORMAL |
FMOD_INIT_3D_RIGHTHANDED |
FMOD_INIT_CHANNEL_LOWPASS, 0)) != FMOD_OK)
{
LOGDEV_AUDIO_ERROR("FMOD init failed: (%d) %s") << result << FMOD_ErrorString(result);
fmodSystem->release();
FMOD_System_Release(fmodSystem);
fmodSystem = 0;
return false;
}
Expand All @@ -212,21 +201,21 @@ static int DS_Init(void)
settings.HRTFMaxAngle = 360;
settings.HRTFMinAngle = 180;
settings.HRTFFreq = 11000;
fmodSystem->setAdvancedSettings(&settings);
FMOD_System_SetAdvancedSettings(fmodSystem, &settings);

#ifdef _DEBUG
int numPlugins = 0;
fmodSystem->getNumPlugins(FMOD_PLUGINTYPE_CODEC, &numPlugins);
FMOD_System_GetNumPlugins(fmodSystem, FMOD_PLUGINTYPE_CODEC, &numPlugins);
DSFMOD_TRACE("Plugins loaded: " << numPlugins);
for (int i = 0; i < numPlugins; i++)
{
unsigned int handle;
fmodSystem->getPluginHandle(FMOD_PLUGINTYPE_CODEC, i, &handle);
FMOD_System_GetPluginHandle(fmodSystem, FMOD_PLUGINTYPE_CODEC, i, &handle);

FMOD_PLUGINTYPE pType;
char pName[100];
unsigned int pVer = 0;
fmodSystem->getPluginInfo(handle, &pType, pName, sizeof(pName), &pVer);
FMOD_System_GetPluginInfo(fmodSystem, handle, &pType, pName, sizeof(pName), &pVer);

DSFMOD_TRACE("Plugin " << i << ", handle " << handle << ": type " << pType
<< ", name:'" << pName << "', ver:" << pVer);
Expand All @@ -246,7 +235,7 @@ static void DS_Shutdown(void)
//DMFmod_CDAudio_Shutdown();

DSFMOD_TRACE("DS_Shutdown.");
fmodSystem->release();
FMOD_System_Release(fmodSystem);
fmodSystem = 0;
}

Expand All @@ -261,7 +250,7 @@ static void DS_Event(int type)
if (type == SFXEV_END)
{
// End of frame, do an update.
fmodSystem->update();
FMOD_System_Update(fmodSystem);
}
}

Expand Down
37 changes: 21 additions & 16 deletions doomsday/apps/client/libs/fmod/src/fmod_music.cpp
Expand Up @@ -58,8 +58,8 @@ struct SongBuffer
}
};

static FMOD::Sound * song;
static FMOD::Channel *music;
static FMOD_SOUND * song;
static FMOD_CHANNEL * music;
static bool needReleaseSong;
static float musicVolume;
static SongBuffer * songBuffer;
Expand All @@ -74,7 +74,7 @@ musicCallback(FMOD_CHANNELCONTROL *channelcontrol,
if (controltype != FMOD_CHANNELCONTROL_CHANNEL)
return FMOD_OK;

if (reinterpret_cast<FMOD::Channel *>(channelcontrol) != music)
if (reinterpret_cast<FMOD_CHANNEL *>(channelcontrol) != music)
return FMOD_OK; // Safety check.

switch (callbacktype)
Expand All @@ -97,7 +97,7 @@ static void releaseSong()
if (needReleaseSong)
{
DSFMOD_TRACE("releaseSong: Song " << song << " will be released.");
song->release();
FMOD_Sound_Release(song);
}
else
{
Expand All @@ -123,7 +123,9 @@ static void setDefaultStreamBufferSize()
if (!fmodSystem) return;

FMOD_RESULT result;
result = fmodSystem->setStreamBufferSize(16*1024, FMOD_TIMEUNIT_RAWBYTES);
result = FMOD_System_SetStreamBufferSize(fmodSystem,
16 * 1024,
FMOD_TIMEUNIT_RAWBYTES);
DSFMOD_ERRCHECK(result);
}

Expand Down Expand Up @@ -177,7 +179,7 @@ void fmod_Music_Set(int prop, float value)
{
case MUSIP_VOLUME:
musicVolume = value;
if (music) music->setVolume(musicVolume);
if (music) FMOD_Channel_SetVolume(music, musicVolume);
DSFMOD_TRACE("Music_Set: MUSIP_VOLUME = " << musicVolume);
break;

Expand Down Expand Up @@ -230,7 +232,7 @@ void fmod_Music_Stop(void)

DSFMOD_TRACE("Music_Stop.");

music->stop();
FMOD_Channel_Stop(music);
}

void fmod_DM_Music_Stop(void)
Expand All @@ -242,23 +244,23 @@ static bool startSong()
{
if (!fmodSystem || !song) return false;

if (music) music->stop();
if (music) FMOD_Channel_Stop(music);

// Start playing the song.
FMOD_RESULT result;
result = fmodSystem->playSound(song, nullptr, true, &music);
result = FMOD_System_PlaySound(fmodSystem, song, nullptr, true, &music);
DSFMOD_ERRCHECK(result);

// Properties.
music->setVolume(musicVolume);
music->setCallback(musicCallback);
FMOD_Channel_SetVolume(music, musicVolume);
FMOD_Channel_SetCallback(music, musicCallback);

// Start playing.
music->setPaused(false);
FMOD_Channel_SetPaused(music, false);
return true;
}

bool fmod_Music_PlaySound(FMOD::Sound* customSound, bool needRelease)
bool fmod_Music_PlaySound(FMOD_SOUND* customSound, bool needRelease)
{
releaseSong();
releaseSongBuffer();
Expand Down Expand Up @@ -290,7 +292,8 @@ int fmod_DM_Music_Play(int looped)

// Load a new song.
FMOD_RESULT result;
result = fmodSystem->createSound(songBuffer->data,
result = FMOD_System_CreateSound(fmodSystem,
songBuffer->data,
FMOD_CREATESTREAM | FMOD_OPENMEMORY |
(looped? FMOD_LOOP_NORMAL : 0),
&extra, &song);
Expand All @@ -308,7 +311,7 @@ void fmod_Music_Pause(int setPause)
{
if (!fmodSystem || !music) return;

music->setPaused(setPause != 0);
FMOD_Channel_SetPaused(music, setPause != 0);
}

void fmod_DM_Music_Pause(int setPause)
Expand Down Expand Up @@ -348,7 +351,9 @@ int fmod_DM_Music_PlayFile(const char *filename, int looped)
}

FMOD_RESULT result;
result = fmodSystem->createSound(filename, FMOD_CREATESTREAM | (looped? FMOD_LOOP_NORMAL : 0),
result = FMOD_System_CreateSound(fmodSystem,
filename,
FMOD_CREATESTREAM | (looped? FMOD_LOOP_NORMAL : 0),
&extra, &song);
DSFMOD_TRACE("Music_Play: loaded '" << filename << "' => Sound " << song);
DSFMOD_ERRCHECK(result);
Expand Down

0 comments on commit 5aad684

Please sign in to comment.