Skip to content

Commit

Permalink
Reset BASS when switching devices; drop Qt Multimedia support (#262)
Browse files Browse the repository at this point in the history
* Allow changing audio device on the fly while in a server
* Use default audio device if device in config doesn't exist
* Automatically change audio device to default when current one is invalid
* Destroy Qt Multimedia support

It was decided that there was not enough attention being given to Qt
Multimedia support to justify its continued maintenance simply as a
libre alternative to BASS. While substantial changes to audio were being
made in 2.8, the Qt Multimedia support code fell behind in disrepair.
It's clear that there is no vested interest in implementing audio
features twice for the sake of licensing.

When it's time to switch to another audio library, it will be done
unilaterally.

* CI: Use BASS for Linux build

Co-authored-by: oldmud0 <oldmud0@users.noreply.github.com>
  • Loading branch information
mposs00 and oldmud0 committed Aug 19, 2020
1 parent cef0ebc commit 9eb0f53
Show file tree
Hide file tree
Showing 14 changed files with 122 additions and 359 deletions.
22 changes: 11 additions & 11 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ build linux x86_64:
- clang --version

# Extract BASS
#- mkdir bass
#- cd bass
#- curl http://www.un4seen.com/files/bass24-linux.zip -o bass.zip
#- unzip bass.zip
#- cp x64/libbass.so ../lib
#- curl http://www.un4seen.com/files/bassopus24-linux.zip -o bassopus.zip
#- unzip bassopus.zip
#- cp x64/libbassopus.so ../lib
#- cd ..
- mkdir bass
- cd bass
- curl http://www.un4seen.com/files/bass24-linux.zip -o bass.zip
- unzip bass.zip
- cp x64/libbass.so ../lib
- curl http://www.un4seen.com/files/bassopus24-linux.zip -o bassopus.zip
- unzip bassopus.zip
- cp x64/libbassopus.so ../lib
- cd ..

# Extract Discord RPC
- mkdir discord-rpc
Expand All @@ -61,7 +61,7 @@ build linux x86_64:
- cd ..

# Build
- qmake -spec linux-clang "DEFINES += DISCORD QTAUDIO"
- qmake -spec linux-clang "DEFINES += DISCORD"
- make -j4

# Post-processing
Expand Down Expand Up @@ -109,7 +109,7 @@ build windows i686:
- ls lib

# Build
- /opt/mxe/usr/${TARGET_SPEC}/qt5/bin/qmake "DEFINES += DISCORD BASSAUDIO"
- /opt/mxe/usr/${TARGET_SPEC}/qt5/bin/qmake "DEFINES += DISCORD"
- make -j4

# Post-processing
Expand Down
32 changes: 6 additions & 26 deletions Attorney_Online.pro
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,15 @@ contains(DEFINES, DISCORD) {
LIBS += -ldiscord-rpc
}

# Uncomment to enable the BASS audio engine
# (Recommended for Windows)
# DEFINES += BASSAUDIO

contains(DEFINES, BASSAUDIO) {
LIBS += -lbass
LIBS += -lbassopus
}

# Uncomment to enable the Qt audio engine
# (Recommended for non-Windows platforms)
# DEFINES += QTAUDIO

contains(DEFINES, QTAUDIO) {
QT += multimedia
}

AUDIO_DEFINES = $$find(DEFINES, BASSAUDIO) $$find(DEFINES, QTAUDIO)
count(AUDIO_DEFINES, 0) {
warning("No audio system selected. Your build will not have audio.")
}

count(AUDIO_DEFINES, 2) {
error("More than one audio system selected.")
}
# As of 2.8.5, BASS and BASSOPUS are required for all platforms. Qt Multimedia
# is no longer an option due to outdated code and lack of versatility.
# Download at un4seen.com and place the DLLs in the "lib" and "bin" folders.
DEFINES += BASSAUDIO
LIBS += -lbass
LIBS += -lbassopus

macx:LIBS += -framework CoreFoundation -framework Foundation -framework CoreServices


CONFIG += c++14

RESOURCES += resources.qrc
Expand Down
18 changes: 11 additions & 7 deletions include/aoapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include "datatypes.h"
#include "discord_rich_presence.h"

#include "bass.h"
#include "bassopus.h"

#include <QApplication>
#include <QFile>
#include <QSettings>
Expand All @@ -23,9 +26,6 @@
#include <QScreen>
#include <QStringList>
#include <QTextStream>
#ifdef QTAUDIO
#include <QAudioDeviceInfo>
#endif

class NetworkManager;
class Lobby;
Expand Down Expand Up @@ -202,7 +202,8 @@ class AOApplication : public QApplication {

// Returns the value of whether custom chatboxes should be a thing.
// from the config.ini.
// I am increasingly maddened by the lack of dynamic auto-generation system for settings.
// I am increasingly maddened by the lack of dynamic auto-generation system
// for settings.
bool is_customchat_enabled();

// Returns the value of the maximum amount of lines the IC chatlog
Expand All @@ -227,9 +228,6 @@ class AOApplication : public QApplication {

// Returns the audio device used for the client.
QString get_audio_output_device();
#ifdef QTAUDIO
QAudioDeviceInfo QtAudioDevice;
#endif

// Returns whether the user would like to have custom shownames on by default.
bool get_showname_enabled_by_default();
Expand Down Expand Up @@ -442,6 +440,12 @@ class AOApplication : public QApplication {
// The file name of the log file in base/logs.
QString log_filename;

void initBASS();
static void load_bass_opus_plugin();
static void CALLBACK BASSreset(HSTREAM handle, DWORD channel, DWORD data,
void *user);
static void doBASSreset();

private:
const int RELEASE = 2;
const int MAJOR_VERSION = 8;
Expand Down
8 changes: 0 additions & 8 deletions include/aoblipplayer.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
#ifndef AOBLIPPLAYER_H
#define AOBLIPPLAYER_H

#if defined(BASSAUDIO)
#include "bass.h"
#include "bassopus.h"
#elif defined(QTAUDIO)
#include <QSoundEffect>
#endif

#include "aoapplication.h"

Expand Down Expand Up @@ -35,11 +31,7 @@ class AOBlipPlayer {

void set_volume_internal(qreal p_volume);

#if defined(BASSAUDIO)
HSTREAM m_stream_list[5];
#elif defined(QTAUDIO)
QSoundEffect m_blips;
#endif
};

#endif // AOBLIPPLAYER_H
8 changes: 0 additions & 8 deletions include/aomusicplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
#define AOMUSICPLAYER_H
#include "file_functions.h"

#if defined(BASSAUDIO)
#include "bass.h"
#include "bassopus.h"
#elif defined(QTAUDIO)
#include <QMediaPlayer>
#endif

#include "aoapplication.h"

Expand Down Expand Up @@ -44,12 +40,8 @@ public slots:
// Channel 1 = ambience
// Channel 2 = extra
// Channel 3 = extra
#if defined(BASSAUDIO)
HSTREAM m_stream_list[4];
HSYNC loop_sync[4];
#elif defined(QTAUDIO)
QMediaPlayer m_stream_list[4];
#endif
};

#endif // AOMUSICPLAYER_H
8 changes: 0 additions & 8 deletions include/aosfxplayer.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
#ifndef AOSFXPLAYER_H
#define AOSFXPLAYER_H

#if defined(BASSAUDIO)
#include "bass.h"
#include "bassopus.h"
#elif defined(QTAUDIO)
#include <QSoundEffect>
#endif

#include "aoapplication.h"

Expand Down Expand Up @@ -37,11 +33,7 @@ class AOSfxPlayer {

const int m_channelmax = 5;

#if defined(BASSAUDIO)
HSTREAM m_stream_list[5];
#elif defined(QTAUDIO)
QSoundEffect m_stream_list[5];
#endif
};

#endif // AOSFXPLAYER_H
2 changes: 0 additions & 2 deletions include/courtroom.h
Original file line number Diff line number Diff line change
Expand Up @@ -828,8 +828,6 @@ private slots:
void on_casing_clicked();

void ping_server();

void load_bass_opus_plugin();
};

#endif // COURTROOM_H
61 changes: 61 additions & 0 deletions src/aoapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,64 @@ void AOApplication::call_announce_menu(Courtroom *court)
AOCaseAnnouncerDialog announcer(nullptr, this, court);
announcer.exec();
}

// Callback for when BASS device is lost
void CALLBACK AOApplication::BASSreset(HSTREAM handle, DWORD channel,
DWORD data, void *user)
{
doBASSreset();
}

void AOApplication::doBASSreset()
{
BASS_Free();
BASS_Init(-1, 48000, BASS_DEVICE_LATENCY, nullptr, nullptr);
load_bass_opus_plugin();
}

void AOApplication::initBASS()
{
BASS_Free();
// Change the default audio output device to be the one the user has given
// in his config.ini file for now.
unsigned int a = 0;
BASS_DEVICEINFO info;

if (get_audio_output_device() == "default") {
BASS_Init(-1, 48000, BASS_DEVICE_LATENCY, nullptr, nullptr);
load_bass_opus_plugin();
}
else {
for (a = 0; BASS_GetDeviceInfo(a, &info); a++) {
if (get_audio_output_device() == info.name) {
BASS_SetDevice(a);
BASS_Init(static_cast<int>(a), 48000, BASS_DEVICE_LATENCY, nullptr,
nullptr);
load_bass_opus_plugin();
qDebug() << info.name << "was set as the default audio output device.";
return;
}
}
BASS_Init(-1, 48000, BASS_DEVICE_LATENCY, nullptr, nullptr);
load_bass_opus_plugin();
}
}

#if (defined(_WIN32) || defined(_WIN64))
void AOApplication::load_bass_opus_plugin()
{
BASS_PluginLoad("bassopus.dll", 0);
}
#elif (defined(LINUX) || defined(__linux__))
void AOApplication::load_bass_opus_plugin()
{
BASS_PluginLoad("libbassopus.so", 0);
}
#elif defined __APPLE__
void AOApplication::load_bass_opus_plugin()
{
BASS_PluginLoad("libbassopus.dylib", 0);
}
#else
#error This operating system is unsupported for BASS plugins.
#endif
57 changes: 7 additions & 50 deletions src/aoblipplayer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "aoblipplayer.h"

#if defined(BASSAUDIO) // Using bass.dll for the blips
AOBlipPlayer::AOBlipPlayer(QWidget *parent, AOApplication *p_ao_app)
{
m_parent = parent;
Expand Down Expand Up @@ -37,8 +36,14 @@ void AOBlipPlayer::blip_tick()
m_cycle = 0;

HSTREAM f_stream = m_stream_list[f_cycle];
if (ao_app->get_audio_output_device() != "default")

BASS_ChannelSetDevice(f_stream, BASS_GetDevice());
int f_bass_error = BASS_ErrorGetCode();
if (f_bass_error == BASS_ERROR_DEVICE) {
ao_app->doBASSreset();
BASS_ChannelSetDevice(f_stream, BASS_GetDevice());
}

BASS_ChannelPlay(f_stream, false);
}

Expand All @@ -56,51 +61,3 @@ void AOBlipPlayer::set_volume_internal(qreal p_value)
BASS_ChannelSetAttribute(m_stream_list[n_stream], BASS_ATTRIB_VOL, volume);
}
}
#elif defined(QTAUDIO) // Using Qt's QSoundEffect class
AOBlipPlayer::AOBlipPlayer(QWidget *parent, AOApplication *p_ao_app)
{
m_parent = parent;
ao_app = p_ao_app;
}

void AOBlipPlayer::set_blips(QString p_sfx)
{
QString f_path = ao_app->get_sounds_path(p_sfx);

for (int n_stream = 0; n_stream < 5; ++n_stream) {
m_blips.setSource(QUrl::fromLocalFile(f_path));
}

set_volume(m_volume);
}

void AOBlipPlayer::blip_tick()
{
int f_cycle = m_cycle++;

if (m_cycle == 5)
m_cycle = 0;

m_blips.play();
}

void AOBlipPlayer::set_volume(int p_value)
{
m_volume = p_value;
m_blips.setVolume(m_volume);
}
#else // No audio
AOBlipPlayer::AOBlipPlayer(QWidget *parent, AOApplication *p_ao_app)
{
m_parent = parent;
ao_app = p_ao_app;
}

void AOBlipPlayer::set_blips(QString p_sfx) {}

void AOBlipPlayer::blip_tick() {}

void AOBlipPlayer::set_volume(int p_value) {}

void AOBlipPlayer::set_volume_internal(qreal p_value) {}
#endif
Loading

0 comments on commit 9eb0f53

Please sign in to comment.