Skip to content
Snippets Groups Projects
Commit 58332046 authored by Leander Schulten's avatar Leander Schulten
Browse files

simplify code for example

parent 63d4fba5
No related merge requests found
Checking pipeline status
......@@ -12,8 +12,6 @@ AudioCaptureManager::AudioCaptureManager():audiofft(sample.size())
void AudioCaptureManager::initCallback(int channels){
this->channels = channels;
if(GUI::Colorplot::getLast())
GUI::Colorplot::getLast()->setBlockSize(512);
}
void AudioCaptureManager::dataCallback(float* data, unsigned int frames, bool*done){
......@@ -42,11 +40,6 @@ void AudioCaptureManager::dataCallback(float* data, unsigned int frames, bool*do
if(GUI::Graph::getLast())
GUI::Graph::getLast()->showData(fftoutput.data(),fftoutput.size());
if(GUI::Colorplot::getLast()){
GUI::Colorplot::getLast()->startBlock();
for (int i = 0; i < 512; ++i) {
GUI::Colorplot::getLast()->pushDataToBlock(fftoutput.at(i));
}
GUI::Colorplot::getLast()->endBlock();
}
if(GUI::Oscillogram::getLast())
GUI::Oscillogram::getLast()->showData(sample.data(),sample.size());
......
......@@ -5,7 +5,7 @@
namespace GUI{
Colorplot::Colorplot():haveNewData(false)
Colorplot::Colorplot()
{
setFlag(ItemHasContents);
lastCreated = this;
......
......@@ -11,16 +11,12 @@ namespace GUI{
class Colorplot : public QQuickItem
{
Q_OBJECT
unsigned int blockSize = 0;
std::list<volatile float*> dataBlocks;
std::list<float*> freeBlocks;
int currentBlockCounter = -1;
unsigned int blockSize = 512;
QColor lineColor = QColor(0,0,0);
Q_PROPERTY(QColor lineColor READ getLineColor WRITE setLineColor NOTIFY lineColorChanged)
static Colorplot * lastCreated;
std::atomic_bool haveNewData;
const static unsigned int MAX_BLOCKS_COUNT = 900;
std::mutex mutex;
public:
Colorplot();
......@@ -28,45 +24,8 @@ public:
if(lastCreated==this)
lastCreated = nullptr;
}
static Colorplot * getLast(){return lastCreated;}
void startBlock(){
mutex.lock();
if (dataBlocks.size()>=MAX_BLOCKS_COUNT) {
currentBlockCounter = 0;
auto data = dataBlocks.front();
dataBlocks.pop_front();
dataBlocks.push_back(data);
}else{
currentBlockCounter = 0;
auto data = new float[blockSize];
memset(data,0,blockSize*sizeof(float));
dataBlocks.push_back(data);
}
}
void endBlock(){
mutex.unlock();
}
void pushDataToBlock(float d){
if (currentBlockCounter>=0) {
dataBlocks.back()[currentBlockCounter] = d;//*0.4f;//std::pow(1+d*0.001,3)*20;
++currentBlockCounter;
if(currentBlockCounter>=static_cast<int>(blockSize))
currentBlockCounter=-1;
}else
qDebug()<<"Error : currentBlockCounter less then 0";
}
void setBlockSize(unsigned int size){
if(size!=this->blockSize){
for(const auto i : dataBlocks)
delete i;
for(const auto i : freeBlocks)
delete i;
dataBlocks.clear();
freeBlocks.clear();
currentBlockCounter = -1;
blockSize=size;
}
}
static Colorplot * getLast(){return nullptr;}
void setLineColor(QColor c){lineColor=c;update();lineColorChanged();}
QColor getLineColor(){return lineColor;}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment