Add a volume (gain) property to QAudioInput.

Only implemented for PulseAudio so far, but the API does explain that
it's optional.

Change-Id: I4543a1c81d810fe92bb08f1ed13f3a3534a371e4
Reviewed-by: Ling Hu <ling.hu@nokia.com>
This commit is contained in:
Michael Goddard
2012-01-25 13:50:37 +10:00
committed by Qt by Nokia
parent 8aef60c1cf
commit 3b00730eca
8 changed files with 181 additions and 0 deletions

View File

@@ -235,6 +235,12 @@ void InputTest::initializeWindow()
connect(m_deviceBox, SIGNAL(activated(int)), SLOT(deviceChanged(int)));
layout->addWidget(m_deviceBox);
m_volumeSlider = new QSlider(Qt::Horizontal, this);
m_volumeSlider->setRange(0, 100);
m_volumeSlider->setValue(100);
connect(m_volumeSlider, SIGNAL(valueChanged(int)), SLOT(sliderChanged(int)));
layout->addWidget(m_volumeSlider);
m_modeButton = new QPushButton(this);
m_modeButton->setText(PushModeLabel);
connect(m_modeButton, SIGNAL(clicked()), SLOT(toggleMode()));
@@ -281,6 +287,7 @@ void InputTest::createAudioInput()
m_audioInput = new QAudioInput(m_device, m_format, this);
connect(m_audioInput, SIGNAL(notify()), SLOT(notified()));
connect(m_audioInput, SIGNAL(stateChanged(QAudio::State)), SLOT(stateChanged(QAudio::State)));
m_volumeSlider->setValue(m_audioInput->volume() * 100);
m_audioInfo->start();
m_audioInput->start(m_audioInfo);
}
@@ -364,3 +371,9 @@ void InputTest::deviceChanged(int index)
m_device = m_deviceBox->itemData(index).value<QAudioDeviceInfo>();
createAudioInput();
}
void InputTest::sliderChanged(int value)
{
if (m_audioInput)
m_audioInput->setVolume(qreal(value) / 100);
}

View File

@@ -48,6 +48,7 @@
#include <QPushButton>
#include <QComboBox>
#include <QByteArray>
#include <QSlider>
#include <qaudioinput.h>
@@ -113,6 +114,7 @@ private slots:
void toggleSuspend();
void stateChanged(QAudio::State state);
void deviceChanged(int index);
void sliderChanged(int value);
private:
// Owned by layout
@@ -120,6 +122,7 @@ private:
QPushButton *m_modeButton;
QPushButton *m_suspendResumeButton;
QComboBox *m_deviceBox;
QSlider *m_volumeSlider;
QAudioDeviceInfo m_device;
AudioInfo *m_audioInfo;