Skip to content

Commit

Permalink
various performance improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
KinoMyu committed Sep 14, 2018
1 parent f03b3cc commit c851048
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 30 deletions.
2 changes: 1 addition & 1 deletion FastHCADecoder
Submodule FastHCADecoder updated 7 files
+60 −50 HCADecodeService.cpp
+16 −12 HCADecodeService.h
+3 −0 README.md
+9 −9 Semaphore.h
+139 −125 Source.cpp
+150 −207 clHCA.cpp
+22 −23 clHCA.h
4 changes: 4 additions & 0 deletions QuintetPlayer.pro
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ INCLUDEPATH += $$PWD/.
DEPENDPATH += $$PWD/.

TRANSLATIONS = QuintetPlayer_ja.ts

win32-msvc* {
QMAKE_CXXFLAGS_RELEASE += /O2 /Ob2 /Zc:inline /Zc:forScope
}
18 changes: 9 additions & 9 deletions src/HCAStreamChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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();
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
45 changes: 26 additions & 19 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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('_'));
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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<int> 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&)
Expand Down Expand Up @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class MainWindow : public QMainWindow
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();

private:
Expand Down
1 change: 1 addition & 0 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <map>
#include <unordered_map>
#include <QComboBox>
#include "../bass/bass.h"

#define NUM_IDOLS 13
#define ALL 0x15
Expand Down

0 comments on commit c851048

Please sign in to comment.