##// END OF EJS Templates
Added axes titles to audio example and decreased the number of samples on chart to 2000
Marek Rosa -
r2214:0a3cbf6ad29b
parent child
Show More
@@ -23,13 +23,16 Widget::Widget(QWidget *parent)
23 23 m_series = new QLineSeries;
24 24 m_chart->addSeries(m_series);
25 25 QValueAxis *axisX = new QValueAxis;
26 axisX->setRange(0, 4000);
26 axisX->setRange(0, 2000);
27 axisX->setLabelFormat("%g");
28 axisX->setTitle("Samples");
27 29 QValueAxis *axisY = new QValueAxis;
28 axisY->setRange(0, 256);
30 axisY->setRange(-1, 1);
31 axisY->setTitle("Audio level");
29 32 m_chart->setAxisX(axisX, m_series);
30 33 m_chart->setAxisY(axisY, m_series);
31 34 m_chart->legend()->hide();
32 m_chart->setTitle("Data from microphone");
35 m_chart->setTitle("Data from the microphone");
33 36
34 37 QVBoxLayout *mainLayout = new QVBoxLayout;
35 38 mainLayout->addWidget(chartView);
@@ -16,20 +16,21 qint64 XYSeriesIODevice::readData(char * data, qint64 maxSize)
16 16
17 17 qint64 XYSeriesIODevice::writeData(const char * data, qint64 maxSize)
18 18 {
19 qint64 range = 4000;
19 qint64 range = 2000;
20 20 QList<QPointF> oldPoints = m_series->points();
21 21 QList<QPointF> points;
22 int resolution = 4;
22 23
23 24 if (oldPoints.count() < range) {
24 25 points = m_series->points();
25 26 } else {
26 for (int i = maxSize/2; i < oldPoints.count(); i++)
27 points.append(QPointF(i - maxSize/2, oldPoints.at(i).y()));
27 for (int i = maxSize/resolution; i < oldPoints.count(); i++)
28 points.append(QPointF(i - maxSize/resolution, oldPoints.at(i).y()));
28 29 }
29 30
30 31 qint64 size = points.count();
31 for (int k = 0; k < maxSize/2; k++)
32 points.append(QPointF(k + size, (quint8)data[2 * k]));
32 for (int k = 0; k < maxSize/resolution; k++)
33 points.append(QPointF(k + size, ((quint8)data[resolution * k] - 128)/128.0));
33 34
34 35 m_series->replace(points);
35 36 return maxSize;
General Comments 0
You need to be logged in to leave comments. Login now