From 7d51bedc3e574a6e1d02c24501c7b71efdb3209f Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 23 Apr 2020 20:19:59 +0200 Subject: [PATCH] [AFV] misc style issues: * object name * simple style fixes * some renamings * comments --- .../afv/audio/callsignsampleprovider.cpp | 62 ++++++++++--------- .../afv/audio/callsignsampleprovider.h | 22 +++---- src/blackcore/afv/audio/output.cpp | 15 ++--- .../afv/audio/receiversampleprovider.cpp | 31 +++++----- .../afv/audio/receiversampleprovider.h | 2 +- .../afv/audio/soundcardsampleprovider.cpp | 21 ++++--- .../afv/crypto/cryptodtoserializer.cpp | 1 - src/blackcore/inputmanager.cpp | 2 +- .../sampleprovider/bufferedwaveprovider.cpp | 4 ++ .../equalizersampleprovider.cpp | 8 ++- .../sampleprovider/mixingsampleprovider.cpp | 21 ++++++- .../sampleprovider/mixingsampleprovider.h | 4 +- .../sampleprovider/resourcesound.cpp | 6 ++ src/blacksound/sampleprovider/resourcesound.h | 2 +- .../resourcesoundsampleprovider.cpp | 25 +++++--- .../sampleprovider/sinusgenerator.cpp | 22 ++++--- .../sampleprovider/sinusgenerator.h | 14 ++--- .../sampleprovider/volumesampleprovider.cpp | 15 +++-- 18 files changed, 170 insertions(+), 107 deletions(-) diff --git a/src/blackcore/afv/audio/callsignsampleprovider.cpp b/src/blackcore/afv/audio/callsignsampleprovider.cpp index e98e3c768..1a406d62a 100644 --- a/src/blackcore/afv/audio/callsignsampleprovider.cpp +++ b/src/blackcore/afv/audio/callsignsampleprovider.cpp @@ -6,8 +6,6 @@ * or distributed except according to the terms contained in the LICENSE file. */ -//! \file - #include "callsignsampleprovider.h" #include "callsigndelaycache.h" @@ -15,6 +13,7 @@ #include "blacksound/sampleprovider/samples.h" #include "blacksound/audioutilities.h" #include "blackmisc/logmessage.h" +#include "blackmisc/metadatautils.h" #include "blackconfig/buildconfig.h" #include @@ -30,15 +29,18 @@ namespace BlackCore { namespace Audio { - CallsignSampleProvider::CallsignSampleProvider(const QAudioFormat &audioFormat, const CReceiverSampleProvider *receiver, QObject *parent) : + CCallsignSampleProvider::CCallsignSampleProvider(const QAudioFormat &audioFormat, const CReceiverSampleProvider *receiver, QObject *parent) : ISampleProvider(parent), m_audioFormat(audioFormat), m_receiver(receiver), m_decoder(audioFormat.sampleRate(), 1) { Q_ASSERT(audioFormat.channelCount() == 1); + Q_ASSERT(receiver); + + const QString on = QStringLiteral("%1").arg(classNameShort(this)); + this->setObjectName(on); - this->setObjectName("CallsignSampleProvider"); m_mixer = new CMixingSampleProvider(this); m_crackleSoundProvider = new CResourceSoundSampleProvider(Samples::instance().crackle(), m_mixer); m_crackleSoundProvider->setLooping(true); @@ -57,23 +59,23 @@ namespace BlackCore m_simpleCompressorEffect->setMakeUpGain(-5.5); // Create the voice EQ - m_voiceEq = new CEqualizerSampleProvider(m_simpleCompressorEffect, EqualizerPresets::VHFEmulation, m_mixer); + m_voiceEqualizer = new CEqualizerSampleProvider(m_simpleCompressorEffect, EqualizerPresets::VHFEmulation, m_mixer); m_mixer->addMixerInput(m_whiteNoise); m_mixer->addMixerInput(m_acBusNoise); m_mixer->addMixerInput(m_hfWhiteNoise); - m_mixer->addMixerInput(m_voiceEq); + m_mixer->addMixerInput(m_voiceEqualizer); m_timer = new QTimer(this); - m_timer->setObjectName(this->objectName() + "m_timer"); + m_timer->setObjectName(this->objectName() + ":m_timer"); m_timer->setInterval(100); - connect(m_timer, &QTimer::timeout, this, &CallsignSampleProvider::timerElapsed); + connect(m_timer, &QTimer::timeout, this, &CCallsignSampleProvider::timerElapsed); } - int CallsignSampleProvider::readSamples(QVector &samples, qint64 count) + int CCallsignSampleProvider::readSamples(QVector &samples, qint64 count) { - int noOfSamples = m_mixer->readSamples(samples, count); + const int noOfSamples = m_mixer->readSamples(samples, count); if (m_inUse && m_lastPacketLatch && m_audioInput->getBufferedBytes() == 0) { @@ -91,7 +93,7 @@ namespace BlackCore return noOfSamples; } - void CallsignSampleProvider::timerElapsed() + void CCallsignSampleProvider::timerElapsed() { if (m_inUse && m_audioInput->getBufferedBytes() == 0 && m_lastSamplesAddedUtc.msecsTo(QDateTime::currentDateTimeUtc()) > m_idleTimeoutMs) { @@ -99,7 +101,7 @@ namespace BlackCore } } - void CallsignSampleProvider::active(const QString &callsign, const QString &aircraftType) + void CCallsignSampleProvider::active(const QString &callsign, const QString &aircraftType) { m_callsign = callsign; CallsignDelayCache::instance().initialise(callsign); @@ -109,17 +111,17 @@ namespace BlackCore setEffects(); m_underflow = false; - int delayMs = CallsignDelayCache::instance().get(callsign); + const int delayMs = CallsignDelayCache::instance().get(callsign); if (verbose()) { CLogMessage(this).debug(u"[%1] [Delay %2ms]") << m_callsign << delayMs; } if (delayMs > 0) { - int phaseDelayLength = (m_audioFormat.sampleRate() / 1000) * delayMs; - QVector phaseDelay(phaseDelayLength * 2, 0); + const int phaseDelayLength = (m_audioFormat.sampleRate() / 1000) * delayMs; + const QVector phaseDelay(phaseDelayLength * 2, 0); m_audioInput->addSamples(phaseDelay); } } - void CallsignSampleProvider::activeSilent(const QString &callsign, const QString &aircraftType) + void CCallsignSampleProvider::activeSilent(const QString &callsign, const QString &aircraftType) { m_callsign = callsign; CallsignDelayCache::instance().initialise(callsign); @@ -130,18 +132,18 @@ namespace BlackCore m_underflow = true; } - void CallsignSampleProvider::clear() + void CCallsignSampleProvider::clear() { idle(); m_audioInput->clearBuffer(); } - void CallsignSampleProvider::addOpusSamples(const IAudioDto &audioDto, float distanceRatio) + void CCallsignSampleProvider::addOpusSamples(const IAudioDto &audioDto, float distanceRatio) { m_distanceRatio = distanceRatio; setEffects(); - QVector audio = decodeOpus(audioDto.audio); + const QVector audio = decodeOpus(audioDto.audio); m_audioInput->addSamples(BlackSound::convertFromShortToFloat(audio)); m_lastPacketLatch = audioDto.lastPacket; if (audioDto.lastPacket && !m_underflow) { CallsignDelayCache::instance().success(m_callsign); } @@ -149,7 +151,7 @@ namespace BlackCore if (!m_timer->isActive()) { m_timer->start(); } } - void CallsignSampleProvider::addSilentSamples(const IAudioDto &audioDto) + void CCallsignSampleProvider::addSilentSamples(const IAudioDto &audioDto) { // Disable all audio effects setEffects(true); @@ -161,7 +163,7 @@ namespace BlackCore if (!m_timer->isActive()) { m_timer->start(); } } - void CallsignSampleProvider::idle() + void CCallsignSampleProvider::idle() { m_timer->stop(); m_inUse = false; @@ -170,14 +172,14 @@ namespace BlackCore m_type.clear(); } - QVector CallsignSampleProvider::decodeOpus(const QByteArray &opusData) + QVector CCallsignSampleProvider::decodeOpus(const QByteArray &opusData) { int decodedLength = 0; - QVector decoded = m_decoder.decode(opusData, opusData.size(), &decodedLength); + const QVector decoded = m_decoder.decode(opusData, opusData.size(), &decodedLength); return decoded; } - void CallsignSampleProvider::setEffects(bool noEffects) + void CCallsignSampleProvider::setEffects(bool noEffects) { if (noEffects || m_bypassEffects || !m_inUse) { @@ -186,7 +188,7 @@ namespace BlackCore m_hfWhiteNoise->setGain(0.0); m_acBusNoise->setGain(0.0); m_simpleCompressorEffect->setEnabled(false); - m_voiceEq->setBypassEffects(true); + m_voiceEqualizer->setBypassEffects(true); } else { @@ -201,8 +203,8 @@ namespace BlackCore m_hfWhiteNoise->setGain(m_hfWhiteNoiseGainMin); m_acBusNoise->setGain(m_acBusGainMin + 0.001f); m_simpleCompressorEffect->setEnabled(true); - m_voiceEq->setBypassEffects(false); - m_voiceEq->setOutputGain(0.38); + m_voiceEqualizer->setBypassEffects(false); + m_voiceEqualizer->setOutputGain(0.38); m_whiteNoise->setGain(0.0); } else @@ -216,13 +218,13 @@ namespace BlackCore m_whiteNoise->setGain(m_whiteNoiseGainMin); m_acBusNoise->setGain(m_acBusGainMin); m_simpleCompressorEffect->setEnabled(true); - m_voiceEq->setBypassEffects(false); - m_voiceEq->setOutputGain(1.0 - crackleFactor * 3.7); + m_voiceEqualizer->setBypassEffects(false); + m_voiceEqualizer->setOutputGain(1.0 - crackleFactor * 3.7); } } } - void CallsignSampleProvider::setBypassEffects(bool bypassEffects) + void CCallsignSampleProvider::setBypassEffects(bool bypassEffects) { m_bypassEffects = bypassEffects; setEffects(); diff --git a/src/blackcore/afv/audio/callsignsampleprovider.h b/src/blackcore/afv/audio/callsignsampleprovider.h index 8ad6d980b..8deeb99ae 100644 --- a/src/blackcore/afv/audio/callsignsampleprovider.h +++ b/src/blackcore/afv/audio/callsignsampleprovider.h @@ -35,14 +35,14 @@ namespace BlackCore { class CReceiverSampleProvider; - //! Callsign provide - class CallsignSampleProvider : public BlackSound::SampleProvider::ISampleProvider + //! Callsign provider + class CCallsignSampleProvider : public BlackSound::SampleProvider::ISampleProvider { Q_OBJECT public: //! Ctor - CallsignSampleProvider(const QAudioFormat &audioFormat, const BlackCore::Afv::Audio::CReceiverSampleProvider *receiver, QObject *parent = nullptr); + CCallsignSampleProvider(const QAudioFormat &audioFormat, const BlackCore::Afv::Audio::CReceiverSampleProvider *receiver, QObject *parent = nullptr); //! Read samples int readSamples(QVector &samples, qint64 count) override; @@ -93,15 +93,15 @@ namespace BlackCore bool m_bypassEffects = false; float m_distanceRatio = 1.0; - const CReceiverSampleProvider *m_receiver = nullptr; - BlackSound::SampleProvider::CMixingSampleProvider *m_mixer = nullptr; - BlackSound::SampleProvider::CResourceSoundSampleProvider *m_crackleSoundProvider = nullptr; - BlackSound::SampleProvider::CResourceSoundSampleProvider *m_whiteNoise = nullptr; - BlackSound::SampleProvider::CResourceSoundSampleProvider *m_hfWhiteNoise = nullptr; - BlackSound::SampleProvider::CSawToothGenerator *m_acBusNoise = nullptr; + const CReceiverSampleProvider *m_receiver = nullptr; + BlackSound::SampleProvider::CMixingSampleProvider *m_mixer = nullptr; + BlackSound::SampleProvider::CResourceSoundSampleProvider *m_crackleSoundProvider = nullptr; + BlackSound::SampleProvider::CResourceSoundSampleProvider *m_whiteNoise = nullptr; + BlackSound::SampleProvider::CResourceSoundSampleProvider *m_hfWhiteNoise = nullptr; + BlackSound::SampleProvider::CSawToothGenerator *m_acBusNoise = nullptr; BlackSound::SampleProvider::CSimpleCompressorEffect *m_simpleCompressorEffect = nullptr; - BlackSound::SampleProvider::CEqualizerSampleProvider *m_voiceEq = nullptr; - BlackSound::SampleProvider::CBufferedWaveProvider *m_audioInput = nullptr; + BlackSound::SampleProvider::CEqualizerSampleProvider *m_voiceEqualizer = nullptr; + BlackSound::SampleProvider::CBufferedWaveProvider *m_audioInput = nullptr; QTimer *m_timer = nullptr; BlackSound::Codecs::COpusDecoder m_decoder; diff --git a/src/blackcore/afv/audio/output.cpp b/src/blackcore/afv/audio/output.cpp index 6dc58bd66..877c531a4 100644 --- a/src/blackcore/afv/audio/output.cpp +++ b/src/blackcore/afv/audio/output.cpp @@ -6,10 +6,9 @@ * or distributed except according to the terms contained in the LICENSE file. */ -//! \file - #include "output.h" #include "blacksound/audioutilities.h" +#include "blackmisc/metadatautils.h" #include "blackmisc/logmessage.h" #include "blackmisc/verify.h" @@ -32,7 +31,9 @@ namespace BlackCore QIODevice(parent), m_sampleProvider(sampleProvider) { - this->setObjectName("CAudioOutputBuffer"); + Q_ASSERT_X(sampleProvider, Q_FUNC_INFO, "need sample provide"); + const QString on = QStringLiteral("%1 for %2").arg(classNameShort(this), sampleProvider->objectName()); + this->setObjectName(on); } qint64 CAudioOutputBuffer::readData(char *data, qint64 maxlen) @@ -43,7 +44,7 @@ namespace BlackCore QVector buffer; m_sampleProvider->readSamples(buffer, count); - for (float sample : buffer) + for (float sample : as_const(buffer)) { const float absSample = qAbs(sample); if (absSample > m_maxSampleOutput) { m_maxSampleOutput = absSample; } @@ -54,14 +55,14 @@ namespace BlackCore { OutputVolumeStreamArgs outputVolumeStreamArgs; outputVolumeStreamArgs.PeakRaw = m_maxSampleOutput / 1.0; - outputVolumeStreamArgs.PeakDb = static_cast(20 * std::log10(outputVolumeStreamArgs.PeakRaw)); + outputVolumeStreamArgs.PeakDb = static_cast(20 * std::log10(outputVolumeStreamArgs.PeakRaw)); const double db = qBound(m_minDb, outputVolumeStreamArgs.PeakDb, m_maxDb); double ratio = (db - m_minDb) / (m_maxDb - m_minDb); if (ratio < 0.30) { ratio = 0.0; } if (ratio > 1.0) { ratio = 1.0; } outputVolumeStreamArgs.PeakVU = ratio; emit outputVolumeStream(outputVolumeStreamArgs); - m_sampleCount = 0; + m_sampleCount = 0; m_maxSampleOutput = 0; } @@ -83,7 +84,7 @@ namespace BlackCore COutput::COutput(QObject *parent) : QObject(parent) { - this->setObjectName("COutput"); + this->setObjectName(classNameShort(this)); } void COutput::start(const CAudioDeviceInfo &outputDevice, ISampleProvider *sampleProvider) diff --git a/src/blackcore/afv/audio/receiversampleprovider.cpp b/src/blackcore/afv/audio/receiversampleprovider.cpp index b9f979e29..7cb28a652 100644 --- a/src/blackcore/afv/audio/receiversampleprovider.cpp +++ b/src/blackcore/afv/audio/receiversampleprovider.cpp @@ -10,6 +10,7 @@ #include "receiversampleprovider.h" #include "blackmisc/logmessage.h" +#include "blackmisc/metadatautils.h" #include "blacksound/sampleprovider/resourcesoundsampleprovider.h" #include "blacksound/sampleprovider/samples.h" @@ -36,11 +37,13 @@ namespace BlackCore ISampleProvider(parent), m_id(id) { - m_mixer = new CMixingSampleProvider(this); + const QString on = QStringLiteral("%1 id: %2").arg(classNameShort(this)).arg(id); + this->setObjectName(on); + m_mixer = new CMixingSampleProvider(this); for (int i = 0; i < voiceInputNumber; i++) { - const auto voiceInput = new CallsignSampleProvider(audioFormat, this, m_mixer); + const auto voiceInput = new CCallsignSampleProvider(audioFormat, this, m_mixer); m_voiceInputs.push_back(voiceInput); m_mixer->addMixerInput(voiceInput); } @@ -52,7 +55,7 @@ namespace BlackCore void CReceiverSampleProvider::setBypassEffects(bool value) { - for (CallsignSampleProvider *voiceInput : m_voiceInputs) + for (CCallsignSampleProvider *voiceInput : m_voiceInputs) { voiceInput->setBypassEffects(value); } @@ -62,7 +65,7 @@ namespace BlackCore { if (frequencyHz != m_frequencyHz) { - for (CallsignSampleProvider *voiceInput : m_voiceInputs) + for (CCallsignSampleProvider *voiceInput : m_voiceInputs) { voiceInput->clear(); } @@ -72,7 +75,7 @@ namespace BlackCore int CReceiverSampleProvider::activeCallsigns() const { - const int numberOfCallsigns = static_cast(std::count_if(m_voiceInputs.begin(), m_voiceInputs.end(), [](const CallsignSampleProvider * p) + const int numberOfCallsigns = static_cast(std::count_if(m_voiceInputs.begin(), m_voiceInputs.end(), [](const CCallsignSampleProvider * p) { return p->inUse() == true; })); @@ -84,7 +87,7 @@ namespace BlackCore m_mute = value; if (value) { - for (CallsignSampleProvider *voiceInput : m_voiceInputs) + for (CCallsignSampleProvider *voiceInput : m_voiceInputs) { voiceInput->clear(); } @@ -108,14 +111,14 @@ namespace BlackCore { CResourceSoundSampleProvider *resourceSound = new CResourceSoundSampleProvider(Samples::instance().click(), m_mixer); m_mixer->addMixerInput(resourceSound); - // CLogMessage(this).debug(u"AFV Click..."); m_doClickWhenAppropriate = false; + // CLogMessage(this).debug(u"AFV Click..."); } if (numberOfInUseInputs != m_lastNumberOfInUseInputs) { QStringList receivingCallsigns; - for (const CallsignSampleProvider *voiceInput : m_voiceInputs) + for (const CCallsignSampleProvider *voiceInput : m_voiceInputs) { const QString callsign = voiceInput->callsign(); if (! callsign.isEmpty()) @@ -136,9 +139,9 @@ namespace BlackCore void CReceiverSampleProvider::addOpusSamples(const IAudioDto &audioDto, uint frequency, float distanceRatio) { if (m_frequencyHz != frequency) { return; } // Lag in the backend means we get the tail end of a transmission - CallsignSampleProvider *voiceInput = nullptr; + CCallsignSampleProvider *voiceInput = nullptr; - auto it = std::find_if(m_voiceInputs.begin(), m_voiceInputs.end(), [audioDto](const CallsignSampleProvider * p) + auto it = std::find_if(m_voiceInputs.begin(), m_voiceInputs.end(), [audioDto](const CCallsignSampleProvider * p) { return p->callsign() == audioDto.callsign; }); @@ -150,7 +153,7 @@ namespace BlackCore if (! voiceInput) { - it = std::find_if(m_voiceInputs.begin(), m_voiceInputs.end(), [](const CallsignSampleProvider * p) { return p->inUse() == false; }); + it = std::find_if(m_voiceInputs.begin(), m_voiceInputs.end(), [](const CCallsignSampleProvider * p) { return p->inUse() == false; }); if (it != m_voiceInputs.end()) { voiceInput = *it; @@ -173,8 +176,8 @@ namespace BlackCore Q_UNUSED(distanceRatio) if (m_frequencyHz != frequency) { return; } // Lag in the backend means we get the tail end of a transmission - CallsignSampleProvider *voiceInput = nullptr; - auto it = std::find_if(m_voiceInputs.begin(), m_voiceInputs.end(), [audioDto](const CallsignSampleProvider * p) + CCallsignSampleProvider *voiceInput = nullptr; + auto it = std::find_if(m_voiceInputs.begin(), m_voiceInputs.end(), [audioDto](const CCallsignSampleProvider * p) { return p->callsign() == audioDto.callsign; }); @@ -186,7 +189,7 @@ namespace BlackCore if (!voiceInput) { - it = std::find_if(m_voiceInputs.begin(), m_voiceInputs.end(), [](const CallsignSampleProvider * p) { return p->inUse() == false; }); + it = std::find_if(m_voiceInputs.begin(), m_voiceInputs.end(), [](const CCallsignSampleProvider * p) { return p->inUse() == false; }); if (it != m_voiceInputs.end()) { voiceInput = *it; diff --git a/src/blackcore/afv/audio/receiversampleprovider.h b/src/blackcore/afv/audio/receiversampleprovider.h index db69e31bb..666b79849 100644 --- a/src/blackcore/afv/audio/receiversampleprovider.h +++ b/src/blackcore/afv/audio/receiversampleprovider.h @@ -103,7 +103,7 @@ namespace BlackCore BlackSound::SampleProvider::CVolumeSampleProvider *m_volume = nullptr; BlackSound::SampleProvider::CMixingSampleProvider *m_mixer = nullptr; BlackSound::SampleProvider::CSinusGenerator *m_blockTone = nullptr; - QVector m_voiceInputs; + QVector m_voiceInputs; QString m_receivingCallsignsString; BlackMisc::Aviation::CCallsignSet m_receivingCallsigns; diff --git a/src/blackcore/afv/audio/soundcardsampleprovider.cpp b/src/blackcore/afv/audio/soundcardsampleprovider.cpp index b93fdedd9..63ad467ec 100644 --- a/src/blackcore/afv/audio/soundcardsampleprovider.cpp +++ b/src/blackcore/afv/audio/soundcardsampleprovider.cpp @@ -6,10 +6,10 @@ * or distributed except according to the terms contained in the LICENSE file. */ -//! \file - #include "soundcardsampleprovider.h" +#include "blackmisc/metadatautils.h" +using namespace BlackMisc; using namespace BlackSound::SampleProvider; namespace BlackCore @@ -22,6 +22,9 @@ namespace BlackCore ISampleProvider(parent), m_mixer(new CMixingSampleProvider()) { + const QString on = QStringLiteral("%1 sample rate: %2, transceivers: %3").arg(classNameShort(this)).arg(sampleRate).arg(transceiverIDs.size()); + this->setObjectName(on); + m_waveFormat.setSampleRate(sampleRate); m_waveFormat.setChannelCount(1); m_waveFormat.setSampleSize(16); @@ -32,9 +35,10 @@ namespace BlackCore m_mixer = new CMixingSampleProvider(this); m_receiverIDs = transceiverIDs; + constexpr int voiceInputNumber = 4; // number of CallsignSampleProviders for (quint16 transceiverID : transceiverIDs) { - CReceiverSampleProvider *transceiverInput = new CReceiverSampleProvider(m_waveFormat, transceiverID, 4, m_mixer); + CReceiverSampleProvider *transceiverInput = new CReceiverSampleProvider(m_waveFormat, transceiverID, voiceInputNumber, m_mixer); connect(transceiverInput, &CReceiverSampleProvider::receivingCallsignsChanged, this, &CSoundcardSampleProvider::receivingCallsignsChanged); m_receiverInputs.push_back(transceiverInput); m_receiverIDs.push_back(transceiverID); @@ -111,7 +115,7 @@ namespace BlackCore QVector handledTransceiverIDs; for (int i = 0; i < rxTransceiversFilteredAndSorted.size(); i++) { - RxTransceiverDto rxTransceiver = rxTransceiversFilteredAndSorted[i]; + const RxTransceiverDto rxTransceiver = rxTransceiversFilteredAndSorted[i]; if (!handledTransceiverIDs.contains(rxTransceiver.id)) { handledTransceiverIDs.push_back(rxTransceiver.id); @@ -121,12 +125,13 @@ namespace BlackCore { return p->getId() == rxTransceiver.id; }); + if (it != m_receiverInputs.end()) { receiverInput = *it; } - if (! receiverInput) { continue; } + if (!receiverInput) { continue; } if (receiverInput->getMute()) { continue; } if (!audioPlayed) @@ -160,9 +165,9 @@ namespace BlackCore for (CReceiverSampleProvider *receiverInput : m_receiverInputs) { - quint16 transceiverID = receiverInput->getId(); - bool contains = std::any_of(radioTransceivers.begin(), radioTransceivers.end(), [&](const auto & tx) { return transceiverID == tx.id; }); - if (! contains) + const quint16 transceiverID = receiverInput->getId(); + const bool contains = std::any_of(radioTransceivers.cbegin(), radioTransceivers.cend(), [ transceiverID ](const auto &tx) { return transceiverID == tx.id; }); + if (!contains) { receiverInput->setFrequency(0); } diff --git a/src/blackcore/afv/crypto/cryptodtoserializer.cpp b/src/blackcore/afv/crypto/cryptodtoserializer.cpp index ecc25f968..4f2b595a3 100644 --- a/src/blackcore/afv/crypto/cryptodtoserializer.cpp +++ b/src/blackcore/afv/crypto/cryptodtoserializer.cpp @@ -8,7 +8,6 @@ #include "cryptodtoserializer.h" - namespace BlackCore { namespace Afv diff --git a/src/blackcore/inputmanager.cpp b/src/blackcore/inputmanager.cpp index 9e64f0434..1a701a5f9 100644 --- a/src/blackcore/inputmanager.cpp +++ b/src/blackcore/inputmanager.cpp @@ -149,7 +149,7 @@ namespace BlackCore info.m_index = index; ++index; info.m_function = function; - info.m_action = action; + info.m_action = action; info.m_receiver = receiver; m_boundActions.push_back(info); return info.m_index; diff --git a/src/blacksound/sampleprovider/bufferedwaveprovider.cpp b/src/blacksound/sampleprovider/bufferedwaveprovider.cpp index 3926239a0..7176e2c99 100644 --- a/src/blacksound/sampleprovider/bufferedwaveprovider.cpp +++ b/src/blacksound/sampleprovider/bufferedwaveprovider.cpp @@ -1,4 +1,5 @@ #include "bufferedwaveprovider.h" +#include "blacksound/audioutilities.h" #include @@ -9,6 +10,9 @@ namespace BlackSound CBufferedWaveProvider::CBufferedWaveProvider(const QAudioFormat &format, QObject *parent) : ISampleProvider(parent) { + const QString on = QStringLiteral("%1 format: ").arg(this->metaObject()->className(), BlackSound::toQString(format)); + this->setObjectName(on); + // Set buffer size to 10 secs m_maxBufferSize = format.bytesForDuration(10 * 1000 * 1000); } diff --git a/src/blacksound/sampleprovider/equalizersampleprovider.cpp b/src/blacksound/sampleprovider/equalizersampleprovider.cpp index 2a37e8cb4..bcf67f526 100644 --- a/src/blacksound/sampleprovider/equalizersampleprovider.cpp +++ b/src/blacksound/sampleprovider/equalizersampleprovider.cpp @@ -11,13 +11,17 @@ namespace BlackSound CEqualizerSampleProvider::CEqualizerSampleProvider(ISampleProvider *sourceProvider, EqualizerPresets preset, QObject *parent) : ISampleProvider(parent) { + Q_ASSERT_X(sourceProvider, Q_FUNC_INFO, "Need provider"); + const QString on = QStringLiteral("%1 of %2").arg(this->metaObject()->className(), sourceProvider->objectName()); + this->setObjectName(on); + m_sourceProvider = sourceProvider; setupPreset(preset); } int CEqualizerSampleProvider::readSamples(QVector &samples, qint64 count) { - int samplesRead = m_sourceProvider->readSamples(samples, count); + const int samplesRead = m_sourceProvider->readSamples(samples, count); if (m_bypass) return samplesRead; for (int n = 0; n < samplesRead; n++) @@ -26,7 +30,7 @@ namespace BlackSound { samples[n] = m_filters[band].transform(samples[n]); } - samples[n] *= m_outputGain; + samples[n] *= static_cast(m_outputGain); } return samplesRead; } diff --git a/src/blacksound/sampleprovider/mixingsampleprovider.cpp b/src/blacksound/sampleprovider/mixingsampleprovider.cpp index 35e68fe0a..6e5df8d0a 100644 --- a/src/blacksound/sampleprovider/mixingsampleprovider.cpp +++ b/src/blacksound/sampleprovider/mixingsampleprovider.cpp @@ -7,11 +7,29 @@ */ #include "mixingsampleprovider.h" +#include "blackmisc/metadatautils.h" + +using namespace BlackMisc; namespace BlackSound { namespace SampleProvider { + CMixingSampleProvider::CMixingSampleProvider(QObject *parent) : ISampleProvider(parent) + { + const QString on = QStringLiteral("%1").arg(classNameShort(this)); + this->setObjectName(on); + } + + void CMixingSampleProvider::addMixerInput(ISampleProvider *provider) + { + Q_ASSERT(provider); + m_sources.append(provider); + + const QString on = QStringLiteral("%1 sources: %2").arg(classNameShort(this)).arg(m_sources.size()); + this->setObjectName(on); + } + int CMixingSampleProvider::readSamples(QVector &samples, qint64 count) { samples.clear(); @@ -23,15 +41,14 @@ namespace BlackSound { ISampleProvider *sampleProvider = m_sources.at(i); QVector sourceBuffer; - int len = sampleProvider->readSamples(sourceBuffer, count); + const int len = sampleProvider->readSamples(sourceBuffer, count); for (int n = 0; n < len; n++) { samples[n] += sourceBuffer[n]; } outputLen = qMax(len, outputLen); - if (sampleProvider->isFinished()) { finishedProviders.push_back(sampleProvider); diff --git a/src/blacksound/sampleprovider/mixingsampleprovider.h b/src/blacksound/sampleprovider/mixingsampleprovider.h index 2bb6864e8..3b5316e2b 100644 --- a/src/blacksound/sampleprovider/mixingsampleprovider.h +++ b/src/blacksound/sampleprovider/mixingsampleprovider.h @@ -25,10 +25,10 @@ namespace BlackSound { public: //! Ctor mixing provider - CMixingSampleProvider(QObject *parent = nullptr) : ISampleProvider(parent) {} + CMixingSampleProvider(QObject *parent = nullptr); //! Add a provider - void addMixerInput(ISampleProvider *provider) { m_sources.append(provider); } + void addMixerInput(ISampleProvider *provider); //! \copydoc ISampleProvider::readSamples virtual int readSamples(QVector &samples, qint64 count) override; diff --git a/src/blacksound/sampleprovider/resourcesound.cpp b/src/blacksound/sampleprovider/resourcesound.cpp index 42a9d29de..4c3e9069e 100644 --- a/src/blacksound/sampleprovider/resourcesound.cpp +++ b/src/blacksound/sampleprovider/resourcesound.cpp @@ -54,6 +54,12 @@ namespace BlackSound return true; } + const QString &CResourceSound::getFileName() const + { + static const QString empty; + return m_data ? empty : m_data->fileName; + } + bool CResourceSound::isSameFileName(const QString &fn) const { if (fn.isEmpty()) { return false; } diff --git a/src/blacksound/sampleprovider/resourcesound.h b/src/blacksound/sampleprovider/resourcesound.h index 976e63f15..adfd83839 100644 --- a/src/blacksound/sampleprovider/resourcesound.h +++ b/src/blacksound/sampleprovider/resourcesound.h @@ -52,7 +52,7 @@ namespace BlackSound const QVector &audioData() const { return m_data->samples; } //! Corresponding file - const QString &getFileName() { return m_data->fileName; } + const QString &getFileName() const; //! Is same file? bool isSameFileName(const QString &fn) const; diff --git a/src/blacksound/sampleprovider/resourcesoundsampleprovider.cpp b/src/blacksound/sampleprovider/resourcesoundsampleprovider.cpp index 26426186d..f782bbbf6 100644 --- a/src/blacksound/sampleprovider/resourcesoundsampleprovider.cpp +++ b/src/blacksound/sampleprovider/resourcesoundsampleprovider.cpp @@ -1,7 +1,18 @@ +/* Copyright (C) 2019 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated, + * or distributed except according to the terms contained in the LICENSE file. + */ + #include "resourcesoundsampleprovider.h" -#include "resourcesoundsampleprovider.h" +#include "blackmisc/metadatautils.h" + #include +using namespace BlackMisc; + namespace BlackSound { namespace SampleProvider @@ -10,21 +21,21 @@ namespace BlackSound ISampleProvider(parent), m_resourceSound(resourceSound) { + const QString on = QStringLiteral("%1 %2").arg(classNameShort(this), resourceSound.getFileName()); + this->setObjectName(on); m_tempBuffer.resize(m_tempBufferSize); } int CResourceSoundSampleProvider::readSamples(QVector &samples, qint64 count) { - if (! m_resourceSound.isLoaded()) { return 0; } - + if (!m_resourceSound.isLoaded()) { return 0; } if (count > m_tempBufferSize) { qDebug() << "Count too large for temp buffer" << count; return 0; } - qint64 availableSamples = m_resourceSound.audioData().size() - m_position; - - const qint64 samplesToCopy = qMin(availableSamples, count); + const qint64 availableSamples = m_resourceSound.audioData().size() - m_position; + const qint64 samplesToCopy = qMin(availableSamples, count); samples.clear(); samples.fill(0, static_cast(samplesToCopy)); @@ -37,7 +48,7 @@ namespace BlackSound { for (int i = 0; i < samplesToCopy; i++) { - m_tempBuffer[i] *= m_gain; + m_tempBuffer[i] = static_cast(m_gain * m_tempBuffer[i]); } } diff --git a/src/blacksound/sampleprovider/sinusgenerator.cpp b/src/blacksound/sampleprovider/sinusgenerator.cpp index d7d1f7ff8..7378ad957 100644 --- a/src/blacksound/sampleprovider/sinusgenerator.cpp +++ b/src/blacksound/sampleprovider/sinusgenerator.cpp @@ -7,16 +7,22 @@ */ #include "sinusgenerator.h" +#include "blackmisc/metadatautils.h" #include +using namespace BlackMisc; + namespace BlackSound { namespace SampleProvider { - CSinusGenerator::CSinusGenerator(double frequency, QObject *parent) : + CSinusGenerator::CSinusGenerator(double frequencyHz, QObject *parent) : ISampleProvider(parent), - m_frequency(frequency) - {} + m_frequencyHz(frequencyHz) + { + const QString on = QStringLiteral("%1 frequency: %2Hz").arg(classNameShort(this)).arg(frequencyHz); + this->setObjectName(on); + } int CSinusGenerator::readSamples(QVector &samples, qint64 count) { @@ -25,17 +31,17 @@ namespace BlackSound for (int sampleCount = 0; sampleCount < count; sampleCount++) { - double multiple = m_twoPi * m_frequency / m_sampleRate; - double sampleValue = m_gain * qSin(m_nSample * multiple); - samples[sampleCount] = static_cast(sampleValue); + const double multiple = s_twoPi * m_frequencyHz / m_sampleRate; + const double sampleValue = m_gain * qSin(m_nSample * multiple); + samples[sampleCount] = static_cast(sampleValue); m_nSample++; } return static_cast(count); } - void CSinusGenerator::setFrequency(double frequency) + void CSinusGenerator::setFrequency(double frequencyHz) { - m_frequency = frequency; + m_frequencyHz = frequencyHz; } } // ns } // ns diff --git a/src/blacksound/sampleprovider/sinusgenerator.h b/src/blacksound/sampleprovider/sinusgenerator.h index 1a398a579..70286aa05 100644 --- a/src/blacksound/sampleprovider/sinusgenerator.h +++ b/src/blacksound/sampleprovider/sinusgenerator.h @@ -27,7 +27,7 @@ namespace BlackSound public: //! Ctor - CSinusGenerator(double frequency, QObject *parent = nullptr); + CSinusGenerator(double frequencyHz, QObject *parent = nullptr); //! \copydoc ISampleProvider::readSamples virtual int readSamples(QVector &samples, qint64 count) override; @@ -36,14 +36,14 @@ namespace BlackSound void setGain(double gain) { m_gain = gain; } //! Set frequency in Hz - void setFrequency(double frequency); + void setFrequency(double frequencyHz); private: - double m_gain = 0.0; - double m_frequency = 0.0; - double m_sampleRate = 48000; - int m_nSample = 0; - const double m_twoPi = 2 * M_PI; + double m_gain = 0.0; + double m_frequencyHz = 0.0; + double m_sampleRate = 48000; + int m_nSample = 0; + static constexpr double s_twoPi = 2 * M_PI; }; } // ns } // ns diff --git a/src/blacksound/sampleprovider/volumesampleprovider.cpp b/src/blacksound/sampleprovider/volumesampleprovider.cpp index 37047758f..c8fc59778 100644 --- a/src/blacksound/sampleprovider/volumesampleprovider.cpp +++ b/src/blacksound/sampleprovider/volumesampleprovider.cpp @@ -9,7 +9,9 @@ //! \file #include "volumesampleprovider.h" -#include "volumesampleprovider.h" +#include "blackmisc/metadatautils.h" + +using namespace BlackMisc; namespace BlackSound { @@ -18,17 +20,20 @@ namespace BlackSound CVolumeSampleProvider::CVolumeSampleProvider(ISampleProvider *sourceProvider, QObject *parent) : ISampleProvider(parent), m_sourceProvider(sourceProvider) - { } + { + Q_ASSERT_X(sourceProvider, Q_FUNC_INFO, "Need source provider"); + const QString on = QStringLiteral("%1 with source: %2").arg(classNameShort(this), sourceProvider->objectName()); + this->setObjectName(on); + } int CVolumeSampleProvider::readSamples(QVector &samples, qint64 count) { - int samplesRead = m_sourceProvider->readSamples(samples, count); - + const int samplesRead = m_sourceProvider->readSamples(samples, count); if (!qFuzzyCompare(m_volume, 1.0)) { for (int n = 0; n < samplesRead; n++) { - samples[n] *= static_cast(m_volume); + samples[n] = static_cast(m_volume * samples[n]); } } return samplesRead;