mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-30 14:15:35 +08:00
[AFV] misc style issues:
* object name * simple style fixes * some renamings * comments
This commit is contained in:
committed by
Mat Sutcliffe
parent
c1622951b3
commit
7d51bedc3e
@@ -6,8 +6,6 @@
|
|||||||
* or distributed except according to the terms contained in the LICENSE file.
|
* or distributed except according to the terms contained in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//! \file
|
|
||||||
|
|
||||||
#include "callsignsampleprovider.h"
|
#include "callsignsampleprovider.h"
|
||||||
#include "callsigndelaycache.h"
|
#include "callsigndelaycache.h"
|
||||||
|
|
||||||
@@ -15,6 +13,7 @@
|
|||||||
#include "blacksound/sampleprovider/samples.h"
|
#include "blacksound/sampleprovider/samples.h"
|
||||||
#include "blacksound/audioutilities.h"
|
#include "blacksound/audioutilities.h"
|
||||||
#include "blackmisc/logmessage.h"
|
#include "blackmisc/logmessage.h"
|
||||||
|
#include "blackmisc/metadatautils.h"
|
||||||
#include "blackconfig/buildconfig.h"
|
#include "blackconfig/buildconfig.h"
|
||||||
|
|
||||||
#include <QtMath>
|
#include <QtMath>
|
||||||
@@ -30,15 +29,18 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
namespace Audio
|
namespace Audio
|
||||||
{
|
{
|
||||||
CallsignSampleProvider::CallsignSampleProvider(const QAudioFormat &audioFormat, const CReceiverSampleProvider *receiver, QObject *parent) :
|
CCallsignSampleProvider::CCallsignSampleProvider(const QAudioFormat &audioFormat, const CReceiverSampleProvider *receiver, QObject *parent) :
|
||||||
ISampleProvider(parent),
|
ISampleProvider(parent),
|
||||||
m_audioFormat(audioFormat),
|
m_audioFormat(audioFormat),
|
||||||
m_receiver(receiver),
|
m_receiver(receiver),
|
||||||
m_decoder(audioFormat.sampleRate(), 1)
|
m_decoder(audioFormat.sampleRate(), 1)
|
||||||
{
|
{
|
||||||
Q_ASSERT(audioFormat.channelCount() == 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_mixer = new CMixingSampleProvider(this);
|
||||||
m_crackleSoundProvider = new CResourceSoundSampleProvider(Samples::instance().crackle(), m_mixer);
|
m_crackleSoundProvider = new CResourceSoundSampleProvider(Samples::instance().crackle(), m_mixer);
|
||||||
m_crackleSoundProvider->setLooping(true);
|
m_crackleSoundProvider->setLooping(true);
|
||||||
@@ -57,23 +59,23 @@ namespace BlackCore
|
|||||||
m_simpleCompressorEffect->setMakeUpGain(-5.5);
|
m_simpleCompressorEffect->setMakeUpGain(-5.5);
|
||||||
|
|
||||||
// Create the voice EQ
|
// 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_whiteNoise);
|
||||||
m_mixer->addMixerInput(m_acBusNoise);
|
m_mixer->addMixerInput(m_acBusNoise);
|
||||||
m_mixer->addMixerInput(m_hfWhiteNoise);
|
m_mixer->addMixerInput(m_hfWhiteNoise);
|
||||||
m_mixer->addMixerInput(m_voiceEq);
|
m_mixer->addMixerInput(m_voiceEqualizer);
|
||||||
|
|
||||||
m_timer = new QTimer(this);
|
m_timer = new QTimer(this);
|
||||||
m_timer->setObjectName(this->objectName() + "m_timer");
|
m_timer->setObjectName(this->objectName() + ":m_timer");
|
||||||
|
|
||||||
m_timer->setInterval(100);
|
m_timer->setInterval(100);
|
||||||
connect(m_timer, &QTimer::timeout, this, &CallsignSampleProvider::timerElapsed);
|
connect(m_timer, &QTimer::timeout, this, &CCallsignSampleProvider::timerElapsed);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CallsignSampleProvider::readSamples(QVector<float> &samples, qint64 count)
|
int CCallsignSampleProvider::readSamples(QVector<float> &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)
|
if (m_inUse && m_lastPacketLatch && m_audioInput->getBufferedBytes() == 0)
|
||||||
{
|
{
|
||||||
@@ -91,7 +93,7 @@ namespace BlackCore
|
|||||||
return noOfSamples;
|
return noOfSamples;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CallsignSampleProvider::timerElapsed()
|
void CCallsignSampleProvider::timerElapsed()
|
||||||
{
|
{
|
||||||
if (m_inUse && m_audioInput->getBufferedBytes() == 0 && m_lastSamplesAddedUtc.msecsTo(QDateTime::currentDateTimeUtc()) > m_idleTimeoutMs)
|
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;
|
m_callsign = callsign;
|
||||||
CallsignDelayCache::instance().initialise(callsign);
|
CallsignDelayCache::instance().initialise(callsign);
|
||||||
@@ -109,17 +111,17 @@ namespace BlackCore
|
|||||||
setEffects();
|
setEffects();
|
||||||
m_underflow = false;
|
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 (verbose()) { CLogMessage(this).debug(u"[%1] [Delay %2ms]") << m_callsign << delayMs; }
|
||||||
if (delayMs > 0)
|
if (delayMs > 0)
|
||||||
{
|
{
|
||||||
int phaseDelayLength = (m_audioFormat.sampleRate() / 1000) * delayMs;
|
const int phaseDelayLength = (m_audioFormat.sampleRate() / 1000) * delayMs;
|
||||||
QVector<float> phaseDelay(phaseDelayLength * 2, 0);
|
const QVector<float> phaseDelay(phaseDelayLength * 2, 0);
|
||||||
m_audioInput->addSamples(phaseDelay);
|
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;
|
m_callsign = callsign;
|
||||||
CallsignDelayCache::instance().initialise(callsign);
|
CallsignDelayCache::instance().initialise(callsign);
|
||||||
@@ -130,18 +132,18 @@ namespace BlackCore
|
|||||||
m_underflow = true;
|
m_underflow = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CallsignSampleProvider::clear()
|
void CCallsignSampleProvider::clear()
|
||||||
{
|
{
|
||||||
idle();
|
idle();
|
||||||
m_audioInput->clearBuffer();
|
m_audioInput->clearBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CallsignSampleProvider::addOpusSamples(const IAudioDto &audioDto, float distanceRatio)
|
void CCallsignSampleProvider::addOpusSamples(const IAudioDto &audioDto, float distanceRatio)
|
||||||
{
|
{
|
||||||
m_distanceRatio = distanceRatio;
|
m_distanceRatio = distanceRatio;
|
||||||
setEffects();
|
setEffects();
|
||||||
|
|
||||||
QVector<qint16> audio = decodeOpus(audioDto.audio);
|
const QVector<qint16> audio = decodeOpus(audioDto.audio);
|
||||||
m_audioInput->addSamples(BlackSound::convertFromShortToFloat(audio));
|
m_audioInput->addSamples(BlackSound::convertFromShortToFloat(audio));
|
||||||
m_lastPacketLatch = audioDto.lastPacket;
|
m_lastPacketLatch = audioDto.lastPacket;
|
||||||
if (audioDto.lastPacket && !m_underflow) { CallsignDelayCache::instance().success(m_callsign); }
|
if (audioDto.lastPacket && !m_underflow) { CallsignDelayCache::instance().success(m_callsign); }
|
||||||
@@ -149,7 +151,7 @@ namespace BlackCore
|
|||||||
if (!m_timer->isActive()) { m_timer->start(); }
|
if (!m_timer->isActive()) { m_timer->start(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
void CallsignSampleProvider::addSilentSamples(const IAudioDto &audioDto)
|
void CCallsignSampleProvider::addSilentSamples(const IAudioDto &audioDto)
|
||||||
{
|
{
|
||||||
// Disable all audio effects
|
// Disable all audio effects
|
||||||
setEffects(true);
|
setEffects(true);
|
||||||
@@ -161,7 +163,7 @@ namespace BlackCore
|
|||||||
if (!m_timer->isActive()) { m_timer->start(); }
|
if (!m_timer->isActive()) { m_timer->start(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
void CallsignSampleProvider::idle()
|
void CCallsignSampleProvider::idle()
|
||||||
{
|
{
|
||||||
m_timer->stop();
|
m_timer->stop();
|
||||||
m_inUse = false;
|
m_inUse = false;
|
||||||
@@ -170,14 +172,14 @@ namespace BlackCore
|
|||||||
m_type.clear();
|
m_type.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<qint16> CallsignSampleProvider::decodeOpus(const QByteArray &opusData)
|
QVector<qint16> CCallsignSampleProvider::decodeOpus(const QByteArray &opusData)
|
||||||
{
|
{
|
||||||
int decodedLength = 0;
|
int decodedLength = 0;
|
||||||
QVector<qint16> decoded = m_decoder.decode(opusData, opusData.size(), &decodedLength);
|
const QVector<qint16> decoded = m_decoder.decode(opusData, opusData.size(), &decodedLength);
|
||||||
return decoded;
|
return decoded;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CallsignSampleProvider::setEffects(bool noEffects)
|
void CCallsignSampleProvider::setEffects(bool noEffects)
|
||||||
{
|
{
|
||||||
if (noEffects || m_bypassEffects || !m_inUse)
|
if (noEffects || m_bypassEffects || !m_inUse)
|
||||||
{
|
{
|
||||||
@@ -186,7 +188,7 @@ namespace BlackCore
|
|||||||
m_hfWhiteNoise->setGain(0.0);
|
m_hfWhiteNoise->setGain(0.0);
|
||||||
m_acBusNoise->setGain(0.0);
|
m_acBusNoise->setGain(0.0);
|
||||||
m_simpleCompressorEffect->setEnabled(false);
|
m_simpleCompressorEffect->setEnabled(false);
|
||||||
m_voiceEq->setBypassEffects(true);
|
m_voiceEqualizer->setBypassEffects(true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -201,8 +203,8 @@ namespace BlackCore
|
|||||||
m_hfWhiteNoise->setGain(m_hfWhiteNoiseGainMin);
|
m_hfWhiteNoise->setGain(m_hfWhiteNoiseGainMin);
|
||||||
m_acBusNoise->setGain(m_acBusGainMin + 0.001f);
|
m_acBusNoise->setGain(m_acBusGainMin + 0.001f);
|
||||||
m_simpleCompressorEffect->setEnabled(true);
|
m_simpleCompressorEffect->setEnabled(true);
|
||||||
m_voiceEq->setBypassEffects(false);
|
m_voiceEqualizer->setBypassEffects(false);
|
||||||
m_voiceEq->setOutputGain(0.38);
|
m_voiceEqualizer->setOutputGain(0.38);
|
||||||
m_whiteNoise->setGain(0.0);
|
m_whiteNoise->setGain(0.0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -216,13 +218,13 @@ namespace BlackCore
|
|||||||
m_whiteNoise->setGain(m_whiteNoiseGainMin);
|
m_whiteNoise->setGain(m_whiteNoiseGainMin);
|
||||||
m_acBusNoise->setGain(m_acBusGainMin);
|
m_acBusNoise->setGain(m_acBusGainMin);
|
||||||
m_simpleCompressorEffect->setEnabled(true);
|
m_simpleCompressorEffect->setEnabled(true);
|
||||||
m_voiceEq->setBypassEffects(false);
|
m_voiceEqualizer->setBypassEffects(false);
|
||||||
m_voiceEq->setOutputGain(1.0 - crackleFactor * 3.7);
|
m_voiceEqualizer->setOutputGain(1.0 - crackleFactor * 3.7);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CallsignSampleProvider::setBypassEffects(bool bypassEffects)
|
void CCallsignSampleProvider::setBypassEffects(bool bypassEffects)
|
||||||
{
|
{
|
||||||
m_bypassEffects = bypassEffects;
|
m_bypassEffects = bypassEffects;
|
||||||
setEffects();
|
setEffects();
|
||||||
|
|||||||
@@ -35,14 +35,14 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
class CReceiverSampleProvider;
|
class CReceiverSampleProvider;
|
||||||
|
|
||||||
//! Callsign provide
|
//! Callsign provider
|
||||||
class CallsignSampleProvider : public BlackSound::SampleProvider::ISampleProvider
|
class CCallsignSampleProvider : public BlackSound::SampleProvider::ISampleProvider
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//! Ctor
|
//! 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
|
//! Read samples
|
||||||
int readSamples(QVector<float> &samples, qint64 count) override;
|
int readSamples(QVector<float> &samples, qint64 count) override;
|
||||||
@@ -93,15 +93,15 @@ namespace BlackCore
|
|||||||
|
|
||||||
bool m_bypassEffects = false;
|
bool m_bypassEffects = false;
|
||||||
float m_distanceRatio = 1.0;
|
float m_distanceRatio = 1.0;
|
||||||
const CReceiverSampleProvider *m_receiver = nullptr;
|
const CReceiverSampleProvider *m_receiver = nullptr;
|
||||||
BlackSound::SampleProvider::CMixingSampleProvider *m_mixer = nullptr;
|
BlackSound::SampleProvider::CMixingSampleProvider *m_mixer = nullptr;
|
||||||
BlackSound::SampleProvider::CResourceSoundSampleProvider *m_crackleSoundProvider = nullptr;
|
BlackSound::SampleProvider::CResourceSoundSampleProvider *m_crackleSoundProvider = nullptr;
|
||||||
BlackSound::SampleProvider::CResourceSoundSampleProvider *m_whiteNoise = nullptr;
|
BlackSound::SampleProvider::CResourceSoundSampleProvider *m_whiteNoise = nullptr;
|
||||||
BlackSound::SampleProvider::CResourceSoundSampleProvider *m_hfWhiteNoise = nullptr;
|
BlackSound::SampleProvider::CResourceSoundSampleProvider *m_hfWhiteNoise = nullptr;
|
||||||
BlackSound::SampleProvider::CSawToothGenerator *m_acBusNoise = nullptr;
|
BlackSound::SampleProvider::CSawToothGenerator *m_acBusNoise = nullptr;
|
||||||
BlackSound::SampleProvider::CSimpleCompressorEffect *m_simpleCompressorEffect = nullptr;
|
BlackSound::SampleProvider::CSimpleCompressorEffect *m_simpleCompressorEffect = nullptr;
|
||||||
BlackSound::SampleProvider::CEqualizerSampleProvider *m_voiceEq = nullptr;
|
BlackSound::SampleProvider::CEqualizerSampleProvider *m_voiceEqualizer = nullptr;
|
||||||
BlackSound::SampleProvider::CBufferedWaveProvider *m_audioInput = nullptr;
|
BlackSound::SampleProvider::CBufferedWaveProvider *m_audioInput = nullptr;
|
||||||
QTimer *m_timer = nullptr;
|
QTimer *m_timer = nullptr;
|
||||||
|
|
||||||
BlackSound::Codecs::COpusDecoder m_decoder;
|
BlackSound::Codecs::COpusDecoder m_decoder;
|
||||||
|
|||||||
@@ -6,10 +6,9 @@
|
|||||||
* or distributed except according to the terms contained in the LICENSE file.
|
* or distributed except according to the terms contained in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//! \file
|
|
||||||
|
|
||||||
#include "output.h"
|
#include "output.h"
|
||||||
#include "blacksound/audioutilities.h"
|
#include "blacksound/audioutilities.h"
|
||||||
|
#include "blackmisc/metadatautils.h"
|
||||||
#include "blackmisc/logmessage.h"
|
#include "blackmisc/logmessage.h"
|
||||||
#include "blackmisc/verify.h"
|
#include "blackmisc/verify.h"
|
||||||
|
|
||||||
@@ -32,7 +31,9 @@ namespace BlackCore
|
|||||||
QIODevice(parent),
|
QIODevice(parent),
|
||||||
m_sampleProvider(sampleProvider)
|
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)
|
qint64 CAudioOutputBuffer::readData(char *data, qint64 maxlen)
|
||||||
@@ -43,7 +44,7 @@ namespace BlackCore
|
|||||||
QVector<float> buffer;
|
QVector<float> buffer;
|
||||||
m_sampleProvider->readSamples(buffer, count);
|
m_sampleProvider->readSamples(buffer, count);
|
||||||
|
|
||||||
for (float sample : buffer)
|
for (float sample : as_const(buffer))
|
||||||
{
|
{
|
||||||
const float absSample = qAbs(sample);
|
const float absSample = qAbs(sample);
|
||||||
if (absSample > m_maxSampleOutput) { m_maxSampleOutput = absSample; }
|
if (absSample > m_maxSampleOutput) { m_maxSampleOutput = absSample; }
|
||||||
@@ -54,14 +55,14 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
OutputVolumeStreamArgs outputVolumeStreamArgs;
|
OutputVolumeStreamArgs outputVolumeStreamArgs;
|
||||||
outputVolumeStreamArgs.PeakRaw = m_maxSampleOutput / 1.0;
|
outputVolumeStreamArgs.PeakRaw = m_maxSampleOutput / 1.0;
|
||||||
outputVolumeStreamArgs.PeakDb = static_cast<float>(20 * std::log10(outputVolumeStreamArgs.PeakRaw));
|
outputVolumeStreamArgs.PeakDb = static_cast<float>(20 * std::log10(outputVolumeStreamArgs.PeakRaw));
|
||||||
const double db = qBound(m_minDb, outputVolumeStreamArgs.PeakDb, m_maxDb);
|
const double db = qBound(m_minDb, outputVolumeStreamArgs.PeakDb, m_maxDb);
|
||||||
double ratio = (db - m_minDb) / (m_maxDb - m_minDb);
|
double ratio = (db - m_minDb) / (m_maxDb - m_minDb);
|
||||||
if (ratio < 0.30) { ratio = 0.0; }
|
if (ratio < 0.30) { ratio = 0.0; }
|
||||||
if (ratio > 1.0) { ratio = 1.0; }
|
if (ratio > 1.0) { ratio = 1.0; }
|
||||||
outputVolumeStreamArgs.PeakVU = ratio;
|
outputVolumeStreamArgs.PeakVU = ratio;
|
||||||
emit outputVolumeStream(outputVolumeStreamArgs);
|
emit outputVolumeStream(outputVolumeStreamArgs);
|
||||||
m_sampleCount = 0;
|
m_sampleCount = 0;
|
||||||
m_maxSampleOutput = 0;
|
m_maxSampleOutput = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +84,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
COutput::COutput(QObject *parent) : QObject(parent)
|
COutput::COutput(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
this->setObjectName("COutput");
|
this->setObjectName(classNameShort(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
void COutput::start(const CAudioDeviceInfo &outputDevice, ISampleProvider *sampleProvider)
|
void COutput::start(const CAudioDeviceInfo &outputDevice, ISampleProvider *sampleProvider)
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include "receiversampleprovider.h"
|
#include "receiversampleprovider.h"
|
||||||
#include "blackmisc/logmessage.h"
|
#include "blackmisc/logmessage.h"
|
||||||
|
#include "blackmisc/metadatautils.h"
|
||||||
#include "blacksound/sampleprovider/resourcesoundsampleprovider.h"
|
#include "blacksound/sampleprovider/resourcesoundsampleprovider.h"
|
||||||
#include "blacksound/sampleprovider/samples.h"
|
#include "blacksound/sampleprovider/samples.h"
|
||||||
|
|
||||||
@@ -36,11 +37,13 @@ namespace BlackCore
|
|||||||
ISampleProvider(parent),
|
ISampleProvider(parent),
|
||||||
m_id(id)
|
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++)
|
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_voiceInputs.push_back(voiceInput);
|
||||||
m_mixer->addMixerInput(voiceInput);
|
m_mixer->addMixerInput(voiceInput);
|
||||||
}
|
}
|
||||||
@@ -52,7 +55,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
void CReceiverSampleProvider::setBypassEffects(bool value)
|
void CReceiverSampleProvider::setBypassEffects(bool value)
|
||||||
{
|
{
|
||||||
for (CallsignSampleProvider *voiceInput : m_voiceInputs)
|
for (CCallsignSampleProvider *voiceInput : m_voiceInputs)
|
||||||
{
|
{
|
||||||
voiceInput->setBypassEffects(value);
|
voiceInput->setBypassEffects(value);
|
||||||
}
|
}
|
||||||
@@ -62,7 +65,7 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
if (frequencyHz != m_frequencyHz)
|
if (frequencyHz != m_frequencyHz)
|
||||||
{
|
{
|
||||||
for (CallsignSampleProvider *voiceInput : m_voiceInputs)
|
for (CCallsignSampleProvider *voiceInput : m_voiceInputs)
|
||||||
{
|
{
|
||||||
voiceInput->clear();
|
voiceInput->clear();
|
||||||
}
|
}
|
||||||
@@ -72,7 +75,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
int CReceiverSampleProvider::activeCallsigns() const
|
int CReceiverSampleProvider::activeCallsigns() const
|
||||||
{
|
{
|
||||||
const int numberOfCallsigns = static_cast<int>(std::count_if(m_voiceInputs.begin(), m_voiceInputs.end(), [](const CallsignSampleProvider * p)
|
const int numberOfCallsigns = static_cast<int>(std::count_if(m_voiceInputs.begin(), m_voiceInputs.end(), [](const CCallsignSampleProvider * p)
|
||||||
{
|
{
|
||||||
return p->inUse() == true;
|
return p->inUse() == true;
|
||||||
}));
|
}));
|
||||||
@@ -84,7 +87,7 @@ namespace BlackCore
|
|||||||
m_mute = value;
|
m_mute = value;
|
||||||
if (value)
|
if (value)
|
||||||
{
|
{
|
||||||
for (CallsignSampleProvider *voiceInput : m_voiceInputs)
|
for (CCallsignSampleProvider *voiceInput : m_voiceInputs)
|
||||||
{
|
{
|
||||||
voiceInput->clear();
|
voiceInput->clear();
|
||||||
}
|
}
|
||||||
@@ -108,14 +111,14 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
CResourceSoundSampleProvider *resourceSound = new CResourceSoundSampleProvider(Samples::instance().click(), m_mixer);
|
CResourceSoundSampleProvider *resourceSound = new CResourceSoundSampleProvider(Samples::instance().click(), m_mixer);
|
||||||
m_mixer->addMixerInput(resourceSound);
|
m_mixer->addMixerInput(resourceSound);
|
||||||
// CLogMessage(this).debug(u"AFV Click...");
|
|
||||||
m_doClickWhenAppropriate = false;
|
m_doClickWhenAppropriate = false;
|
||||||
|
// CLogMessage(this).debug(u"AFV Click...");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numberOfInUseInputs != m_lastNumberOfInUseInputs)
|
if (numberOfInUseInputs != m_lastNumberOfInUseInputs)
|
||||||
{
|
{
|
||||||
QStringList receivingCallsigns;
|
QStringList receivingCallsigns;
|
||||||
for (const CallsignSampleProvider *voiceInput : m_voiceInputs)
|
for (const CCallsignSampleProvider *voiceInput : m_voiceInputs)
|
||||||
{
|
{
|
||||||
const QString callsign = voiceInput->callsign();
|
const QString callsign = voiceInput->callsign();
|
||||||
if (! callsign.isEmpty())
|
if (! callsign.isEmpty())
|
||||||
@@ -136,9 +139,9 @@ namespace BlackCore
|
|||||||
void CReceiverSampleProvider::addOpusSamples(const IAudioDto &audioDto, uint frequency, float distanceRatio)
|
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
|
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;
|
return p->callsign() == audioDto.callsign;
|
||||||
});
|
});
|
||||||
@@ -150,7 +153,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
if (! voiceInput)
|
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())
|
if (it != m_voiceInputs.end())
|
||||||
{
|
{
|
||||||
voiceInput = *it;
|
voiceInput = *it;
|
||||||
@@ -173,8 +176,8 @@ namespace BlackCore
|
|||||||
Q_UNUSED(distanceRatio)
|
Q_UNUSED(distanceRatio)
|
||||||
if (m_frequencyHz != frequency) { return; } // Lag in the backend means we get the tail end of a transmission
|
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;
|
return p->callsign() == audioDto.callsign;
|
||||||
});
|
});
|
||||||
@@ -186,7 +189,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
if (!voiceInput)
|
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())
|
if (it != m_voiceInputs.end())
|
||||||
{
|
{
|
||||||
voiceInput = *it;
|
voiceInput = *it;
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ namespace BlackCore
|
|||||||
BlackSound::SampleProvider::CVolumeSampleProvider *m_volume = nullptr;
|
BlackSound::SampleProvider::CVolumeSampleProvider *m_volume = nullptr;
|
||||||
BlackSound::SampleProvider::CMixingSampleProvider *m_mixer = nullptr;
|
BlackSound::SampleProvider::CMixingSampleProvider *m_mixer = nullptr;
|
||||||
BlackSound::SampleProvider::CSinusGenerator *m_blockTone = nullptr;
|
BlackSound::SampleProvider::CSinusGenerator *m_blockTone = nullptr;
|
||||||
QVector<CallsignSampleProvider *> m_voiceInputs;
|
QVector<CCallsignSampleProvider *> m_voiceInputs;
|
||||||
|
|
||||||
QString m_receivingCallsignsString;
|
QString m_receivingCallsignsString;
|
||||||
BlackMisc::Aviation::CCallsignSet m_receivingCallsigns;
|
BlackMisc::Aviation::CCallsignSet m_receivingCallsigns;
|
||||||
|
|||||||
@@ -6,10 +6,10 @@
|
|||||||
* or distributed except according to the terms contained in the LICENSE file.
|
* or distributed except according to the terms contained in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//! \file
|
|
||||||
|
|
||||||
#include "soundcardsampleprovider.h"
|
#include "soundcardsampleprovider.h"
|
||||||
|
#include "blackmisc/metadatautils.h"
|
||||||
|
|
||||||
|
using namespace BlackMisc;
|
||||||
using namespace BlackSound::SampleProvider;
|
using namespace BlackSound::SampleProvider;
|
||||||
|
|
||||||
namespace BlackCore
|
namespace BlackCore
|
||||||
@@ -22,6 +22,9 @@ namespace BlackCore
|
|||||||
ISampleProvider(parent),
|
ISampleProvider(parent),
|
||||||
m_mixer(new CMixingSampleProvider())
|
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.setSampleRate(sampleRate);
|
||||||
m_waveFormat.setChannelCount(1);
|
m_waveFormat.setChannelCount(1);
|
||||||
m_waveFormat.setSampleSize(16);
|
m_waveFormat.setSampleSize(16);
|
||||||
@@ -32,9 +35,10 @@ namespace BlackCore
|
|||||||
m_mixer = new CMixingSampleProvider(this);
|
m_mixer = new CMixingSampleProvider(this);
|
||||||
m_receiverIDs = transceiverIDs;
|
m_receiverIDs = transceiverIDs;
|
||||||
|
|
||||||
|
constexpr int voiceInputNumber = 4; // number of CallsignSampleProviders
|
||||||
for (quint16 transceiverID : transceiverIDs)
|
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);
|
connect(transceiverInput, &CReceiverSampleProvider::receivingCallsignsChanged, this, &CSoundcardSampleProvider::receivingCallsignsChanged);
|
||||||
m_receiverInputs.push_back(transceiverInput);
|
m_receiverInputs.push_back(transceiverInput);
|
||||||
m_receiverIDs.push_back(transceiverID);
|
m_receiverIDs.push_back(transceiverID);
|
||||||
@@ -111,7 +115,7 @@ namespace BlackCore
|
|||||||
QVector<quint16> handledTransceiverIDs;
|
QVector<quint16> handledTransceiverIDs;
|
||||||
for (int i = 0; i < rxTransceiversFilteredAndSorted.size(); i++)
|
for (int i = 0; i < rxTransceiversFilteredAndSorted.size(); i++)
|
||||||
{
|
{
|
||||||
RxTransceiverDto rxTransceiver = rxTransceiversFilteredAndSorted[i];
|
const RxTransceiverDto rxTransceiver = rxTransceiversFilteredAndSorted[i];
|
||||||
if (!handledTransceiverIDs.contains(rxTransceiver.id))
|
if (!handledTransceiverIDs.contains(rxTransceiver.id))
|
||||||
{
|
{
|
||||||
handledTransceiverIDs.push_back(rxTransceiver.id);
|
handledTransceiverIDs.push_back(rxTransceiver.id);
|
||||||
@@ -121,12 +125,13 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
return p->getId() == rxTransceiver.id;
|
return p->getId() == rxTransceiver.id;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (it != m_receiverInputs.end())
|
if (it != m_receiverInputs.end())
|
||||||
{
|
{
|
||||||
receiverInput = *it;
|
receiverInput = *it;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! receiverInput) { continue; }
|
if (!receiverInput) { continue; }
|
||||||
if (receiverInput->getMute()) { continue; }
|
if (receiverInput->getMute()) { continue; }
|
||||||
|
|
||||||
if (!audioPlayed)
|
if (!audioPlayed)
|
||||||
@@ -160,9 +165,9 @@ namespace BlackCore
|
|||||||
|
|
||||||
for (CReceiverSampleProvider *receiverInput : m_receiverInputs)
|
for (CReceiverSampleProvider *receiverInput : m_receiverInputs)
|
||||||
{
|
{
|
||||||
quint16 transceiverID = receiverInput->getId();
|
const quint16 transceiverID = receiverInput->getId();
|
||||||
bool contains = std::any_of(radioTransceivers.begin(), radioTransceivers.end(), [&](const auto & tx) { return transceiverID == tx.id; });
|
const bool contains = std::any_of(radioTransceivers.cbegin(), radioTransceivers.cend(), [ transceiverID ](const auto &tx) { return transceiverID == tx.id; });
|
||||||
if (! contains)
|
if (!contains)
|
||||||
{
|
{
|
||||||
receiverInput->setFrequency(0);
|
receiverInput->setFrequency(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
#include "cryptodtoserializer.h"
|
#include "cryptodtoserializer.h"
|
||||||
|
|
||||||
|
|
||||||
namespace BlackCore
|
namespace BlackCore
|
||||||
{
|
{
|
||||||
namespace Afv
|
namespace Afv
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ namespace BlackCore
|
|||||||
info.m_index = index;
|
info.m_index = index;
|
||||||
++index;
|
++index;
|
||||||
info.m_function = function;
|
info.m_function = function;
|
||||||
info.m_action = action;
|
info.m_action = action;
|
||||||
info.m_receiver = receiver;
|
info.m_receiver = receiver;
|
||||||
m_boundActions.push_back(info);
|
m_boundActions.push_back(info);
|
||||||
return info.m_index;
|
return info.m_index;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "bufferedwaveprovider.h"
|
#include "bufferedwaveprovider.h"
|
||||||
|
#include "blacksound/audioutilities.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
@@ -9,6 +10,9 @@ namespace BlackSound
|
|||||||
CBufferedWaveProvider::CBufferedWaveProvider(const QAudioFormat &format, QObject *parent) :
|
CBufferedWaveProvider::CBufferedWaveProvider(const QAudioFormat &format, QObject *parent) :
|
||||||
ISampleProvider(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
|
// Set buffer size to 10 secs
|
||||||
m_maxBufferSize = format.bytesForDuration(10 * 1000 * 1000);
|
m_maxBufferSize = format.bytesForDuration(10 * 1000 * 1000);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,13 +11,17 @@ namespace BlackSound
|
|||||||
CEqualizerSampleProvider::CEqualizerSampleProvider(ISampleProvider *sourceProvider, EqualizerPresets preset, QObject *parent) :
|
CEqualizerSampleProvider::CEqualizerSampleProvider(ISampleProvider *sourceProvider, EqualizerPresets preset, QObject *parent) :
|
||||||
ISampleProvider(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;
|
m_sourceProvider = sourceProvider;
|
||||||
setupPreset(preset);
|
setupPreset(preset);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CEqualizerSampleProvider::readSamples(QVector<float> &samples, qint64 count)
|
int CEqualizerSampleProvider::readSamples(QVector<float> &samples, qint64 count)
|
||||||
{
|
{
|
||||||
int samplesRead = m_sourceProvider->readSamples(samples, count);
|
const int samplesRead = m_sourceProvider->readSamples(samples, count);
|
||||||
if (m_bypass) return samplesRead;
|
if (m_bypass) return samplesRead;
|
||||||
|
|
||||||
for (int n = 0; n < samplesRead; n++)
|
for (int n = 0; n < samplesRead; n++)
|
||||||
@@ -26,7 +30,7 @@ namespace BlackSound
|
|||||||
{
|
{
|
||||||
samples[n] = m_filters[band].transform(samples[n]);
|
samples[n] = m_filters[band].transform(samples[n]);
|
||||||
}
|
}
|
||||||
samples[n] *= m_outputGain;
|
samples[n] *= static_cast<float>(m_outputGain);
|
||||||
}
|
}
|
||||||
return samplesRead;
|
return samplesRead;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,29 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "mixingsampleprovider.h"
|
#include "mixingsampleprovider.h"
|
||||||
|
#include "blackmisc/metadatautils.h"
|
||||||
|
|
||||||
|
using namespace BlackMisc;
|
||||||
|
|
||||||
namespace BlackSound
|
namespace BlackSound
|
||||||
{
|
{
|
||||||
namespace SampleProvider
|
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<float> &samples, qint64 count)
|
int CMixingSampleProvider::readSamples(QVector<float> &samples, qint64 count)
|
||||||
{
|
{
|
||||||
samples.clear();
|
samples.clear();
|
||||||
@@ -23,15 +41,14 @@ namespace BlackSound
|
|||||||
{
|
{
|
||||||
ISampleProvider *sampleProvider = m_sources.at(i);
|
ISampleProvider *sampleProvider = m_sources.at(i);
|
||||||
QVector<float> sourceBuffer;
|
QVector<float> sourceBuffer;
|
||||||
int len = sampleProvider->readSamples(sourceBuffer, count);
|
|
||||||
|
|
||||||
|
const int len = sampleProvider->readSamples(sourceBuffer, count);
|
||||||
for (int n = 0; n < len; n++)
|
for (int n = 0; n < len; n++)
|
||||||
{
|
{
|
||||||
samples[n] += sourceBuffer[n];
|
samples[n] += sourceBuffer[n];
|
||||||
}
|
}
|
||||||
|
|
||||||
outputLen = qMax(len, outputLen);
|
outputLen = qMax(len, outputLen);
|
||||||
|
|
||||||
if (sampleProvider->isFinished())
|
if (sampleProvider->isFinished())
|
||||||
{
|
{
|
||||||
finishedProviders.push_back(sampleProvider);
|
finishedProviders.push_back(sampleProvider);
|
||||||
|
|||||||
@@ -25,10 +25,10 @@ namespace BlackSound
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//! Ctor mixing provider
|
//! Ctor mixing provider
|
||||||
CMixingSampleProvider(QObject *parent = nullptr) : ISampleProvider(parent) {}
|
CMixingSampleProvider(QObject *parent = nullptr);
|
||||||
|
|
||||||
//! Add a provider
|
//! Add a provider
|
||||||
void addMixerInput(ISampleProvider *provider) { m_sources.append(provider); }
|
void addMixerInput(ISampleProvider *provider);
|
||||||
|
|
||||||
//! \copydoc ISampleProvider::readSamples
|
//! \copydoc ISampleProvider::readSamples
|
||||||
virtual int readSamples(QVector<float> &samples, qint64 count) override;
|
virtual int readSamples(QVector<float> &samples, qint64 count) override;
|
||||||
|
|||||||
@@ -54,6 +54,12 @@ namespace BlackSound
|
|||||||
return true;
|
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
|
bool CResourceSound::isSameFileName(const QString &fn) const
|
||||||
{
|
{
|
||||||
if (fn.isEmpty()) { return false; }
|
if (fn.isEmpty()) { return false; }
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ namespace BlackSound
|
|||||||
const QVector<float> &audioData() const { return m_data->samples; }
|
const QVector<float> &audioData() const { return m_data->samples; }
|
||||||
|
|
||||||
//! Corresponding file
|
//! Corresponding file
|
||||||
const QString &getFileName() { return m_data->fileName; }
|
const QString &getFileName() const;
|
||||||
|
|
||||||
//! Is same file?
|
//! Is same file?
|
||||||
bool isSameFileName(const QString &fn) const;
|
bool isSameFileName(const QString &fn) const;
|
||||||
|
|||||||
@@ -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 "resourcesoundsampleprovider.h"
|
#include "blackmisc/metadatautils.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
using namespace BlackMisc;
|
||||||
|
|
||||||
namespace BlackSound
|
namespace BlackSound
|
||||||
{
|
{
|
||||||
namespace SampleProvider
|
namespace SampleProvider
|
||||||
@@ -10,21 +21,21 @@ namespace BlackSound
|
|||||||
ISampleProvider(parent),
|
ISampleProvider(parent),
|
||||||
m_resourceSound(resourceSound)
|
m_resourceSound(resourceSound)
|
||||||
{
|
{
|
||||||
|
const QString on = QStringLiteral("%1 %2").arg(classNameShort(this), resourceSound.getFileName());
|
||||||
|
this->setObjectName(on);
|
||||||
m_tempBuffer.resize(m_tempBufferSize);
|
m_tempBuffer.resize(m_tempBufferSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CResourceSoundSampleProvider::readSamples(QVector<float> &samples, qint64 count)
|
int CResourceSoundSampleProvider::readSamples(QVector<float> &samples, qint64 count)
|
||||||
{
|
{
|
||||||
if (! m_resourceSound.isLoaded()) { return 0; }
|
if (!m_resourceSound.isLoaded()) { return 0; }
|
||||||
|
|
||||||
if (count > m_tempBufferSize)
|
if (count > m_tempBufferSize)
|
||||||
{
|
{
|
||||||
qDebug() << "Count too large for temp buffer" << count;
|
qDebug() << "Count too large for temp buffer" << count;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
qint64 availableSamples = m_resourceSound.audioData().size() - m_position;
|
const qint64 availableSamples = m_resourceSound.audioData().size() - m_position;
|
||||||
|
const qint64 samplesToCopy = qMin(availableSamples, count);
|
||||||
const qint64 samplesToCopy = qMin(availableSamples, count);
|
|
||||||
samples.clear();
|
samples.clear();
|
||||||
samples.fill(0, static_cast<int>(samplesToCopy));
|
samples.fill(0, static_cast<int>(samplesToCopy));
|
||||||
|
|
||||||
@@ -37,7 +48,7 @@ namespace BlackSound
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < samplesToCopy; i++)
|
for (int i = 0; i < samplesToCopy; i++)
|
||||||
{
|
{
|
||||||
m_tempBuffer[i] *= m_gain;
|
m_tempBuffer[i] = static_cast<float>(m_gain * m_tempBuffer[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,16 +7,22 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "sinusgenerator.h"
|
#include "sinusgenerator.h"
|
||||||
|
#include "blackmisc/metadatautils.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
using namespace BlackMisc;
|
||||||
|
|
||||||
namespace BlackSound
|
namespace BlackSound
|
||||||
{
|
{
|
||||||
namespace SampleProvider
|
namespace SampleProvider
|
||||||
{
|
{
|
||||||
CSinusGenerator::CSinusGenerator(double frequency, QObject *parent) :
|
CSinusGenerator::CSinusGenerator(double frequencyHz, QObject *parent) :
|
||||||
ISampleProvider(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<float> &samples, qint64 count)
|
int CSinusGenerator::readSamples(QVector<float> &samples, qint64 count)
|
||||||
{
|
{
|
||||||
@@ -25,17 +31,17 @@ namespace BlackSound
|
|||||||
|
|
||||||
for (int sampleCount = 0; sampleCount < count; sampleCount++)
|
for (int sampleCount = 0; sampleCount < count; sampleCount++)
|
||||||
{
|
{
|
||||||
double multiple = m_twoPi * m_frequency / m_sampleRate;
|
const double multiple = s_twoPi * m_frequencyHz / m_sampleRate;
|
||||||
double sampleValue = m_gain * qSin(m_nSample * multiple);
|
const double sampleValue = m_gain * qSin(m_nSample * multiple);
|
||||||
samples[sampleCount] = static_cast<float>(sampleValue);
|
samples[sampleCount] = static_cast<float>(sampleValue);
|
||||||
m_nSample++;
|
m_nSample++;
|
||||||
}
|
}
|
||||||
return static_cast<int>(count);
|
return static_cast<int>(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSinusGenerator::setFrequency(double frequency)
|
void CSinusGenerator::setFrequency(double frequencyHz)
|
||||||
{
|
{
|
||||||
m_frequency = frequency;
|
m_frequencyHz = frequencyHz;
|
||||||
}
|
}
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace BlackSound
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
//! Ctor
|
//! Ctor
|
||||||
CSinusGenerator(double frequency, QObject *parent = nullptr);
|
CSinusGenerator(double frequencyHz, QObject *parent = nullptr);
|
||||||
|
|
||||||
//! \copydoc ISampleProvider::readSamples
|
//! \copydoc ISampleProvider::readSamples
|
||||||
virtual int readSamples(QVector<float> &samples, qint64 count) override;
|
virtual int readSamples(QVector<float> &samples, qint64 count) override;
|
||||||
@@ -36,14 +36,14 @@ namespace BlackSound
|
|||||||
void setGain(double gain) { m_gain = gain; }
|
void setGain(double gain) { m_gain = gain; }
|
||||||
|
|
||||||
//! Set frequency in Hz
|
//! Set frequency in Hz
|
||||||
void setFrequency(double frequency);
|
void setFrequency(double frequencyHz);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
double m_gain = 0.0;
|
double m_gain = 0.0;
|
||||||
double m_frequency = 0.0;
|
double m_frequencyHz = 0.0;
|
||||||
double m_sampleRate = 48000;
|
double m_sampleRate = 48000;
|
||||||
int m_nSample = 0;
|
int m_nSample = 0;
|
||||||
const double m_twoPi = 2 * M_PI;
|
static constexpr double s_twoPi = 2 * M_PI;
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -9,7 +9,9 @@
|
|||||||
//! \file
|
//! \file
|
||||||
|
|
||||||
#include "volumesampleprovider.h"
|
#include "volumesampleprovider.h"
|
||||||
#include "volumesampleprovider.h"
|
#include "blackmisc/metadatautils.h"
|
||||||
|
|
||||||
|
using namespace BlackMisc;
|
||||||
|
|
||||||
namespace BlackSound
|
namespace BlackSound
|
||||||
{
|
{
|
||||||
@@ -18,17 +20,20 @@ namespace BlackSound
|
|||||||
CVolumeSampleProvider::CVolumeSampleProvider(ISampleProvider *sourceProvider, QObject *parent) :
|
CVolumeSampleProvider::CVolumeSampleProvider(ISampleProvider *sourceProvider, QObject *parent) :
|
||||||
ISampleProvider(parent),
|
ISampleProvider(parent),
|
||||||
m_sourceProvider(sourceProvider)
|
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<float> &samples, qint64 count)
|
int CVolumeSampleProvider::readSamples(QVector<float> &samples, qint64 count)
|
||||||
{
|
{
|
||||||
int samplesRead = m_sourceProvider->readSamples(samples, count);
|
const int samplesRead = m_sourceProvider->readSamples(samples, count);
|
||||||
|
|
||||||
if (!qFuzzyCompare(m_volume, 1.0))
|
if (!qFuzzyCompare(m_volume, 1.0))
|
||||||
{
|
{
|
||||||
for (int n = 0; n < samplesRead; n++)
|
for (int n = 0; n < samplesRead; n++)
|
||||||
{
|
{
|
||||||
samples[n] *= static_cast<float>(m_volume);
|
samples[n] = static_cast<float>(m_volume * samples[n]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return samplesRead;
|
return samplesRead;
|
||||||
|
|||||||
Reference in New Issue
Block a user