Tone player "myself" guard

This commit is contained in:
Klaus Basan
2020-03-15 00:32:31 +01:00
committed by Mat Sutcliffe
parent 5b3c011a15
commit 5718f95819
2 changed files with 8 additions and 4 deletions

View File

@@ -28,12 +28,16 @@ namespace BlackSound
void CThreadedTonePairPlayer::play(int volume, const QList<CTonePair> &tonePairs)
{
QPointer<CThreadedTonePairPlayer> myself(this);
QMutexLocker ml(&m_mutex);
if (m_audioOutput->state() != QAudio::StoppedState) { return; }
m_bufferData = this->getAudioByTonePairs(tonePairs);
m_audioOutput->setVolume(static_cast<qreal>(0.01 * volume));
QTimer::singleShot(0, this, &CThreadedTonePairPlayer::playBuffer);
QTimer::singleShot(0, this, [ = ]
{
if (myself) { myself->playBuffer(); }
});
}
bool CThreadedTonePairPlayer::reinitializeAudio(const CAudioDeviceInfo &device)

View File

@@ -68,9 +68,9 @@ namespace BlackSound
BlackMisc::Audio::CAudioDeviceInfo m_deviceInfo;
QAudioOutput *m_audioOutput = nullptr;
QByteArray m_bufferData;
QBuffer m_buffer;
QAudioFormat m_audioFormat;
QByteArray m_bufferData;
QBuffer m_buffer;
QAudioFormat m_audioFormat;
QMap<CTonePair, QByteArray> m_tonePairCache;
mutable QMutex m_mutex { QMutex::Recursive };
};