Verified Commit a997276b authored by Jonah Brüchert's avatar Jonah Brüchert
Browse files

More work on visualization

parent af83043a
......@@ -6,10 +6,14 @@
AudioRecorder::AudioRecorder(QObject *parent) : QAudioRecorder(parent)
{
m_audioProbe = new QAudioProbe();
m_audioProbe = new QAudioProbe(parent);
connect(m_audioProbe, &QAudioProbe::audioBufferProbed, this, &AudioRecorder::process);
m_audioProbe->setSource(this);
for (int n = 0; n < 1000; ++n) {
m_volumesList.append(0);
}
}
void AudioRecorder::process(QAudioBuffer buffer) {
......@@ -18,13 +22,32 @@ void AudioRecorder::process(QAudioBuffer buffer) {
for(int i = 0; i < buffer.sampleCount(); i++) {
sum += abs(static_cast<short *>(buffer.data())[i]);
}
sum/=buffer.sampleCount();
sum /= buffer.sampleCount();
/*int previous = 0;
for(int i = 901; i < 1000; i++) {
previous += m_volumesList[i];
}
previous += sum;
previous /= 100;*/
m_volumesList.append(sum);
/*if (previous > 1000) {
m_volumesList.append(1000);
} else {
m_volumesList.append(previous);
}*/
if (sum > 1000) {
m_volumesList.append(1000);
} else {
m_volumesList.append(sum);
}
if (m_volumesList.count() > 300) {
m_volumesList.removeFirst();
}
volumesListChanged();
}
QList<int> AudioRecorder::volumesList() const
QVariantList AudioRecorder::volumesList() const
{
return m_volumesList;
return QVariantList(m_volumesList.begin(), m_volumesList.end());
}
......@@ -15,7 +15,7 @@ class AudioRecorder : public QAudioRecorder
Q_PROPERTY(int audioQuality READ audioQuality WRITE setAudioQuality NOTIFY audioQualityChanged)
Q_PROPERTY(QString containerFormat READ containerFormat WRITE setContainerFormat)
Q_PROPERTY(QList<int> volumesList READ volumesList NOTIFY volumesListChanged)
Q_PROPERTY(QVariantList volumesList READ volumesList NOTIFY volumesListChanged)
private:
QAudioEncoderSettings m_encoderSettings {};
......@@ -46,7 +46,7 @@ public:
emit audioQualityChanged();
}
QList<int> volumesList() const;
QVariantList volumesList() const;
void setVolumesList(const QList<int> &volumesList);
signals:
......
......@@ -2,16 +2,14 @@ import QtQuick 2.0
import QtQuick.Layouts 1.12
import org.kde.quickcharts 1.0 as Charts
import org.kde.quickcharts.controls 1.0 as ChartsControls
Item {
id: visualization
height: 500
property var volumes: []
onVolumesChanged: console.log(volumes)
ChartsControls.LineChartControl {
Charts.LineChart {
smooth: true
id: lineChart
anchors.fill: parent
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment