diff options
author | Gareth Stockwell <ext-gareth.stockwell@nokia.com> | 2010-10-26 14:15:14 (GMT) |
---|---|---|
committer | Gareth Stockwell <ext-gareth.stockwell@nokia.com> | 2010-10-29 12:46:33 (GMT) |
commit | a53df3596e2061c202845f9f1c183177ca8a7eda (patch) | |
tree | 3fa4d53240388348a1fdfae16791fee8aa222e16 /demos/spectrum/app/engine.cpp | |
parent | dd5ec222ce0285bd9419c9a47a8329bda41b5dd8 (diff) | |
download | Qt-a53df3596e2061c202845f9f1c183177ca8a7eda.zip Qt-a53df3596e2061c202845f9f1c183177ca8a7eda.tar.gz Qt-a53df3596e2061c202845f9f1c183177ca8a7eda.tar.bz2 |
Do not unnecessarily reset state of spectrum demo
This patch ensures that the state of the application is not reset when:
- Any of the 'Play generated tone', 'Play file' or settings
dialogs are opened
- Any of the 'Play generated tone', 'Play file' or settings
dialogs are dismissed by pressing the Cancel button
- A new input or output device is selected via the settings
dialog, and that new device supports the data format which
is currently being used within the application
- The window function is changed via the settings dialog
Note that the application is still reset if a new input or output
device is selected via the settings dialog, and this device does not
support the current data format.
Task-number: QTBUG-12935
Task-number: QTBUG-14810
Diffstat (limited to 'demos/spectrum/app/engine.cpp')
-rw-r--r-- | demos/spectrum/app/engine.cpp | 84 |
1 files changed, 46 insertions, 38 deletions
diff --git a/demos/spectrum/app/engine.cpp b/demos/spectrum/app/engine.cpp index 119a0e3..0495fe3 100644 --- a/demos/spectrum/app/engine.cpp +++ b/demos/spectrum/app/engine.cpp @@ -453,44 +453,50 @@ bool Engine::initialize() { bool result = false; - reset(); + QAudioFormat format = m_format; if (selectFormat()) { - const qint64 bufferLength = audioLength(m_format, BufferDurationUs); - m_buffer.resize(bufferLength); - m_buffer.fill(0); - emit bufferDurationChanged(BufferDurationUs); - - if (m_generateTone) { - if (0 == m_tone.endFreq) { - const qreal nyquist = nyquistFrequency(m_format); - m_tone.endFreq = qMin(qreal(SpectrumHighFreq), nyquist); - } + if (m_format != format) { + format = m_format; + reset(); + m_format = format; + + const qint64 bufferLength = audioLength(m_format, BufferDurationUs); + m_buffer.resize(bufferLength); + m_buffer.fill(0); + emit bufferDurationChanged(BufferDurationUs); + + if (m_generateTone) { + if (0 == m_tone.endFreq) { + const qreal nyquist = nyquistFrequency(m_format); + m_tone.endFreq = qMin(qreal(SpectrumHighFreq), nyquist); + } - // Call function defined in utils.h, at global scope - ::generateTone(m_tone, m_format, m_buffer); - m_dataLength = m_buffer.size(); - emit dataDurationChanged(bufferDuration()); - setRecordPosition(bufferDuration()); - result = true; - } else if (m_file) { - const qint64 length = m_wavFile.readData(*m_file, m_buffer, m_format); - if (length) { - m_dataLength = length; - emit dataDurationChanged(dataDuration()); - setRecordPosition(dataDuration()); + // Call function defined in utils.h, at global scope + ::generateTone(m_tone, m_format, m_buffer); + m_dataLength = m_buffer.size(); + emit dataDurationChanged(bufferDuration()); + setRecordPosition(bufferDuration()); + result = true; + } else if (m_file) { + const qint64 length = m_wavFile.readData(*m_file, m_buffer, m_format); + if (length) { + m_dataLength = length; + emit dataDurationChanged(dataDuration()); + setRecordPosition(dataDuration()); + result = true; + } + } else { + m_audioInput = new QAudioInput(m_audioInputDevice, m_format, this); + m_audioInput->setNotifyInterval(NotifyIntervalMs); result = true; } - } else { - m_audioInput = new QAudioInput(m_audioInputDevice, m_format, this); - m_audioInput->setNotifyInterval(NotifyIntervalMs); - result = true; - } - m_audioOutput = new QAudioOutput(m_audioOutputDevice, m_format, this); - m_audioOutput->setNotifyInterval(NotifyIntervalMs); - m_spectrumLengthBytes = SpectrumLengthSamples * - (m_format.sampleSize() / 8) * m_format.channels(); + m_audioOutput = new QAudioOutput(m_audioOutputDevice, m_format, this); + m_audioOutput->setNotifyInterval(NotifyIntervalMs); + m_spectrumLengthBytes = SpectrumLengthSamples * + (m_format.sampleSize() / 8) * m_format.channels(); + } } else { if (m_file) emit errorMessage(tr("Audio format not supported"), @@ -510,12 +516,14 @@ bool Engine::selectFormat() { bool foundSupportedFormat = false; - if (m_file) { - // Header is read from the WAV file; just need to check whether - // it is supported by the audio output device - QAudioFormat format = m_wavFile.format(); - if (m_audioOutputDevice.isFormatSupported(m_wavFile.format())) { - setFormat(m_wavFile.format()); + if (m_file || QAudioFormat() != m_format) { + QAudioFormat format = m_format; + if (m_file) + // Header is read from the WAV file; just need to check whether + // it is supported by the audio output device + format = m_wavFile.format(); + if (m_audioOutputDevice.isFormatSupported(format)) { + setFormat(format); foundSupportedFormat = true; } else { // Try flipping mono <-> stereo |