atrooney-online-2/src/aoblipplayer.cpp
Crystalwarrior ad578eb0bd
Suppress application volume when alt-tabbed (#730)
* Suppress application volume when alt-tabbed
Add a "suppress_audio" slider setting, 50% by default, which decides how much audio remains when the client is not in focus
Add a "muted" setting for blip, music, and sfx players
Add update_audio_volume func

* change "suppress" to "how much audio is suppressed" instead of "how much audio remains"

* Fix last commit just flipping the behavior and being ultra wacky

* Fix evidence present sound ignoring audio suppression settings

Co-authored-by: stonedDiscord <Tukz@gmx.de>
Co-authored-by: Salanto <62221668+Salanto@users.noreply.github.com>
2022-07-23 18:18:45 +03:00

61 lines
1.4 KiB
C++

#include "aoblipplayer.h"
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_sfx_suffix(ao_app->get_sounds_path(p_sfx));
for (int n_stream = 0; n_stream < 5; ++n_stream) {
BASS_StreamFree(m_stream_list[n_stream]);
if (f_path.endsWith(".opus"))
m_stream_list[n_stream] = BASS_OPUS_StreamCreateFile(
FALSE, f_path.utf16(), 0, 0, BASS_UNICODE | BASS_ASYNCFILE);
else
m_stream_list[n_stream] = BASS_StreamCreateFile(
FALSE, f_path.utf16(), 0, 0, BASS_UNICODE | BASS_ASYNCFILE);
}
set_volume_internal(m_volume);
}
void AOBlipPlayer::blip_tick()
{
int f_cycle = m_cycle++;
if (m_cycle == 5)
m_cycle = 0;
HSTREAM f_stream = m_stream_list[f_cycle];
BASS_ChannelSetDevice(f_stream, BASS_GetDevice());
BASS_ChannelPlay(f_stream, false);
}
void AOBlipPlayer::set_muted(bool toggle)
{
m_muted = toggle;
set_volume_internal(m_volume);
}
void AOBlipPlayer::set_volume(int p_value)
{
m_volume = static_cast<qreal>(p_value) / 100;
set_volume_internal(m_volume);
}
void AOBlipPlayer::set_volume_internal(qreal p_value)
{
// If muted, volume will always be 0
float volume = static_cast<float>(p_value) * !m_muted;
for (int n_stream = 0; n_stream < 5; ++n_stream) {
BASS_ChannelSetAttribute(m_stream_list[n_stream], BASS_ATTRIB_VOL, volume);
}
}