Compare commits

...

6 Commits

Author SHA1 Message Date
Claude Heiland-Allen 2cb064696d Merge branch 'parallel-synapse-generation' into 'main'
parallelize synapse generation using OpenMP

See merge request then-try-this/samplebrain!6
2022-10-05 12:12:54 +00:00
dave griffiths 004d9970c8 Merge branch 'tooltip-fixup' into 'main'
fix some tooltips in the GUI

See merge request then-try-this/samplebrain!13
2022-10-05 11:32:45 +00:00
dave griffiths 0a309ef8cd Merge branch 'theme' into 'main'
set dark foreground when using light background

See merge request then-try-this/samplebrain!14
2022-10-05 11:31:29 +00:00
Claude Heiland-Allen 28a8bd31f8 set dark foreground when using light background
fixes hard-to-read light text on light background
when using a dark system theme enabled for QT apps
2022-10-05 11:06:18 +01:00
Claude Heiland-Allen ad2a70a8d6 fix some tooltips in the GUI
- some were incorrect, now corrected
- some spinboxes were missing, now added (same as slider)
- still not all widgets have tooltips (notably blocksize + overlap)
2022-10-04 12:44:52 +01:00
Claude Heiland-Allen 8aa0dee3d1 parallelize synapse generation using OpenMP
- only tested on Debian Linux with a 16-thread amd64 CPU
- Windows may need DLLs to be shipped with the EXE
- using `-fopenmp` should be made optional via qmake somehow
  (without the flag, parallelization pragmas are ignored
  and it reverts to serial operation)
- assumes `status::update()` among other code is thread-safe,
  it seems to work on my machine without issues...
2022-09-27 13:19:04 +01:00
4 changed files with 47 additions and 18 deletions

View File

