diff --git a/demos/audio/widget.cpp b/demos/audio/widget.cpp index 8d5a6f6..bce89be 100644 --- a/demos/audio/widget.cpp +++ b/demos/audio/widget.cpp @@ -23,13 +23,16 @@ Widget::Widget(QWidget *parent) m_series = new QLineSeries; m_chart->addSeries(m_series); QValueAxis *axisX = new QValueAxis; - axisX->setRange(0, 4000); + axisX->setRange(0, 2000); + axisX->setLabelFormat("%g"); + axisX->setTitle("Samples"); QValueAxis *axisY = new QValueAxis; - axisY->setRange(0, 256); - m_chart->setAxisX(axisX, m_series); + axisY->setRange(-1, 1); + axisY->setTitle("Audio level"); + m_chart->setAxisX(axisX, m_series); m_chart->setAxisY(axisY, m_series); m_chart->legend()->hide(); - m_chart->setTitle("Data from microphone"); + m_chart->setTitle("Data from the microphone"); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(chartView); diff --git a/demos/audio/xyseriesiodevice.cpp b/demos/audio/xyseriesiodevice.cpp index a833d4a..4d06861 100644 --- a/demos/audio/xyseriesiodevice.cpp +++ b/demos/audio/xyseriesiodevice.cpp @@ -16,20 +16,21 @@ qint64 XYSeriesIODevice::readData(char * data, qint64 maxSize) qint64 XYSeriesIODevice::writeData(const char * data, qint64 maxSize) { - qint64 range = 4000; + qint64 range = 2000; QList oldPoints = m_series->points(); QList points; + int resolution = 4; if (oldPoints.count() < range) { points = m_series->points(); } else { - for (int i = maxSize/2; i < oldPoints.count(); i++) - points.append(QPointF(i - maxSize/2, oldPoints.at(i).y())); + for (int i = maxSize/resolution; i < oldPoints.count(); i++) + points.append(QPointF(i - maxSize/resolution, oldPoints.at(i).y())); } qint64 size = points.count(); - for (int k = 0; k < maxSize/2; k++) - points.append(QPointF(k + size, (quint8)data[2 * k])); + for (int k = 0; k < maxSize/resolution; k++) + points.append(QPointF(k + size, ((quint8)data[resolution * k] - 128)/128.0)); m_series->replace(points); return maxSize;