Made audio output example easier to understand. No real code changes
Maybe it's just me, but every time I try to read the "toggleMode" method in the audio output example, I get confused on whether I'm switching to/ from push/pull mode, and even what pushing and pulling entails. The name of the push timer also seemed backwards (which added to the confusion). Change-Id: I5ff7d18f72490c22b91a948ad7513b402a01c5e4 Reviewed-by: Yoann Lopes <yoann.lopes@theqtcompany.com>
This commit is contained in:
@@ -159,7 +159,7 @@ qint64 Generator::bytesAvailable() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
AudioTest::AudioTest()
|
AudioTest::AudioTest()
|
||||||
: m_pullTimer(new QTimer(this))
|
: m_pushTimer(new QTimer(this))
|
||||||
, m_modeButton(0)
|
, m_modeButton(0)
|
||||||
, m_suspendResumeButton(0)
|
, m_suspendResumeButton(0)
|
||||||
, m_deviceBox(0)
|
, m_deviceBox(0)
|
||||||
@@ -220,7 +220,7 @@ void AudioTest::initializeWindow()
|
|||||||
|
|
||||||
void AudioTest::initializeAudio()
|
void AudioTest::initializeAudio()
|
||||||
{
|
{
|
||||||
connect(m_pullTimer, SIGNAL(timeout()), SLOT(pullTimerExpired()));
|
connect(m_pushTimer, SIGNAL(timeout()), SLOT(pushTimerExpired()));
|
||||||
|
|
||||||
m_pullMode = true;
|
m_pullMode = true;
|
||||||
|
|
||||||
@@ -259,7 +259,7 @@ AudioTest::~AudioTest()
|
|||||||
|
|
||||||
void AudioTest::deviceChanged(int index)
|
void AudioTest::deviceChanged(int index)
|
||||||
{
|
{
|
||||||
m_pullTimer->stop();
|
m_pushTimer->stop();
|
||||||
m_generator->stop();
|
m_generator->stop();
|
||||||
m_audioOutput->stop();
|
m_audioOutput->stop();
|
||||||
m_audioOutput->disconnect(this);
|
m_audioOutput->disconnect(this);
|
||||||
@@ -273,7 +273,7 @@ void AudioTest::volumeChanged(int value)
|
|||||||
m_audioOutput->setVolume(qreal(value/100.0f));
|
m_audioOutput->setVolume(qreal(value/100.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioTest::pullTimerExpired()
|
void AudioTest::pushTimerExpired()
|
||||||
{
|
{
|
||||||
if (m_audioOutput && m_audioOutput->state() != QAudio::StoppedState) {
|
if (m_audioOutput && m_audioOutput->state() != QAudio::StoppedState) {
|
||||||
int chunks = m_audioOutput->bytesFree()/m_audioOutput->periodSize();
|
int chunks = m_audioOutput->bytesFree()/m_audioOutput->periodSize();
|
||||||
@@ -290,15 +290,17 @@ void AudioTest::pullTimerExpired()
|
|||||||
|
|
||||||
void AudioTest::toggleMode()
|
void AudioTest::toggleMode()
|
||||||
{
|
{
|
||||||
m_pullTimer->stop();
|
m_pushTimer->stop();
|
||||||
m_audioOutput->stop();
|
m_audioOutput->stop();
|
||||||
|
|
||||||
if (m_pullMode) {
|
if (m_pullMode) {
|
||||||
|
//switch to push mode (periodically push to QAudioOutput using a timer)
|
||||||
m_modeButton->setText(tr(PULL_MODE_LABEL));
|
m_modeButton->setText(tr(PULL_MODE_LABEL));
|
||||||
m_output = m_audioOutput->start();
|
m_output = m_audioOutput->start();
|
||||||
m_pullMode = false;
|
m_pullMode = false;
|
||||||
m_pullTimer->start(20);
|
m_pushTimer->start(20);
|
||||||
} else {
|
} else {
|
||||||
|
//switch to pull mode (QAudioOutput pulls from Generator as needed)
|
||||||
m_modeButton->setText(tr(PUSH_MODE_LABEL));
|
m_modeButton->setText(tr(PUSH_MODE_LABEL));
|
||||||
m_pullMode = true;
|
m_pullMode = true;
|
||||||
m_audioOutput->start(m_generator);
|
m_audioOutput->start(m_generator);
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ private:
|
|||||||
void createAudioOutput();
|
void createAudioOutput();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTimer *m_pullTimer;
|
QTimer *m_pushTimer;
|
||||||
|
|
||||||
// Owned by layout
|
// Owned by layout
|
||||||
QPushButton *m_modeButton;
|
QPushButton *m_modeButton;
|
||||||
@@ -110,7 +110,7 @@ private:
|
|||||||
QByteArray m_buffer;
|
QByteArray m_buffer;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void pullTimerExpired();
|
void pushTimerExpired();
|
||||||
void toggleMode();
|
void toggleMode();
|
||||||
void toggleSuspendResume();
|
void toggleSuspendResume();
|
||||||
void deviceChanged(int index);
|
void deviceChanged(int index);
|
||||||
|
|||||||
Reference in New Issue
Block a user