atrooney-online-2/src/aoblipplayer.cpp
TrickyLeifa 1ef96383c8 Lightly reworked NetworkManager, ...
* Lightly reworked `NetworkManager`
* Added new modules to handle various connection types.
  * TCP
  * WebSocket
* Added general string splitter alias based on Qt version.
* Replaced `lobby_constructed` and `courtroom_constructed`
* Refactored and partially reimplemented the following classes:
  * `AOBlipPlayer`
  * `AOEmotePreview`
  * `AOMusicPlayer`
  * `AOSfxPlayer`
  * `AOTextArea`
2024-05-17 19:04:57 +02:00

55 lines
1.2 KiB
C++

#include "aoblipplayer.h"
AOBlipPlayer::AOBlipPlayer(AOApplication *ao_app)
: ao_app(ao_app)
{}
void AOBlipPlayer::setVolume(int value)
{
m_volume = value;
updateInternalVolume();
}
void AOBlipPlayer::setMuted(bool enabled)
{
m_muted = enabled;
updateInternalVolume();
}
void AOBlipPlayer::setBlip(QString blip)
{
QString path = ao_app->get_sfx_suffix(ao_app->get_sounds_path(blip));
for (int i = 0; i < STREAM_COUNT; ++i)
{
BASS_StreamFree(m_stream[i]);
if (path.endsWith(".opus"))
{
m_stream[i] = BASS_OPUS_StreamCreateFile(FALSE, path.utf16(), 0, 0, BASS_UNICODE | BASS_ASYNCFILE);
}
else
{
m_stream[i] = BASS_StreamCreateFile(FALSE, path.utf16(), 0, 0, BASS_UNICODE | BASS_ASYNCFILE);
}
}
updateInternalVolume();
}
void AOBlipPlayer::playBlip()
{
HSTREAM stream = m_stream[m_cycle];
BASS_ChannelSetDevice(stream, BASS_GetDevice());
BASS_ChannelPlay(stream, false);
m_cycle = ++m_cycle % STREAM_COUNT;
}
void AOBlipPlayer::updateInternalVolume()
{
float volume = m_muted ? 0.0f : (m_volume * 0.01);
for (int i = 0; i < STREAM_COUNT; ++i)
{
BASS_ChannelSetAttribute(m_stream[i], BASS_ATTRIB_VOL, volume);
}
}