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