@ -33,7 +33,7 @@ sound_items::sound_item &sound_items::add(QVBoxLayout *container, const string &
sound_item si;
si.m_filename = name;
si.m_id = m_current_sound_id++;
QString style("background-color:lightgrey;");
QString style("color:black;background-color:lightgrey;");
si.m_container = new QHBoxLayout();
si.m_container->setSpacing(10);
@ -89,8 +89,8 @@ void sound_items::clear() {
void sound_items::recolour() {
u32 c=0;
for (auto &si:m_sound_items) {
QString style("background-color:lightblue;");
if (c%2==0) style="background-color:pink;";
QString style("color:black;background-color:lightblue;");
if (c%2==0) style="color:black;background-color:pink;";
si.m_enable->setStyleSheet(style);
si.m_del->setStyleSheet(style);
si.m_label->setStyleSheet(style);
@ -101,7 +101,7 @@ void sound_items::recolour() {
void sound_items::change_colour(const std::string &name, const std::string &colour) {
for (auto &si:m_sound_items) {
if (si.m_filename==name) {
QString style("background-color:"+QString::fromStdString(colour)+";");
QString style("color:black;background-color:"+QString::fromStdString(colour)+";");
si.m_enable->setStyleSheet(style);
si.m_del->setStyleSheet(style);
si.m_label->setStyleSheet(style);

View File

@ -16,6 +16,7 @@
#include <iostream>
#include <algorithm>
#include <atomic>
#include <sndfile.h>
#include <float.h>
#include <spiralcore/audio.h>
@ -242,10 +243,12 @@ void brain::build_synapses_thresh(search_params &params, double thresh) {
m_average_error = calc_average_diff(params)*thresh;
double err = m_average_error*thresh;
u32 brain_size = m_blocks.size();
u32 outer_index = 0;
for (auto &i : m_blocks) {
std::atomic<u32> progress{0};
#pragma omp parallel for
for (u32 outer_index = 0; outer_index < brain_size; ++outer_index) {
auto &i = m_blocks[outer_index];
u32 index = 0;
status::update("building synapses %d%%",(int)(outer_index/(float)brain_size*100));
status::update("building synapses %d%%",(int)(progress/(float)brain_size*100));
for (auto &j : m_blocks) {
if (index!=outer_index) {
// collect connections that are under threshold in closeness
@ -256,30 +259,32 @@ void brain::build_synapses_thresh(search_params &params, double thresh) {
}
++index;
}
++outer_index;
++progress;
}
}
void brain::build_synapses_fixed(search_params &params) {
//m_average_error = calc_average_diff(params)*thresh;
u32 brain_size = m_blocks.size();
u32 outer_index = 0;
u32 num_synapses = NUM_FIXED_SYNAPSES;
if (num_synapses>=m_blocks.size()) num_synapses=m_blocks.size()-1;
// need to stop the progress updates flooding osc
u32 update_period = 100;
u32 update_tick = 0;
for (auto &i:m_blocks) {
std::atomic<u32> update_tick{0};
std::atomic<u32> progress{0};
#pragma omp parallel for
for (u32 outer_index = 0; outer_index < brain_size; ++outer_index) {
auto &i = m_blocks[outer_index];
if (update_tick>update_period) {
status::update("building synapses %d%%",(int)(outer_index/(float)brain_size*100));
status::update("building synapses %d%%",(int)(progress/(float)brain_size*100));
update_tick=0;
}
update_tick++;
u32 index = 0;
vector<pair<u32,double>> collect;
collect.reserve(brain_size);
// collect comparisons to all other blocks
for (auto &j:m_blocks) {
@ -304,7 +309,7 @@ void brain::build_synapses_fixed(search_params &params) {
i.get_synapse().push_back(collect[n].first);
}
++outer_index;
++progress;
}
status::update("Done: %d synapses grown for %d blocks",num_synapses*brain_size,brain_size);
}

View File

@ -96,6 +96,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>plain fft match vs mfcc values </string>
</property>
<property name="maximum">
<double>1.000000000000000</double>
</property>
@ -156,6 +159,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>match original or normalised blocks</string>
</property>
<property name="maximum">
<double>1.000000000000000</double>
</property>
@ -298,6 +304,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>use new blocks rather than similar ones</string>
</property>
<property name="maximum">
<double>1.000000000000000</double>
</property>
@ -361,6 +370,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>how long it takes for the novelty to wear off</string>
</property>
<property name="maximum">
<double>1.000000000000000</double>
</property>
@ -424,6 +436,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>likelihood of playing the next block rather than the closest</string>
</property>
<property name="maximum">
<double>1.000000000000000</double>
</property>
@ -491,7 +506,7 @@
</sizepolicy>
</property>
<property name="toolTip">
<string>how many connections to search (ordered in closeness)</string>
<string>repeat search (set novelty to 0 for dodgy jungle timessssstretch)</string>
</property>
<property name="minimum">
<number>1</number>
@ -666,7 +681,7 @@
</sizepolicy>
</property>
<property name="toolTip">
<string>how many connections to search (ordered in closeness)</string>
<string>block difference higher than this causes a new search, skipping the target</string>
</property>
<property name="maximum">
<number>10000</number>
@ -944,6 +959,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>amount to match the frequency</string>
</property>
<property name="maximum">
<double>1.000000000000000</double>
</property>
@ -1001,6 +1019,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>mix in the normalised blocks</string>
</property>
<property name="maximum">
<double>1.000000000000000</double>
</property>
@ -1061,6 +1082,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>mix in the original blocks</string>
</property>
<property name="maximum">
<double>1.000000000000000</double>
</property>

View File

@ -47,9 +47,9 @@ SOURCES += app/MainWindow.cpp \
INCLUDEPATH += brain/src
INCLUDEPATH += /usr/local/include
INCLUDEPATH += /opt/homebrew/include
LIBS += -L.. -L/usr/local/lib -L/opt/homebrew/lib -lportaudio -lfftw3 -lsndfile -llo -ldl -lpthread -lm
LIBS += -L.. -L/usr/local/lib -L/opt/homebrew/lib -lportaudio -lfftw3 -lsndfile -llo -ldl -lpthread -lm -fopenmp
QMAKE_CXXFLAGS += -O3 -Wall -Wno-unused -std=c++11
QMAKE_CXXFLAGS += -O3 -fopenmp -Wall -Wno-unused -std=c++11
# assets
RESOURCES = app/samplebrain.qrc