summaryrefslogtreecommitdiffstats
path: root/src/plugins/audiocapture
diff options
context:
space:
mode:
authorYoann Lopes <yoann.lopes@theqtcompany.com>2015-11-16 16:04:28 +0100
committerYoann Lopes <yoann.lopes@theqtcompany.com>2015-11-23 11:48:37 +0000
commit9937c67decc5b81eaa25fff8d773cc7c2e6ff838 (patch)
tree70c2a8074cee87615e11bec74f689f9ced93daa5 /src/plugins/audiocapture
parent7221ed82d292fc20007b0d1a7953efd28fff3d22 (diff)
Implement volume in audiocapture plugin.
This plugin uses QAudioInput as audio source for the recording, just forward the volume to it. Change-Id: Ice3ec5e48195b13d5f738b79a357dfc261ad8955 Reviewed-by: Christian Stromme <christian.stromme@theqtcompany.com>
Diffstat (limited to 'src/plugins/audiocapture')
-rw-r--r--src/plugins/audiocapture/audiocapturesession.cpp51
-rw-r--r--src/plugins/audiocapture/audiocapturesession.h12
-rw-r--r--src/plugins/audiocapture/audiomediarecordercontrol.cpp15
3 files changed, 71 insertions, 7 deletions
diff --git a/src/plugins/audiocapture/audiocapturesession.cpp b/src/plugins/audiocapture/audiocapturesession.cpp
index 2b300964a..1b183db26 100644
--- a/src/plugins/audiocapture/audiocapturesession.cpp
+++ b/src/plugins/audiocapture/audiocapturesession.cpp
@@ -88,6 +88,8 @@ AudioCaptureSession::AudioCaptureSession(QObject *parent)
, m_audioInput(0)
, m_deviceInfo(QAudioDeviceInfo::defaultInputDevice())
, m_wavFile(true)
+ , m_volume(1.0)
+ , m_muted(false)
{
m_format = m_deviceInfo.preferredFormat();
}
@@ -312,6 +314,8 @@ void AudioCaptureSession::record()
file.write((char*)&header,sizeof(CombinedHeader));
}
+ setVolumeHelper(m_muted ? 0 : m_volume);
+
file.startProbes(m_format);
m_audioInput->start(qobject_cast<QIODevice*>(&file));
} else {
@@ -400,4 +404,51 @@ void AudioCaptureSession::setCaptureDevice(const QString &deviceName)
m_deviceInfo = QAudioDeviceInfo::defaultInputDevice();
}
+qreal AudioCaptureSession::volume() const
+{
+ return m_volume;
+}
+
+bool AudioCaptureSession::isMuted() const
+{
+ return m_muted;
+}
+
+void AudioCaptureSession::setVolume(qreal v)
+{
+ qreal boundedVolume = qBound(qreal(0), v, qreal(1));
+
+ if (m_volume == boundedVolume)
+ return;
+
+ m_volume = boundedVolume;
+
+ if (!m_muted)
+ setVolumeHelper(m_volume);
+
+ emit volumeChanged(m_volume);
+}
+
+void AudioCaptureSession::setMuted(bool muted)
+{
+ if (m_muted == muted)
+ return;
+
+ m_muted = muted;
+
+ setVolumeHelper(m_muted ? 0 : m_volume);
+
+ emit mutedChanged(m_muted);
+}
+
+void AudioCaptureSession::setVolumeHelper(qreal volume)
+{
+ if (!m_audioInput)
+ return;
+
+ m_audioInput->setVolume(volume);
+}
+
+
+
QT_END_NAMESPACE
diff --git a/src/plugins/audiocapture/audiocapturesession.h b/src/plugins/audiocapture/audiocapturesession.h
index 188312905..da30053ad 100644
--- a/src/plugins/audiocapture/audiocapturesession.h
+++ b/src/plugins/audiocapture/audiocapturesession.h
@@ -96,11 +96,19 @@ public:
void setCaptureDevice(const QString &deviceName);
+ void setVolume(qreal v);
+ qreal volume() const;
+
+ void setMuted(bool muted);
+ bool isMuted() const;
+
signals:
void stateChanged(QMediaRecorder::State state);
void statusChanged(QMediaRecorder::Status status);
void positionChanged(qint64 position);
void actualLocationChanged(const QUrl &location);
+ void volumeChanged(qreal volume);
+ void mutedChanged(bool muted);
void error(int error, const QString &errorString);
private slots:
@@ -114,6 +122,8 @@ private:
void setStatus(QMediaRecorder::Status status);
+ void setVolumeHelper(qreal volume);
+
QDir defaultDir() const;
QString generateFileName(const QString &requestedName,
const QString &extension) const;
@@ -129,6 +139,8 @@ private:
QAudioDeviceInfo m_deviceInfo;
QAudioFormat m_format;
bool m_wavFile;
+ qreal m_volume;
+ bool m_muted;
// WAV header stuff
diff --git a/src/plugins/audiocapture/audiomediarecordercontrol.cpp b/src/plugins/audiocapture/audiomediarecordercontrol.cpp
index 432ee3d08..d011d864e 100644
--- a/src/plugins/audiocapture/audiomediarecordercontrol.cpp
+++ b/src/plugins/audiocapture/audiomediarecordercontrol.cpp
@@ -50,6 +50,10 @@ AudioMediaRecorderControl::AudioMediaRecorderControl(QObject *parent)
this, SIGNAL(statusChanged(QMediaRecorder::Status)));
connect(m_session, SIGNAL(actualLocationChanged(QUrl)),
this, SIGNAL(actualLocationChanged(QUrl)));
+ connect(m_session, &AudioCaptureSession::volumeChanged,
+ this, &AudioMediaRecorderControl::volumeChanged);
+ connect(m_session, &AudioCaptureSession::mutedChanged,
+ this, &AudioMediaRecorderControl::mutedChanged);
connect(m_session, SIGNAL(error(int,QString)),
this, SIGNAL(error(int,QString)));
}
@@ -85,13 +89,12 @@ qint64 AudioMediaRecorderControl::duration() const
bool AudioMediaRecorderControl::isMuted() const
{
- return false;
+ return m_session->isMuted();
}
qreal AudioMediaRecorderControl::volume() const
{
- //TODO: implement muting and audio gain
- return 1.0;
+ return m_session->volume();
}
void AudioMediaRecorderControl::setState(QMediaRecorder::State state)
@@ -101,14 +104,12 @@ void AudioMediaRecorderControl::setState(QMediaRecorder::State state)
void AudioMediaRecorderControl::setMuted(bool muted)
{
- if (muted)
- qWarning("Muting the audio recording is not supported.");
+ m_session->setMuted(muted);
}
void AudioMediaRecorderControl::setVolume(qreal volume)
{
- if (!qFuzzyCompare(volume, qreal(1.0)))
- qWarning("Changing the audio recording volume is not supported.");
+ m_session->setVolume(volume);
}
QT_END_NAMESPACE