const QString AudioTest::PullModeLabel(tr("Enable pull mode"));
const QString AudioTest::SuspendLabel(tr("Suspend playback"));
const QString AudioTest::ResumeLabel(tr("Resume playback"));
+const QString AudioTest::VolumeLabel(tr("Volume:"));
const int DurationSeconds = 1;
const int ToneFrequencyHz = 600;
connect(m_suspendResumeButton, SIGNAL(clicked()), SLOT(toggleSuspendResume()));
layout->addWidget(m_suspendResumeButton);
+ QHBoxLayout *volumeBox = new QHBoxLayout;
+ m_volumeLabel = new QLabel;
+ m_volumeLabel->setText(VolumeLabel);
+ m_volumeSlider = new QSlider(Qt::Horizontal);
+ m_volumeSlider->setMinimum(0);
+ m_volumeSlider->setMaximum(100);
+ m_volumeSlider->setSingleStep(10);
+ connect(m_volumeSlider, SIGNAL(valueChanged(int)), this, SLOT(volumeChanged(int)));
+ volumeBox->addWidget(m_volumeLabel);
+ volumeBox->addWidget(m_volumeSlider);
+ layout->addLayout(volumeBox);
+
window->setLayout(layout.data());
layout.take(); // ownership transferred
connect(m_audioOutput, SIGNAL(stateChanged(QAudio::State)), SLOT(stateChanged(QAudio::State)));
m_generator->start();
m_audioOutput->start(m_generator);
+ m_volumeSlider->setValue(int(m_audioOutput->volume()*100.0f));
}
AudioTest::~AudioTest()
createAudioOutput();
}
+void AudioTest::volumeChanged(int value)
+{
+ if (m_audioOutput)
+ m_audioOutput->setVolume(qreal(value/100.0f));
+}
+
void AudioTest::notified()
{
qWarning() << "bytesFree = " << m_audioOutput->bytesFree()
#include <QObject>
#include <QMainWindow>
+#include <QLabel>
+#include <QSlider>
#include <QIODevice>
#include <QTimer>
#include <QPushButton>
QPushButton* m_modeButton;
QPushButton* m_suspendResumeButton;
QComboBox* m_deviceBox;
+ QLabel* m_volumeLabel;
+ QSlider* m_volumeSlider;
QAudioDeviceInfo m_device;
Generator* m_generator;
static const QString PullModeLabel;
static const QString SuspendLabel;
static const QString ResumeLabel;
+ static const QString VolumeLabel;
private slots:
void notified();
void toggleSuspendResume();
void stateChanged(QAudio::State state);
void deviceChanged(int index);
+ void volumeChanged(int);
};
#endif