From c851048ffcedbdcb8c6c0246f2954f20c4b45ed6 Mon Sep 17 00:00:00 2001 From: KinoMyu Date: Thu, 13 Sep 2018 21:38:00 -0700 Subject: [PATCH] various performance improvements --- FastHCADecoder | 2 +- QuintetPlayer.pro | 4 ++++ src/HCAStreamChannel.cpp | 18 ++++++++-------- src/mainwindow.cpp | 45 +++++++++++++++++++++++----------------- src/mainwindow.h | 2 +- src/utils.h | 1 + 6 files changed, 42 insertions(+), 30 deletions(-) diff --git a/FastHCADecoder b/FastHCADecoder index 61b41a4..f1c5fcf 160000 --- a/FastHCADecoder +++ b/FastHCADecoder @@ -1 +1 @@ -Subproject commit 61b41a4404ee7014eb2e664303e5b9ac5a9ed1f3 +Subproject commit f1c5fcf887a19bfba6b6b6bfba11633d50b5f9da diff --git a/QuintetPlayer.pro b/QuintetPlayer.pro index be4aab7..07d9eed 100644 --- a/QuintetPlayer.pro +++ b/QuintetPlayer.pro @@ -51,3 +51,7 @@ INCLUDEPATH += $$PWD/. DEPENDPATH += $$PWD/. TRANSLATIONS = QuintetPlayer_ja.ts + +win32-msvc* { + QMAKE_CXXFLAGS_RELEASE += /O2 /Ob2 /Zc:inline /Zc:forScope +} diff --git a/src/HCAStreamChannel.cpp b/src/HCAStreamChannel.cpp index e2fc64a..06bdb5f 100644 --- a/src/HCAStreamChannel.cpp +++ b/src/HCAStreamChannel.cpp @@ -3,14 +3,14 @@ HCAStreamChannel::HCAStreamChannel(HCADecodeService* dec, float volume, unsigned int cipher_key_1, unsigned int cipher_key_2) : dec {dec}, - flags {0}, - volume {volume}, - cipher_key_1 {cipher_key_1}, - cipher_key_2 {cipher_key_2}, ptr {nullptr}, size {0}, playback_channel {0}, - decode_channel {0} + decode_channel {0}, + flags {0}, + volume {volume}, + cipher_key_1 {cipher_key_1}, + cipher_key_2 {cipher_key_2} {} HCAStreamChannel::HCAStreamChannel(const HCAStreamChannel& other) @@ -27,7 +27,7 @@ HCAStreamChannel::HCAStreamChannel(const HCAStreamChannel& other) cipher_key_1 = other.cipher_key_1; cipher_key_2 = other.cipher_key_2; ptr = new char[size]; - for (size_t i = 0; i < size; ++i) ((char*)ptr)[i] = ((char*)other.ptr)[i]; + memcpy(ptr, other.ptr, size); __load(); } @@ -80,7 +80,7 @@ void HCAStreamChannel::unload() dec->cancel_decode(ptr); if (playback_channel != 0) { BASS_StreamFree(playback_channel); playback_channel = 0; } if (decode_channel != 0) { BASS_StreamFree(decode_channel); decode_channel = 0; } - if (ptr != nullptr) { delete[] ptr; ptr = nullptr; } + if (ptr != nullptr) { operator delete(ptr); ptr = nullptr; } size = 0; } @@ -114,7 +114,7 @@ bool HCAStreamChannel::__load() if (playback_channel == 0) { dec->cancel_decode(ptr); - delete[] ptr; + operator delete(ptr); ptr = nullptr; decode_channel = 0; size = 0; @@ -124,7 +124,7 @@ bool HCAStreamChannel::__load() if (decode_channel == 0) { dec->cancel_decode(ptr); - delete[] ptr; + operator delete(ptr); ptr = nullptr; BASS_StreamFree(playback_channel); playback_channel = 0; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 22ab30d..780070d 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -16,17 +16,17 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow {parent}, ui {new Ui::MainWindow}, - dec {2}, - is_usotsuki {false}, - old_unit_size {5}, unit_size {5}, + old_unit_size {5}, bgm_vol {0.6}, idol_vol {0.6}, + is_usotsuki {false}, play_stream {BASS_Mixer_StreamCreate(44100,2,0)}, mix_stream {BASS_Mixer_StreamCreate(44100,2,BASS_STREAM_DECODE)}, idol_mix_stream {BASS_Mixer_StreamCreate(44100,2,BASS_STREAM_DECODE)}, idol_oneshot_stream {BASS_Mixer_StreamCreate(44100,2,BASS_STREAM_DECODE)}, - freeverb_params {1, 0.4f, 0.76f, 0.3f, 1, 0, BASS_BFX_CHANALL} + freeverb_params {1, 0.4f, 0.76f, 0.3f, 1, 0, BASS_BFX_CHANALL}, + dec {2} { QString locale = QLocale::system().name(); locale.truncate(locale.lastIndexOf('_')); @@ -156,10 +156,14 @@ void MainWindow::updateUIPosition() ui->positionSlider->setValue((double)pos/len*ui->positionSlider->maximum()); ui->positionSlider->blockSignals(false); } - QWORD p = BASS_ChannelBytes2Seconds(bgm->get_decode_channel(),pos); - QWORD l = BASS_ChannelBytes2Seconds(bgm->get_decode_channel(),len); + double p = BASS_ChannelBytes2Seconds(bgm->get_decode_channel(),pos); + double l = BASS_ChannelBytes2Seconds(bgm->get_decode_channel(),len); + int pm = p / 60; + int lm = l / 60; + double ps = p - pm * 60; + double ls = l - lm * 60; QString result; - QTextStream(&result) << QString(language_string == "jp" ? "位置: " : "Position: ") << p/60 << QString(":%1").arg(p%60, 2, 10, QChar('0')) << "/" << l/60 << QString(":%1").arg(l%60, 2, 10, QChar('0')); + QTextStream(&result) << QString(language_string == "jp" ? "位置: " : "Position: ") << pm << QString(":%1").arg(ps, 5, 'f', 2, QChar('0')) << "/" << lm << QString(":%1").arg(ls, 5, 'f', 2, QChar('0')); ui->statusBar->showMessage(result); if( pos >= len ) { @@ -216,20 +220,23 @@ void MainWindow::setIdolVolume(int value) void MainWindow::randomizeUnit() { + unsigned int choices = idol_selection_box[0]->count() - 1; + unsigned int* list = new unsigned int[choices]; + unsigned int* it = list; + for(unsigned int i = 1; i <= choices; ++i) + { + *(it++) = i; + } if(idol_selection_box[0]->count() > 1) { - std::set seen_set; - int n; for(int i = 0; i < unit_size; ++i) { - do - { - n = rand() % (idol_selection_box[i]->count() - 1) + 1; - } while(seen_set.find(n) != seen_set.end()); - seen_set.insert(n); - idol_selection_box[i]->setCurrentIndex(n); + unsigned int n = (unsigned int)rand() % choices; + idol_selection_box[i]->setCurrentIndex(list[n]); + list[n] = list[--choices]; } } + delete[] list; } void MainWindow::setIdolName(const QString&) @@ -520,14 +527,14 @@ void MainWindow::applyOneshotCommand(QWORD pos, const std::string &command) } std::string filtered = filterCommand(command); - int numSinging = filtered.length(); - size_t n = std::count(filtered.begin(), filtered.end(), 'x'); - for(int i = 0; i < numSinging; ++i) + unsigned int numSinging = filtered.length(); + int n = std::count(filtered.begin(), filtered.end(), 'x'); + for(unsigned int i = 0; i < numSinging; ++i) { if(filtered[i] != 'x') { QWORD len = BASS_ChannelGetLength(idols_oneshot[filtered[i] - 48]->get_decode_channel(), BASS_POS_BYTE); - if(mappos >= 0 && mappos < len) + if(mappos < len) { BASS_ChannelSetAttribute(idols_oneshot[filtered[i] - 48]->get_decode_channel(), BASS_ATTRIB_VOL, idol_vol * volTable[numSinging - 1 - n] / (is_usotsuki ? 0.75 : 0.95)); BASS_ChannelSetAttribute(idols_oneshot[filtered[i] - 48]->get_decode_channel(), BASS_ATTRIB_PAN, panTable[numSinging - 1][i]); diff --git a/src/mainwindow.h b/src/mainwindow.h index ebf8e4b..472fcf7 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -23,7 +23,7 @@ class MainWindow : public QMainWindow Q_OBJECT public: - explicit MainWindow(QWidget *parent = 0); + explicit MainWindow(QWidget *parent = nullptr); ~MainWindow(); private: diff --git a/src/utils.h b/src/utils.h index 758cb42..9753f4e 100644 --- a/src/utils.h +++ b/src/utils.h @@ -2,6 +2,7 @@ #include #include #include +#include "../bass/bass.h" #define NUM_IDOLS 13 #define ALL 0x15