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();
}
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
**
** 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 <QtCore/QVariant>
#include <QtGui/QIcon>
@ -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

View File

@ -16,6 +16,7 @@
#include <unistd.h>
#include <iostream>
#include <signal.h>
#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"<<endl;
for (u32 i=0; i<NUM_WORKERS; ++i) {
m_workers.push_back(new worker(i,&m_window));
// ????
#ifndef WIN32
usleep(1);
#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) {
m_block_size=block_size;
@ -93,7 +115,6 @@ void block_stream::process(const sample &left, const sample &right) {
m_block_position=0;
if (m_blocks.size()>MAX_BLOCKS) {
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_id<<" started..."<<endl;
while (true) {
pthread_mutex_lock(m_worker_mutex);
if (m_status==ACTIVATE) {
@ -142,6 +167,7 @@ void block_stream::worker::run() {
m_status=FINISHED;
cerr<<"ending "<<m_id<<endl;
}
pthread_mutex_unlock(m_worker_mutex);
#ifndef WIN32
usleep(5);
@ -149,11 +175,10 @@ void block_stream::worker::run() {
}
}
void block_stream::scatter_gather(u32 block_index, const sample &region) {
while(true) {
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) {
//cerr<<"adding finished block "<<w->m_block_index<<endl;
m_blocks[w->m_block_index]=*w->m_output;
@ -166,6 +191,7 @@ void block_stream::scatter_gather(u32 block_index, const sample &region) {
w->m_block_index = block_index;
return;
}
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 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 };

View File

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