QwtSpectogram "realtime" plotting
Hello,
first of all thanks for this great forum!
I'm developing a program to modify audio data in "realtime".
Actual I can plot different audio signals with curves, but for
the next step I need a spectogram.
I connected the data with QwtMatrixRasterData to QwtSpectogram.
For Y-Axis I have 256 values, with the related Z-Axis value.
Quantity of values for X-Axis depends on the TimerInterval.
For now i use 500 values for 5 seconds (TimerInterval = 10ms).
The QwtSpectrogram is a child of a QwtPlot which is a child of QSplitter.
My actual problem is that QwtSpectrogram is only replotted if I shift the splitter.
So I don't know why the "replot()" in the "timerEvent()" didn't work.
I hope you can help me :)
Thank you in advance!
Christian Wagner
Code:
SignalSpecDomainPlot::SignalSpecDomainPlot(tPlotData *pPlotData,
, d_interval(0)
, d_timerId(-1)
, d_timerCount(0)
, mpPlotData(pPlotData)
{
d_spectrogram->setRenderThreadCount(0);
data = new QwtMatrixRasterData();
data->setInterval(Qt::ZAxis, QwtInterval(-80, 20));
data->setInterval(Qt::YAxis, QwtInterval(0, 256));
data->setInterval(Qt::XAxis, QwtInterval(0, 500));
data->setResampleMode(static_cast<QwtMatrixRasterData::ResampleMode>(1));
d_spectrogram->setData(data);
d_spectrogram->attach(this);
/*-------------------------------------------------------------------------------*
* Set axis
*-------------------------------------------------------------------------------*/
XAxisLabel.setText("Time [s]");
setAxisTitle
(QwtPlot::xBottom, XAxisLabel
);
setAxisScale
(QwtPlot::xBottom,
0,
5);
YAxisLabel.setText("Frequency[kHz]");
setAxisTitle
(QwtPlot::yLeft, YAxisLabel
);
setAxisScale
(QwtPlot::yLeft,
0,
8);
//color bar on the right axis
Y2AxisLabel.setText("Intensity[dB]");
setAxisTitle
(QwtPlot::yRight, Y2AxisLabel
);
setAxisScale
(QwtPlot::yRight,
-80,
20);
rightAxis->setColorBarEnabled(true);
enableAxis(yLeft + yRight);
setColorMap(SignalSpecDomainPlot::RGBMap);
/*-------------------------------------------------------------------------------*
* Set timer interval (in ms)
*-------------------------------------------------------------------------------*/
setTimerInterval(10.0);
}
void SignalSpecDomainPlot::setTimerInterval(double ms)
{
d_interval = qRound(ms);
if (d_timerId >= 0)
{
killTimer(d_timerId);
d_timerId = -1;
}
if (d_interval >= 0)
d_timerId = startTimer(d_interval);
}
{
if (d_timerCount == 0)
{
QVector<double> values;
for (uint i = 0; i <= 500 * 256; i++)
values += 0;
data->setInterval(Qt::XAxis, QwtInterval(0, 5));
data->setInterval(Qt::YAxis, QwtInterval(0, 8));
data->setValueMatrix(values, 500);
}
if(d_timerCount < 500)
{
d_timerCount++;
}
else
{
d_timerCount = 1;
}
for(uint j = 0; j < 256; j++)
{
data->setValue(j, d_timerCount-1, mpPlotData->pppdFreqMemory[0][0][j]);
}
if (d_timerCount % 100 == 0)
{
replot();
}
}
Re: QwtSpectogram "realtime" plotting
When modifying data without telling the spectrogram ( = using setData ) you have to invalidate the internal pixmap cache: see https://qwt.sourceforge.io/class_qwt...6cfbd509ef65b5
It is also possible to disable caching see: QwtPlotRasterItem::CachePolicy: see https://qwt.sourceforge.io/class_qwt...3b0f18289e4c7f
Note, that there are some relevant improvements in Qwt >= 6.2 ( f.e https://sourceforge.net/p/qwt/code/H...nches/qwt-6.2/ )
HTH,
Uwe