Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio fixes #262

Merged
merged 11 commits into from
Aug 19, 2020
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
12 changes: 0 additions & 12 deletions include/aoapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@
#include "datatypes.h"
#include "discord_rich_presence.h"

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

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

class NetworkManager;
class Lobby;
Expand Down Expand Up @@ -226,9 +219,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 @@ -443,10 +433,8 @@ class AOApplication : public QApplication {

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

private:
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
11 changes: 2 additions & 9 deletions src/aoapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ void AOApplication::call_announce_menu(Courtroom *court)
announcer.exec();
}

#ifdef BASSAUDIO
// Callback for when BASS device is lost
void CALLBACK AOApplication::BASSreset(HSTREAM handle, DWORD channel,
DWORD data, void *user)
Expand Down Expand Up @@ -220,28 +219,22 @@ void AOApplication::initBASS()
load_bass_opus_plugin();
}
}
#endif

#if (defined(_WIN32) || defined(_WIN64))
void AOApplication::load_bass_opus_plugin()
{
#ifdef BASSAUDIO
BASS_PluginLoad("bassopus.dll", 0);
#endif
}
#elif (defined(LINUX) || defined(__linux__))
void AOApplication::load_bass_opus_plugin()
{
#ifdef BASSAUDIO
BASS_PluginLoad("libbassopus.so", 0);
#endif
}
#elif defined __APPLE__
void AOApplication::load_bass_opus_plugin()
{
#ifdef BASSAUDIO
BASS_PluginLoad("libbassopus.dylib", 0);
#endif
}
#else
#error This operating system is unsupported for bass plugins.
#error This operating system is unsupported for BASS plugins.
#endif
49 changes: 0 additions & 49 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 @@ -62,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
53 changes: 0 additions & 53 deletions src/aomusicplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ AOMusicPlayer::AOMusicPlayer(QWidget *parent, AOApplication *p_ao_app)
ao_app = p_ao_app;
}

#ifdef BASSAUDIO

AOMusicPlayer::~AOMusicPlayer()
{
for (int n_stream = 0; n_stream < m_channelmax; ++n_stream) {
Expand Down Expand Up @@ -176,54 +174,3 @@ void AOMusicPlayer::set_looping(bool toggle, int channel)
}
}
}
#elif defined(QTAUDIO)

AOMusicPlayer::~AOMusicPlayer()
{
for (int n_stream = 0; n_stream < m_channelmax; ++n_stream) {
m_stream_list[n_stream].stop();
}
}

void AOMusicPlayer::play(QString p_song, int channel, bool loop,
int effect_flags)
{
channel = channel % m_channelmax;
if (channel < 0) // wtf?
return;
QString f_path = ao_app->get_music_path(p_song);

m_stream_list[channel].stop();

m_stream_list[channel].setMedia(QUrl::fromLocalFile(f_path));

this->set_volume(m_volume[channel], channel);

m_stream_list[channel].play();
}

void AOMusicPlayer::stop(int channel) { m_stream_list[channel].stop(); }

void AOMusicPlayer::set_volume(int p_value, int channel)
{
m_volume[channel] = p_value;
m_stream_list[channel].setVolume(m_volume[channel]);
}

#else

AOMusicPlayer::~AOMusicPlayer() {}

void AOMusicPlayer::play(QString p_song, int channel, bool loop,
int effect_flags)
{
}

void AOMusicPlayer::stop(int channel) {}

void AOMusicPlayer::set_volume(int p_value, int channel) {}

void loopProc(int handle, int channel, int data, int *user) {}

void AOMusicPlayer::set_looping(bool toggle, int channel) {}
#endif
12 changes: 0 additions & 12 deletions src/aooptionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,23 +402,13 @@ AOOptionsDialog::AOOptionsDialog(QWidget *parent, AOApplication *p_ao_app)

ui_audio_device_combobox->addItem("default"); //TODO translate this without breaking the default audio device
}
#ifdef BASSAUDIO
BASS_DEVICEINFO info;
for (a = 0; BASS_GetDeviceInfo(a, &info); a++) {
ui_audio_device_combobox->addItem(info.name);
if (p_ao_app->get_audio_output_device() == info.name)
ui_audio_device_combobox->setCurrentIndex(
ui_audio_device_combobox->count() - 1);
}
#elif defined QTAUDIO
foreach (const QAudioDeviceInfo &deviceInfo,
QAudioDeviceInfo::availableDevices(QAudio::AudioOutput)) {
ui_audio_device_combobox->addItem(deviceInfo.deviceName());
if (p_ao_app->get_audio_output_device() == deviceInfo.deviceName())
ui_audio_device_combobox->setCurrentIndex(
ui_audio_device_combobox->count() - 1);
}
#endif
ui_audio_layout->setWidget(row, QFormLayout::FieldRole,
ui_audio_device_combobox);

Expand Down Expand Up @@ -770,9 +760,7 @@ void AOOptionsDialog::save_pressed()
configini->setValue("casing_can_host_cases",
ui_casing_cm_cases_textbox->text());

#ifdef BASSAUDIO
ao_app->initBASS();
#endif
callwordsini->close();
done(0);
}
Expand Down
Loading