Stop audio output for SELCAL player during shutdown

This commit is contained in:
Klaus Basan
2020-03-19 23:15:05 +01:00
committed by Mat Sutcliffe
parent 6841297c6e
commit 651e6bdacf
2 changed files with 21 additions and 4 deletions

View File

@@ -77,6 +77,20 @@ namespace BlackSound
connect(m_audioOutput, &QAudioOutput::stateChanged, this, &CThreadedTonePairPlayer::handleStateChanged);
}
void CThreadedTonePairPlayer::beforeQuit() noexcept
{
QMutexLocker ml(&m_mutex);
CLogMessage(this).info(u"CThreadedTonePairPlayer quit for '%1'") << m_deviceInfo.getName();
if (m_audioOutput)
{
m_audioOutput->stop();
m_audioOutput->disconnect();
}
m_buffer.close();
}
void CThreadedTonePairPlayer::handleStateChanged(QAudio::State newState)
{
QMutexLocker ml(&m_mutex);
@@ -175,7 +189,7 @@ namespace BlackSound
bufferPointer -= last0AmplitudeSample;
while (last0AmplitudeSample)
{
double amplitude = 0.0; // amplitude -1 -> +1 , 0 is silence
const double amplitude = 0.0; // amplitude -1 -> +1 , 0 is silence
// generate this for all channels, usually 1 channel
for (int i = 0; i < this->m_audioFormat.channelCount(); ++i)
@@ -195,7 +209,7 @@ namespace BlackSound
Q_ASSERT(this->m_audioFormat.sampleType() == QAudioFormat::SignedInt);
Q_ASSERT(this->m_audioFormat.byteOrder() == QAudioFormat::LittleEndian);
qint16 value = static_cast<qint16>(amplitude * 32767);
const qint16 value = static_cast<qint16>(amplitude * 32767);
qToLittleEndian<qint16>(value, bufferPointer);
}
}

View File

@@ -53,6 +53,9 @@ namespace BlackSound
//! \copydoc BlackMisc::CContinuousWorker::initialize
virtual void initialize() override;
//! \copydoc BlackMisc::CContinuousWorker::beforeQuit
virtual void beforeQuit() noexcept override;
private:
void handleStateChanged(QAudio::State newState);
void playBuffer();
@@ -61,8 +64,8 @@ namespace BlackSound
//! Write audio amplitude to data buffer
//! This method assumes that
//! \li sampleSize == 16
//! \li byte order == little endian
//! \li sampleSize == 16
//! \li byte order == little endian
//! \li sample type == signed int
void writeAmplitudeToBuffer(double amplitude, unsigned char *bufferPointer);