diff options
| author | Osmium Sorcerer <os@sof.beauty> | 2026-03-24 02:56:23 +0000 |
|---|---|---|
| committer | Osmium Sorcerer <os@sof.beauty> | 2026-03-29 22:22:25 +0000 |
| commit | 3f6fb17deddd1b366d16db5a2531c82407ced9db (patch) | |
| tree | 5dd78ee66a67398274d08f598b79f8b663791c1f /src/courtroom.cpp | |
| parent | 8475cfb7ac19f8698d2b96a0367f4735a016c375 (diff) | |
Rewrite audio engine: replace BASS with miniaudio
SFX and blip players largely remain the same.
For the music player, we now have to implement network streaming
natively, we no longer have a convenient function that did everything
for us. I introduced QNetworkRequest to download the stream in memory
and signal when it's ready to be decoded and played back. The size is
guarded to prevent the client from accidentally downloading terabytes of
audio.
Delete QFutureWatcher, we no longer need it for concurrency. miniaudio
uses a separate audio thread. Network donwloads and communication with
the track name display are handled by Qt signals.
Also, delete an odd "music.txt" feature. Its purpose was specifying
offsets for loops in a text file per track, but it remained obscure and
unused in practice.
Unsupported:
- Large streams, including unbounded ones (radio). We'll need a ring
buffer for that, and a mechanism to write to it from the network and
feed it to the audio thread.
- Effect flags: fade in, fade out, sync pos. Ignored.
- Audio device selection.
Diffstat (limited to 'src/courtroom.cpp')
| -rw-r--r-- | src/courtroom.cpp | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 7646794..9d872a2 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -4,6 +4,7 @@ #include "moderation_functions.h" #include "options.h" +#include <QFileInfo> #include <QtConcurrent/QtConcurrent> // #define DEBUG_TRANSITION @@ -16,7 +17,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) setWindowFlags((this->windowFlags() | Qt::CustomizeWindowHint) & ~Qt::WindowMaximizeButtonHint); setObjectName("courtroom"); - ao_app->initBASS(); + ao_app->initAudio(); keepalive_timer = new QTimer(this); keepalive_timer->start(45000); @@ -33,7 +34,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) music_player = new AOMusicPlayer(ao_app); music_player->setMuted(true); - connect(&music_player->m_watcher, &QFutureWatcher<QString>::finished, this, &Courtroom::update_ui_music_name, Qt::QueuedConnection); + connect(music_player, &AOMusicPlayer::track_ready, this, [this](QString label) { ui_music_name->setText(label); }); sfx_player = new AOSfxPlayer(ao_app); sfx_player->setMuted(true); @@ -538,6 +539,8 @@ Courtroom::~Courtroom() delete sfx_player; delete objection_player; delete blip_player; + + ma_engine_uninit(&ao_app->audio_engine); } void Courtroom::on_application_state_changed(Qt::ApplicationState state) @@ -4720,8 +4723,7 @@ void Courtroom::handle_song(QStringList *p_contents) int effect_flags = 0; // No effects by default - vanilla functionality QString f_song = f_contents.at(0); - QString f_song_clear = QUrl(f_song).fileName(); - f_song_clear = f_song_clear.left(f_song_clear.lastIndexOf('.')); + QString f_song_clear = QFileInfo(f_song).completeBaseName(); int n_char = f_contents.at(1).toInt(&ok); if (!ok) @@ -4791,24 +4793,17 @@ void Courtroom::handle_song(QStringList *p_contents) { // Current song UI only displays the song playing, not other channels. // Any other music playing is irrelevant. - if (music_player->m_watcher.isRunning()) - { - music_player->m_watcher.cancel(); - } - ui_music_name->setText(tr("[LOADING] %1").arg(f_song_clear)); + ui_music_name->setText("[LOADING]"); } - music_player->m_watcher.setFuture(QtConcurrent::run([=, this]() -> QString { return music_player->playStream(f_song, channel, looping, effect_flags); })); -} - -void Courtroom::update_ui_music_name() -{ - QString result = music_player->m_watcher.result(); - if (result.isEmpty()) + if (f_song.startsWith("http")) { - return; + music_player->play_from_url(f_song, channel, looping, effect_flags); + } + else + { + music_player->play_from_file(f_song, channel, looping, effect_flags); } - ui_music_name->setText(result); } void Courtroom::handle_wtce(QString p_wtce, int variant) |
