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>
This commit is contained in:
@@ -88,6 +88,8 @@ AudioCaptureSession::AudioCaptureSession(QObject *parent)
|
|||||||
, m_audioInput(0)
|
, m_audioInput(0)
|
||||||
, m_deviceInfo(QAudioDeviceInfo::defaultInputDevice())
|
, m_deviceInfo(QAudioDeviceInfo::defaultInputDevice())
|
||||||
, m_wavFile(true)
|
, m_wavFile(true)
|
||||||
|
, m_volume(1.0)
|
||||||
|
, m_muted(false)
|
||||||
{
|
{
|
||||||
m_format = m_deviceInfo.preferredFormat();
|
m_format = m_deviceInfo.preferredFormat();
|
||||||
}
|
}
|
||||||
@@ -312,6 +314,8 @@ void AudioCaptureSession::record()
|
|||||||
file.write((char*)&header,sizeof(CombinedHeader));
|
file.write((char*)&header,sizeof(CombinedHeader));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setVolumeHelper(m_muted ? 0 : m_volume);
|
||||||
|
|
||||||
file.startProbes(m_format);
|
file.startProbes(m_format);
|
||||||
m_audioInput->start(qobject_cast<QIODevice*>(&file));
|
m_audioInput->start(qobject_cast<QIODevice*>(&file));
|
||||||
} else {
|
} else {
|
||||||
@@ -400,4 +404,51 @@ void AudioCaptureSession::setCaptureDevice(const QString &deviceName)
|
|||||||
m_deviceInfo = QAudioDeviceInfo::defaultInputDevice();
|
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
|
QT_END_NAMESPACE
|
||||||
|
|||||||
@@ -96,11 +96,19 @@ public:
|
|||||||
|
|
||||||
void setCaptureDevice(const QString &deviceName);
|
void setCaptureDevice(const QString &deviceName);
|
||||||
|
|
||||||
|
void setVolume(qreal v);
|
||||||
|
qreal volume() const;
|
||||||
|
|
||||||
|
void setMuted(bool muted);
|
||||||
|
bool isMuted() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void stateChanged(QMediaRecorder::State state);
|
void stateChanged(QMediaRecorder::State state);
|
||||||
void statusChanged(QMediaRecorder::Status status);
|
void statusChanged(QMediaRecorder::Status status);
|
||||||
void positionChanged(qint64 position);
|
void positionChanged(qint64 position);
|
||||||
void actualLocationChanged(const QUrl &location);
|
void actualLocationChanged(const QUrl &location);
|
||||||
|
void volumeChanged(qreal volume);
|
||||||
|
void mutedChanged(bool muted);
|
||||||
void error(int error, const QString &errorString);
|
void error(int error, const QString &errorString);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
@@ -114,6 +122,8 @@ private:
|
|||||||
|
|
||||||
void setStatus(QMediaRecorder::Status status);
|
void setStatus(QMediaRecorder::Status status);
|
||||||
|
|
||||||
|
void setVolumeHelper(qreal volume);
|
||||||
|
|
||||||
QDir defaultDir() const;
|
QDir defaultDir() const;
|
||||||
QString generateFileName(const QString &requestedName,
|
QString generateFileName(const QString &requestedName,
|
||||||
const QString &extension) const;
|
const QString &extension) const;
|
||||||
@@ -129,6 +139,8 @@ private:
|
|||||||
QAudioDeviceInfo m_deviceInfo;
|
QAudioDeviceInfo m_deviceInfo;
|
||||||
QAudioFormat m_format;
|
QAudioFormat m_format;
|
||||||
bool m_wavFile;
|
bool m_wavFile;
|
||||||
|
qreal m_volume;
|
||||||
|
bool m_muted;
|
||||||
|
|
||||||
// WAV header stuff
|
// WAV header stuff
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,10 @@ AudioMediaRecorderControl::AudioMediaRecorderControl(QObject *parent)
|
|||||||
this, SIGNAL(statusChanged(QMediaRecorder::Status)));
|
this, SIGNAL(statusChanged(QMediaRecorder::Status)));
|
||||||
connect(m_session, SIGNAL(actualLocationChanged(QUrl)),
|
connect(m_session, SIGNAL(actualLocationChanged(QUrl)),
|
||||||
this, 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)),
|
connect(m_session, SIGNAL(error(int,QString)),
|
||||||
this, SIGNAL(error(int,QString)));
|
this, SIGNAL(error(int,QString)));
|
||||||
}
|
}
|
||||||
@@ -85,13 +89,12 @@ qint64 AudioMediaRecorderControl::duration() const
|
|||||||
|
|
||||||
bool AudioMediaRecorderControl::isMuted() const
|
bool AudioMediaRecorderControl::isMuted() const
|
||||||
{
|
{
|
||||||
return false;
|
return m_session->isMuted();
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal AudioMediaRecorderControl::volume() const
|
qreal AudioMediaRecorderControl::volume() const
|
||||||
{
|
{
|
||||||
//TODO: implement muting and audio gain
|
return m_session->volume();
|
||||||
return 1.0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioMediaRecorderControl::setState(QMediaRecorder::State state)
|
void AudioMediaRecorderControl::setState(QMediaRecorder::State state)
|
||||||
@@ -101,14 +104,12 @@ void AudioMediaRecorderControl::setState(QMediaRecorder::State state)
|
|||||||
|
|
||||||
void AudioMediaRecorderControl::setMuted(bool muted)
|
void AudioMediaRecorderControl::setMuted(bool muted)
|
||||||
{
|
{
|
||||||
if (muted)
|
m_session->setMuted(muted);
|
||||||
qWarning("Muting the audio recording is not supported.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioMediaRecorderControl::setVolume(qreal volume)
|
void AudioMediaRecorderControl::setVolume(qreal volume)
|
||||||
{
|
{
|
||||||
if (!qFuzzyCompare(volume, qreal(1.0)))
|
m_session->setVolume(volume);
|
||||||
qWarning("Changing the audio recording volume is not supported.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|||||||
Reference in New Issue
Block a user