Commit 48622461 authored by Akhil K Gangadharan's avatar Akhil K Gangadharan

Add peakTouched signal for peak level animation

parent 876d46d8
......@@ -34,9 +34,12 @@ MediaCapture::MediaCapture(QObject *parent)
, m_audioDevice("default:")
, m_path(QUrl())
, m_recordState(0)
, m_hasPeaked(false)
{
m_probe = std::make_unique<QAudioProbe>(this);
connect(m_probe.get(), &QAudioProbe::audioBufferProbed, this, &MediaCapture::processBuffer);
connect(m_probe.get(), &QAudioProbe::audioBufferProbed, this, &MediaCapture::getPeakStatus);
m_resetTimer.setInterval(5000);
m_resetTimer.setSingleShot(true);
connect(&m_resetTimer, &QTimer::timeout, this, &MediaCapture::resetIfUnused);
......@@ -319,22 +322,46 @@ QVector<qreal> getBufferLevels(const QAudioBuffer &buffer)
return values;
}
bool MediaCapture::getPeakStatus()
{
for(int i=0; i<m_levels.size(); i++) {
if(m_levels[i]>0.8) {
m_hasPeaked = true;
emit peakTouched();
break;
}
else
m_hasPeaked = false;
}
return m_hasPeaked;
}
void MediaCapture::processBuffer(const QAudioBuffer &buffer)
{
m_levels = getBufferLevels(buffer);
m_hasPeaked = getPeakStatus();
emit levelsChanged();
}
QVector<qreal> MediaCapture::levels() const
{
return m_levels;
}
int MediaCapture::recordState() const
{
return m_recordState;
}
bool MediaCapture::touchLevel() const
{
return m_hasPeaked;
}
bool MediaCapture::isRecording() const
{
if (m_audioRecorder && m_audioRecorder->state() == QMediaRecorder::RecordingState) {
......
......@@ -43,6 +43,7 @@ class MediaCapture : public QObject
Q_OBJECT
Q_PROPERTY(QVector<qreal> levels READ levels NOTIFY levelsChanged)
Q_PROPERTY(int recordState READ recordState NOTIFY recordStateChanged)
Q_PROPERTY(bool touchLevel READ touchLevel NOTIFY peakTouched)
public:
MediaCapture(QObject *parent);
......@@ -66,6 +67,7 @@ public:
int currentState;
Q_INVOKABLE QVector<qreal> levels() const;
Q_INVOKABLE int recordState() const;
Q_INVOKABLE bool touchLevel() const;
public slots:
void displayErrorMessage();
......@@ -80,17 +82,20 @@ private:
QUrl m_path;
QVector<qreal> m_levels;
int m_recordState;
bool m_hasPeaked;
QTimer m_resetTimer;
QMutex m_recMutex;
private slots:
void processBuffer(const QAudioBuffer &buffer);
void resetIfUnused();
bool getPeakStatus();
signals:
void levelsChanged();
void recordStateChanged();
void recordDone();
void peakTouched();
};
#endif
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