@@ -23,11 +23,12 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, |
|
|
26 | axisX->setRange(0, 4000); | |
|
27 | 27 | QValueAxis *axisY = new QValueAxis; |
|
28 | 28 | axisY->setRange(0, 256); |
|
29 | 29 | m_chart->setAxisX(axisX, m_series); |
|
30 | 30 | m_chart->setAxisY(axisY, m_series); |
|
31 | m_chart->legend()->hide(); | |
|
31 | 32 | m_chart->setTitle("Data from microphone"); |
|
32 | 33 | |
|
33 | 34 | QVBoxLayout *mainLayout = new QVBoxLayout; |
@@ -48,7 +49,6 Widget::Widget(QWidget *parent) | |||
|
48 | 49 | m_device = new XYSeriesIODevice(m_series, this); |
|
49 | 50 | m_device->open(QIODevice::WriteOnly); |
|
50 | 51 | |
|
51 | m_audioInput->setBufferSize(10); | |
|
52 | 52 | m_audioInput->start(m_device); |
|
53 | 53 | } |
|
54 | 54 |
@@ -16,20 +16,20 qint64 XYSeriesIODevice::readData(char * data, qint64 maxSize) | |||
|
16 | 16 | |
|
17 | 17 | qint64 XYSeriesIODevice::writeData(const char * data, qint64 maxSize) |
|
18 | 18 | { |
|
19 |
qint64 range = |
|
|
19 | qint64 range = 4000; | |
|
20 | 20 | QList<QPointF> oldPoints = m_series->points(); |
|
21 | 21 | QList<QPointF> points; |
|
22 | 22 | |
|
23 | 23 | if (oldPoints.count() < range) { |
|
24 | 24 | points = m_series->points(); |
|
25 | 25 | } else { |
|
26 | for (int i = maxSize; i < oldPoints.count(); i++) | |
|
27 | points.append(QPointF(i - maxSize, oldPoints.at(i).y())); | |
|
26 | for (int i = maxSize/2; i < oldPoints.count(); i++) | |
|
27 | points.append(QPointF(i - maxSize/2, oldPoints.at(i).y())); | |
|
28 | 28 | } |
|
29 | 29 | |
|
30 | 30 | qint64 size = points.count(); |
|
31 | for (int k = 0; k < maxSize; k++) | |
|
32 | points.append(QPointF(k + size, (quint8)data[k])); | |
|
31 | for (int k = 0; k < maxSize/2; k++) | |
|
32 | points.append(QPointF(k + size, (quint8)data[2 * k])); | |
|
33 | 33 | |
|
34 | 34 | m_series->replace(points); |
|
35 | 35 | return maxSize; |
General Comments 0
You need to be logged in to leave comments.
Login now