removed mic input as the worker threads were causing high cpu and it's not reliable anyway fixes #12

This commit is contained in:
Dave Griffiths 2022-09-24 17:49:27 +01:00
parent 4e36c92923
commit b6dcb229d5
5 changed files with 67 additions and 27 deletions

View File

@ -168,7 +168,9 @@ void audio_thread::process(sample &left_in, sample &right_in, sample &left_out,
m_right_renderer->reset(); m_right_renderer->reset();
} }
if (name=="/mic") { 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();
} }
} }

View File

@ -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 ** Created by: Qt User Interface Compiler version 5.12.8
** **
** WARNING! All changes made in this file will be lost when recompiling UI file! ** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/ ********************************************************************************/
#ifndef SAMPLEBRAINROEYJX_H #ifndef SAMPLEBRAINMIZSPU_H
#define SAMPLEBRAINROEYJX_H #define SAMPLEBRAINMIZSPU_H
#include <QtCore/QVariant> #include <QtCore/QVariant>
#include <QtGui/QIcon> #include <QtGui/QIcon>
@ -603,9 +603,11 @@ public:
mic = new QCheckBox(controlTab); mic = new QCheckBox(controlTab);
mic->setObjectName(QString::fromUtf8("mic")); mic->setObjectName(QString::fromUtf8("mic"));
mic->setEnabled(false);
QFont font3; QFont font3;
font3.setFamily(QString::fromUtf8("Comic Sans MS")); font3.setFamily(QString::fromUtf8("Comic Sans MS"));
mic->setFont(font3); mic->setFont(font3);
mic->setCheckable(true);
verticalLayout_6->addWidget(mic); verticalLayout_6->addWidget(mic);
@ -1054,7 +1056,7 @@ public:
void retranslateUi(QMainWindow *MainWindow) 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_19->setText(QApplication::translate("MainWindow", "brain tweaks", nullptr));
label_6->setText(QApplication::translate("MainWindow", "fft / mfcc", nullptr)); label_6->setText(QApplication::translate("MainWindow", "fft / mfcc", nullptr));
#ifndef QT_NO_TOOLTIP #ifndef QT_NO_TOOLTIP
@ -1204,4 +1206,4 @@ namespace Ui {
QT_END_NAMESPACE QT_END_NAMESPACE
#endif // SAMPLEBRAINROEYJX_H #endif // SAMPLEBRAINMIZSPU_H

View File

@ -16,6 +16,7 @@
#include <unistd.h> #include <unistd.h>
#include <iostream> #include <iostream>
#include <signal.h>
#include "block_stream.h" #include "block_stream.h"
using namespace spiralcore; using namespace spiralcore;
@ -34,15 +35,36 @@ block_stream::block_stream() :
m_block_index_offset(0), m_block_index_offset(0),
m_sent_block_index(0) m_sent_block_index(0)
{ {
}
block_stream::~block_stream() {}
void block_stream::start() {
cerr<<"block stream starting up"<<endl;
for (u32 i=0; i<NUM_WORKERS; ++i) { for (u32 i=0; i<NUM_WORKERS; ++i) {
m_workers.push_back(new worker(i,&m_window)); m_workers.push_back(new worker(i,&m_window));
// ????
#ifndef WIN32 #ifndef WIN32
usleep(1); usleep(1);
#endif #endif
} }
} }
block_stream::~block_stream() {} void block_stream::stop() {
cerr<<"block stream ending"<<endl;
bool killcount = 0;
for (auto &w : m_workers) {
pthread_join(*w->m_thread,NULL);
}
usleep(500);
for (u32 i=0; i<NUM_WORKERS; ++i) {
delete m_workers[i];
}
m_workers.clear();
}
void block_stream::init(u32 block_size, u32 overlap, window::type t, bool ditchpcm) { void block_stream::init(u32 block_size, u32 overlap, window::type t, bool ditchpcm) {
m_block_size=block_size; m_block_size=block_size;
@ -82,7 +104,7 @@ void block_stream::process(const sample &left, const sample &right) {
// with the buffer wrapping... // with the buffer wrapping...
//cerr<<(s32)(m_buffer_position-m_block_size)<<" to "<<m_buffer_position<<endl; //cerr<<(s32)(m_buffer_position-m_block_size)<<" to "<<m_buffer_position<<endl;
m_buffer.get_region(region,(s32)(m_buffer_position-m_block_size), m_buffer.get_region(region,(s32)(m_buffer_position-m_block_size),
m_buffer_position); m_buffer_position);
//cerr<<"starting block "<<m_block_index<<endl; //cerr<<"starting block "<<m_block_index<<endl;
scatter_gather(m_block_index,region); scatter_gather(m_block_index,region);
@ -93,10 +115,9 @@ void block_stream::process(const sample &left, const sample &right) {
m_block_position=0; m_block_position=0;
if (m_blocks.size()>MAX_BLOCKS) { if (m_blocks.size()>MAX_BLOCKS) {
m_blocks.erase(m_blocks.begin()); m_blocks.erase(m_blocks.begin());
m_block_index_offset++; 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); 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() { void block_stream::worker::run() {
//cerr<<"worker "<<m_id<<" started..."<<endl;
while (true) { while (true) {
pthread_mutex_lock(m_worker_mutex); pthread_mutex_lock(m_worker_mutex);
if (m_status==ACTIVATE) { if (m_status==ACTIVATE) {
@ -142,6 +167,7 @@ void block_stream::worker::run() {
m_status=FINISHED; m_status=FINISHED;
cerr<<"ending "<<m_id<<endl; cerr<<"ending "<<m_id<<endl;
} }
pthread_mutex_unlock(m_worker_mutex); pthread_mutex_unlock(m_worker_mutex);
#ifndef WIN32 #ifndef WIN32
usleep(5); usleep(5);
@ -149,24 +175,24 @@ void block_stream::worker::run() {
} }
} }
void block_stream::scatter_gather(u32 block_index, const sample &region) { void block_stream::scatter_gather(u32 block_index, const sample &region) {
while(true) { while(true) {
for (auto &w : m_workers) { for (auto &w : m_workers) {
if (pthread_mutex_trylock(w->m_worker_mutex)) { if (pthread_mutex_trylock(w->m_worker_mutex)==0) {
if (w->m_status == worker::FINISHED) { if (w->m_status == worker::FINISHED) {
//cerr<<"adding finished block "<<w->m_block_index<<endl; //cerr<<"adding finished block "<<w->m_block_index<<endl;
m_blocks[w->m_block_index]=*w->m_output; m_blocks[w->m_block_index]=*w->m_output;
w->m_status = worker::READY; w->m_status = worker::READY;
} }
if (w->m_status == worker::READY) { if (w->m_status == worker::READY) {
w->m_region = region; w->m_region = region;
w->m_status = worker::ACTIVATE; w->m_status = worker::ACTIVATE;
w->m_block_index = block_index; w->m_block_index = block_index;
return; return;
} }
pthread_mutex_unlock(w->m_worker_mutex);
pthread_mutex_unlock(w->m_worker_mutex);
} }
} }
} }

View File

@ -41,11 +41,15 @@ class block_stream : public block_source {
virtual const block &get_block(u32 index) const; virtual const block &get_block(u32 index) const;
virtual u32 get_num_blocks() const { return UINT_MAX; } 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; } u32 last_block_index() const { return m_block_index_offset+m_blocks.size()-1; }
class worker { class worker {
public: public:
worker(u32 id, window *w); worker(u32 id, window *w);
~worker();
enum worker_status { READY=0, ACTIVATE, WORKING, FINISHED }; enum worker_status { READY=0, ACTIVATE, WORKING, FINISHED };

View File

@ -11,7 +11,7 @@
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>samplebrain 0.18</string> <string>samplebrain 0.18.1</string>
</property> </property>
<widget class="QWidget" name="centralwidget"> <widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout_4"> <layout class="QVBoxLayout" name="verticalLayout_4">
@ -867,6 +867,9 @@
</item> </item>
<item> <item>
<widget class="QCheckBox" name="mic"> <widget class="QCheckBox" name="mic">
<property name="enabled">
<bool>false</bool>
</property>
<property name="font"> <property name="font">
<font> <font>
<family>Comic Sans MS</family> <family>Comic Sans MS</family>
@ -875,6 +878,9 @@
<property name="text"> <property name="text">
<string>use mic input</string> <string>use mic input</string>
</property> </property>
<property name="checkable">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
<item> <item>