From b6dcb229d54804c5f0ffc36e33a1dfa9e57eae66 Mon Sep 17 00:00:00 2001 From: Dave Griffiths Date: Sat, 24 Sep 2022 17:49:27 +0100 Subject: [PATCH] removed mic input as the worker threads were causing high cpu and it's not reliable anyway fixes #12 --- app/audio_thread.cpp | 4 ++- app/generated/ui_samplebrain.h | 12 ++++--- brain/src/block_stream.cpp | 66 +++++++++++++++++++++++----------- brain/src/block_stream.h | 4 +++ gui/samplebrain.ui | 8 ++++- 5 files changed, 67 insertions(+), 27 deletions(-) diff --git a/app/audio_thread.cpp b/app/audio_thread.cpp index 0354faf..8e87fe3 100644 --- a/app/audio_thread.cpp +++ b/app/audio_thread.cpp @@ -168,7 +168,9 @@ void audio_thread::process(sample &left_in, sample &right_in, sample &left_out, m_right_renderer->reset(); } if (name=="/mic") { - m_mic_mode = cmd.get_int(0); + //m_mic_mode = cmd.get_int(0); + //if (m_mic_mode==1) m_block_stream->start(); + //else m_block_stream->stop(); } } diff --git a/app/generated/ui_samplebrain.h b/app/generated/ui_samplebrain.h index 0536846..0da3bfb 100644 --- a/app/generated/ui_samplebrain.h +++ b/app/generated/ui_samplebrain.h @@ -1,13 +1,13 @@ /******************************************************************************** -** Form generated from reading UI file 'samplebrainroEYjX.ui' +** Form generated from reading UI file 'samplebrainMIzspU.ui' ** ** Created by: Qt User Interface Compiler version 5.12.8 ** ** WARNING! All changes made in this file will be lost when recompiling UI file! ********************************************************************************/ -#ifndef SAMPLEBRAINROEYJX_H -#define SAMPLEBRAINROEYJX_H +#ifndef SAMPLEBRAINMIZSPU_H +#define SAMPLEBRAINMIZSPU_H #include #include @@ -603,9 +603,11 @@ public: mic = new QCheckBox(controlTab); mic->setObjectName(QString::fromUtf8("mic")); + mic->setEnabled(false); QFont font3; font3.setFamily(QString::fromUtf8("Comic Sans MS")); mic->setFont(font3); + mic->setCheckable(true); verticalLayout_6->addWidget(mic); @@ -1054,7 +1056,7 @@ public: void retranslateUi(QMainWindow *MainWindow) { - MainWindow->setWindowTitle(QApplication::translate("MainWindow", "samplebrain 0.18", nullptr)); + MainWindow->setWindowTitle(QApplication::translate("MainWindow", "samplebrain 0.18.1", nullptr)); label_19->setText(QApplication::translate("MainWindow", "brain tweaks", nullptr)); label_6->setText(QApplication::translate("MainWindow", "fft / mfcc", nullptr)); #ifndef QT_NO_TOOLTIP @@ -1204,4 +1206,4 @@ namespace Ui { QT_END_NAMESPACE -#endif // SAMPLEBRAINROEYJX_H +#endif // SAMPLEBRAINMIZSPU_H diff --git a/brain/src/block_stream.cpp b/brain/src/block_stream.cpp index ea56504..ec554b6 100644 --- a/brain/src/block_stream.cpp +++ b/brain/src/block_stream.cpp @@ -16,6 +16,7 @@ #include #include +#include #include "block_stream.h" using namespace spiralcore; @@ -34,15 +35,36 @@ block_stream::block_stream() : m_block_index_offset(0), m_sent_block_index(0) { +} + +block_stream::~block_stream() {} + +void block_stream::start() { + cerr<<"block stream starting up"<m_thread,NULL); + } + + usleep(500); + + for (u32 i=0; iMAX_BLOCKS) { - m_blocks.erase(m_blocks.begin()); - m_block_index_offset++; + m_blocks.erase(m_blocks.begin()); + m_block_index_offset++; } } @@ -131,8 +152,12 @@ block_stream::worker::worker(u32 id, window *w) : pthread_create(m_thread,NULL,(void*(*)(void*))_run_worker,this); } +block_stream::worker::~worker() { + delete m_worker_mutex; + delete m_thread; +} + void block_stream::worker::run() { - //cerr<<"worker "<m_worker_mutex)) { - if (w->m_status == worker::FINISHED) { - //cerr<<"adding finished block "<m_block_index<m_block_index]=*w->m_output; - w->m_status = worker::READY; - } + if (pthread_mutex_trylock(w->m_worker_mutex)==0) { + if (w->m_status == worker::FINISHED) { + //cerr<<"adding finished block "<m_block_index<m_block_index]=*w->m_output; + w->m_status = worker::READY; + } - if (w->m_status == worker::READY) { - w->m_region = region; - w->m_status = worker::ACTIVATE; - w->m_block_index = block_index; - return; - } - pthread_mutex_unlock(w->m_worker_mutex); + if (w->m_status == worker::READY) { + w->m_region = region; + w->m_status = worker::ACTIVATE; + w->m_block_index = block_index; + return; + } + + pthread_mutex_unlock(w->m_worker_mutex); } } } diff --git a/brain/src/block_stream.h b/brain/src/block_stream.h index bc26998..26477a1 100644 --- a/brain/src/block_stream.h +++ b/brain/src/block_stream.h @@ -41,11 +41,15 @@ class block_stream : public block_source { virtual const block &get_block(u32 index) const; virtual u32 get_num_blocks() const { return UINT_MAX; } + void start(); + void stop(); + u32 last_block_index() const { return m_block_index_offset+m_blocks.size()-1; } class worker { public: worker(u32 id, window *w); + ~worker(); enum worker_status { READY=0, ACTIVATE, WORKING, FINISHED }; diff --git a/gui/samplebrain.ui b/gui/samplebrain.ui index 9a1739d..aca0d2c 100644 --- a/gui/samplebrain.ui +++ b/gui/samplebrain.ui @@ -11,7 +11,7 @@ - samplebrain 0.18 + samplebrain 0.18.1 @@ -867,6 +867,9 @@ + + false + Comic Sans MS @@ -875,6 +878,9 @@ use mic input + + true +