2015-07-31 21:33:31 -04:00
|
|
|
#include "ScopeVisualProcessor.h"
|
|
|
|
|
|
|
|
void ScopeVisualProcessor::process() {
|
2015-08-01 11:03:00 -04:00
|
|
|
if (!isOutputEmpty()) {
|
2015-07-31 21:33:31 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!input->empty()) {
|
|
|
|
AudioThreadInput *audioInputData;
|
|
|
|
input->pop(audioInputData);
|
|
|
|
|
|
|
|
if (!audioInputData) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int iMax = audioInputData->data.size();
|
|
|
|
if (!iMax) {
|
|
|
|
audioInputData->decRefCount();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-13 20:39:31 -04:00
|
|
|
audioInputData->busy_update.lock();
|
2015-07-31 21:33:31 -04:00
|
|
|
ScopeRenderData *renderData = outputBuffers.getBuffer();
|
|
|
|
renderData->channels = audioInputData->channels;
|
|
|
|
|
|
|
|
if (renderData->waveform_points.size() != iMax * 2) {
|
|
|
|
renderData->waveform_points.resize(iMax * 2);
|
|
|
|
}
|
2015-08-09 12:51:01 -04:00
|
|
|
|
|
|
|
float peak = 1.0f;
|
2015-07-31 21:33:31 -04:00
|
|
|
|
|
|
|
for (int i = 0; i < iMax; i++) {
|
2015-08-09 12:51:01 -04:00
|
|
|
float p = fabs(audioInputData->data[i]);
|
|
|
|
if (p > peak) {
|
|
|
|
peak = p;
|
|
|
|
}
|
2015-07-31 21:33:31 -04:00
|
|
|
}
|
|
|
|
|
2015-08-09 12:51:01 -04:00
|
|
|
if (audioInputData->channels == 2) {
|
|
|
|
for (int i = 0; i < iMax; i++) {
|
|
|
|
renderData->waveform_points[i * 2] = (((double) (i % (iMax/2)) / (double) iMax) * 2.0 - 0.5) * 2.0;
|
|
|
|
renderData->waveform_points[i * 2 + 1] = audioInputData->data[i] / peak;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < iMax; i++) {
|
|
|
|
renderData->waveform_points[i * 2] = (((double) i / (double) iMax) - 0.5) * 2.0;
|
|
|
|
renderData->waveform_points[i * 2 + 1] = audioInputData->data[i] / peak;
|
|
|
|
}
|
|
|
|
}
|
2015-08-13 20:39:31 -04:00
|
|
|
|
2015-07-31 21:33:31 -04:00
|
|
|
distribute(renderData);
|
2015-08-13 20:39:31 -04:00
|
|
|
audioInputData->busy_update.unlock();
|
2015-07-31 21:33:31 -04:00
|
|
|
}
|
|
|
|
}
|