diff --git a/src/blacksound/threadedtonepairplayer.cpp b/src/blacksound/threadedtonepairplayer.cpp index 18e94332e..8708267c9 100644 --- a/src/blacksound/threadedtonepairplayer.cpp +++ b/src/blacksound/threadedtonepairplayer.cpp @@ -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(amplitude * 32767); + const qint16 value = static_cast(amplitude * 32767); qToLittleEndian(value, bufferPointer); } } diff --git a/src/blacksound/threadedtonepairplayer.h b/src/blacksound/threadedtonepairplayer.h index 9b5123890..917ca3e6e 100644 --- a/src/blacksound/threadedtonepairplayer.h +++ b/src/blacksound/threadedtonepairplayer.h @@ -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);