mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 02:35:33 +08:00
Ref T730, namespace for BlackCore::Afv
* added namespace * removed some *.pri files and added files to blackcore.pro * added copyright etc.
This commit is contained in:
committed by
Mat Sutcliffe
parent
d064da13b5
commit
384aa3ce19
@@ -1,189 +1,205 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#include "receiversampleprovider.h"
|
||||
#include "blacksound/sampleprovider/resourcesoundsampleprovider.h"
|
||||
#include "blacksound/sampleprovider/samples.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
ReceiverSampleProvider::ReceiverSampleProvider(const QAudioFormat &audioFormat, quint16 id, int voiceInputNumber, QObject *parent) :
|
||||
ISampleProvider(parent),
|
||||
m_id(id)
|
||||
namespace BlackCore
|
||||
{
|
||||
m_mixer = new MixingSampleProvider(this);
|
||||
|
||||
for (int i = 0; i < voiceInputNumber; i++)
|
||||
{
|
||||
auto voiceInput = new CallsignSampleProvider(audioFormat, m_mixer);
|
||||
m_voiceInputs.push_back(voiceInput);
|
||||
m_mixer->addMixerInput(voiceInput);
|
||||
};
|
||||
|
||||
// TODO blockTone = new SignalGenerator(WaveFormat.SampleRate, 1) { Gain = 0, Type = SignalGeneratorType.Sin, Frequency = 180 };
|
||||
// TODO mixer.AddMixerInput(blockTone.ToMono());
|
||||
// TODO volume = new VolumeSampleProvider(mixer);
|
||||
}
|
||||
|
||||
void ReceiverSampleProvider::setBypassEffects(bool value)
|
||||
{
|
||||
for (CallsignSampleProvider *voiceInput : m_voiceInputs)
|
||||
namespace Afv
|
||||
{
|
||||
voiceInput->setBypassEffects(value);
|
||||
}
|
||||
}
|
||||
|
||||
void ReceiverSampleProvider::setFrequency(const uint &frequency)
|
||||
{
|
||||
if (frequency != m_frequency)
|
||||
{
|
||||
for (CallsignSampleProvider *voiceInput : m_voiceInputs)
|
||||
namespace Audio
|
||||
{
|
||||
voiceInput->clear();
|
||||
}
|
||||
}
|
||||
m_frequency = frequency;
|
||||
}
|
||||
ReceiverSampleProvider::ReceiverSampleProvider(const QAudioFormat &audioFormat, quint16 id, int voiceInputNumber, QObject *parent) :
|
||||
ISampleProvider(parent),
|
||||
m_id(id)
|
||||
{
|
||||
m_mixer = new MixingSampleProvider(this);
|
||||
|
||||
int ReceiverSampleProvider::activeCallsigns() const
|
||||
{
|
||||
int numberOfCallsigns = std::count_if(m_voiceInputs.begin(), m_voiceInputs.end(), [] (const CallsignSampleProvider *p)
|
||||
{
|
||||
return p->inUse() == true;
|
||||
});
|
||||
return numberOfCallsigns;
|
||||
}
|
||||
for (int i = 0; i < voiceInputNumber; i++)
|
||||
{
|
||||
auto voiceInput = new CallsignSampleProvider(audioFormat, m_mixer);
|
||||
m_voiceInputs.push_back(voiceInput);
|
||||
m_mixer->addMixerInput(voiceInput);
|
||||
};
|
||||
|
||||
float ReceiverSampleProvider::volume() const
|
||||
{
|
||||
return 1.0;
|
||||
}
|
||||
// TODO blockTone = new SignalGenerator(WaveFormat.SampleRate, 1) { Gain = 0, Type = SignalGeneratorType.Sin, Frequency = 180 };
|
||||
// TODO mixer.AddMixerInput(blockTone.ToMono());
|
||||
// TODO volume = new VolumeSampleProvider(mixer);
|
||||
}
|
||||
|
||||
bool ReceiverSampleProvider::getMute() const
|
||||
{
|
||||
return m_mute;
|
||||
}
|
||||
void ReceiverSampleProvider::setBypassEffects(bool value)
|
||||
{
|
||||
for (CallsignSampleProvider *voiceInput : m_voiceInputs)
|
||||
{
|
||||
voiceInput->setBypassEffects(value);
|
||||
}
|
||||
}
|
||||
|
||||
void ReceiverSampleProvider::setMute(bool value)
|
||||
{
|
||||
m_mute = value;
|
||||
if (value)
|
||||
{
|
||||
for (CallsignSampleProvider *voiceInput : m_voiceInputs)
|
||||
{
|
||||
voiceInput->clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
void ReceiverSampleProvider::setFrequency(const uint &frequency)
|
||||
{
|
||||
if (frequency != m_frequency)
|
||||
{
|
||||
for (CallsignSampleProvider *voiceInput : m_voiceInputs)
|
||||
{
|
||||
voiceInput->clear();
|
||||
}
|
||||
}
|
||||
m_frequency = frequency;
|
||||
}
|
||||
|
||||
int ReceiverSampleProvider::readSamples(QVector<qint16> &samples, qint64 count)
|
||||
{
|
||||
int numberOfInUseInputs = activeCallsigns();
|
||||
int ReceiverSampleProvider::activeCallsigns() const
|
||||
{
|
||||
int numberOfCallsigns = std::count_if(m_voiceInputs.begin(), m_voiceInputs.end(), [](const CallsignSampleProvider * p)
|
||||
{
|
||||
return p->inUse() == true;
|
||||
});
|
||||
return numberOfCallsigns;
|
||||
}
|
||||
|
||||
if (numberOfInUseInputs > 1)
|
||||
{
|
||||
float ReceiverSampleProvider::volume() const
|
||||
{
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
bool ReceiverSampleProvider::getMute() const
|
||||
{
|
||||
return m_mute;
|
||||
}
|
||||
|
||||
void ReceiverSampleProvider::setMute(bool value)
|
||||
{
|
||||
m_mute = value;
|
||||
if (value)
|
||||
{
|
||||
for (CallsignSampleProvider *voiceInput : m_voiceInputs)
|
||||
{
|
||||
voiceInput->clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int ReceiverSampleProvider::readSamples(QVector<qint16> &samples, qint64 count)
|
||||
{
|
||||
int numberOfInUseInputs = activeCallsigns();
|
||||
|
||||
if (numberOfInUseInputs > 1)
|
||||
{
|
||||
// blockTone.Frequency = 180;
|
||||
// blockTone.Gain = blockToneGain;
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
// blockTone.Gain = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_doClickWhenAppropriate && numberOfInUseInputs == 0)
|
||||
{
|
||||
ResourceSoundSampleProvider *resourceSound = new ResourceSoundSampleProvider(Samples::instance().click(), m_mixer);
|
||||
m_mixer->addMixerInput(resourceSound);
|
||||
qDebug() << "Click...";
|
||||
m_doClickWhenAppropriate = false;
|
||||
}
|
||||
if (m_doClickWhenAppropriate && numberOfInUseInputs == 0)
|
||||
{
|
||||
ResourceSoundSampleProvider *resourceSound = new ResourceSoundSampleProvider(Samples::instance().click(), m_mixer);
|
||||
m_mixer->addMixerInput(resourceSound);
|
||||
qDebug() << "Click...";
|
||||
m_doClickWhenAppropriate = false;
|
||||
}
|
||||
|
||||
if (numberOfInUseInputs != lastNumberOfInUseInputs)
|
||||
{
|
||||
QStringList receivingCallsigns;
|
||||
for (const CallsignSampleProvider *voiceInput : m_voiceInputs)
|
||||
{
|
||||
QString callsign = voiceInput->callsign();
|
||||
if (! callsign.isEmpty())
|
||||
{
|
||||
receivingCallsigns.push_back(callsign);
|
||||
}
|
||||
}
|
||||
if (numberOfInUseInputs != lastNumberOfInUseInputs)
|
||||
{
|
||||
QStringList receivingCallsigns;
|
||||
for (const CallsignSampleProvider *voiceInput : m_voiceInputs)
|
||||
{
|
||||
QString callsign = voiceInput->callsign();
|
||||
if (! callsign.isEmpty())
|
||||
{
|
||||
receivingCallsigns.push_back(callsign);
|
||||
}
|
||||
}
|
||||
|
||||
TransceiverReceivingCallsignsChangedArgs args = { m_id, receivingCallsigns };
|
||||
emit receivingCallsignsChanged(args);
|
||||
}
|
||||
lastNumberOfInUseInputs = numberOfInUseInputs;
|
||||
TransceiverReceivingCallsignsChangedArgs args = { m_id, receivingCallsigns };
|
||||
emit receivingCallsignsChanged(args);
|
||||
}
|
||||
lastNumberOfInUseInputs = numberOfInUseInputs;
|
||||
|
||||
// return volume.Read(buffer, offset, count);
|
||||
return m_mixer->readSamples(samples, count);
|
||||
}
|
||||
return m_mixer->readSamples(samples, count);
|
||||
}
|
||||
|
||||
void ReceiverSampleProvider::addOpusSamples(const IAudioDto &audioDto, uint frequency, float distanceRatio)
|
||||
{
|
||||
if (m_frequency != frequency) //Lag in the backend means we get the tail end of a transmission
|
||||
return;
|
||||
void ReceiverSampleProvider::addOpusSamples(const IAudioDto &audioDto, uint frequency, float distanceRatio)
|
||||
{
|
||||
if (m_frequency != frequency) //Lag in the backend means we get the tail end of a transmission
|
||||
return;
|
||||
|
||||
CallsignSampleProvider *voiceInput = nullptr;
|
||||
CallsignSampleProvider *voiceInput = nullptr;
|
||||
|
||||
auto it = std::find_if(m_voiceInputs.begin(), m_voiceInputs.end(), [audioDto] (const CallsignSampleProvider *p)
|
||||
{
|
||||
return p->callsign() == audioDto.callsign;
|
||||
});
|
||||
if (it != m_voiceInputs.end())
|
||||
{
|
||||
voiceInput = *it;
|
||||
}
|
||||
auto it = std::find_if(m_voiceInputs.begin(), m_voiceInputs.end(), [audioDto](const CallsignSampleProvider * p)
|
||||
{
|
||||
return p->callsign() == audioDto.callsign;
|
||||
});
|
||||
if (it != m_voiceInputs.end())
|
||||
{
|
||||
voiceInput = *it;
|
||||
}
|
||||
|
||||
if (! voiceInput)
|
||||
{
|
||||
it = std::find_if(m_voiceInputs.begin(), m_voiceInputs.end(), [] (const CallsignSampleProvider *p) { return p->inUse() == false; });
|
||||
if (it != m_voiceInputs.end())
|
||||
{
|
||||
voiceInput = *it;
|
||||
voiceInput->active(audioDto.callsign, "");
|
||||
}
|
||||
}
|
||||
if (! voiceInput)
|
||||
{
|
||||
it = std::find_if(m_voiceInputs.begin(), m_voiceInputs.end(), [](const CallsignSampleProvider * p) { return p->inUse() == false; });
|
||||
if (it != m_voiceInputs.end())
|
||||
{
|
||||
voiceInput = *it;
|
||||
voiceInput->active(audioDto.callsign, "");
|
||||
}
|
||||
}
|
||||
|
||||
if (voiceInput)
|
||||
{
|
||||
voiceInput->addOpusSamples(audioDto, distanceRatio);
|
||||
}
|
||||
if (voiceInput)
|
||||
{
|
||||
voiceInput->addOpusSamples(audioDto, distanceRatio);
|
||||
}
|
||||
|
||||
m_doClickWhenAppropriate = true;
|
||||
}
|
||||
m_doClickWhenAppropriate = true;
|
||||
}
|
||||
|
||||
void ReceiverSampleProvider::addSilentSamples(const IAudioDto &audioDto, uint frequency, float distanceRatio)
|
||||
{
|
||||
Q_UNUSED(distanceRatio);
|
||||
if (m_frequency != frequency) //Lag in the backend means we get the tail end of a transmission
|
||||
return;
|
||||
void ReceiverSampleProvider::addSilentSamples(const IAudioDto &audioDto, uint frequency, float distanceRatio)
|
||||
{
|
||||
Q_UNUSED(distanceRatio);
|
||||
if (m_frequency != frequency) //Lag in the backend means we get the tail end of a transmission
|
||||
return;
|
||||
|
||||
CallsignSampleProvider *voiceInput = nullptr;
|
||||
CallsignSampleProvider *voiceInput = nullptr;
|
||||
|
||||
auto it = std::find_if(m_voiceInputs.begin(), m_voiceInputs.end(), [audioDto] (const CallsignSampleProvider *p)
|
||||
{
|
||||
return p->callsign() == audioDto.callsign;
|
||||
});
|
||||
if (it != m_voiceInputs.end())
|
||||
{
|
||||
voiceInput = *it;
|
||||
}
|
||||
auto it = std::find_if(m_voiceInputs.begin(), m_voiceInputs.end(), [audioDto](const CallsignSampleProvider * p)
|
||||
{
|
||||
return p->callsign() == audioDto.callsign;
|
||||
});
|
||||
if (it != m_voiceInputs.end())
|
||||
{
|
||||
voiceInput = *it;
|
||||
}
|
||||
|
||||
if (! voiceInput)
|
||||
{
|
||||
it = std::find_if(m_voiceInputs.begin(), m_voiceInputs.end(), [] (const CallsignSampleProvider *p) { return p->inUse() == false; });
|
||||
if (it != m_voiceInputs.end())
|
||||
{
|
||||
voiceInput = *it;
|
||||
voiceInput->active(audioDto.callsign, "");
|
||||
}
|
||||
}
|
||||
if (! voiceInput)
|
||||
{
|
||||
it = std::find_if(m_voiceInputs.begin(), m_voiceInputs.end(), [](const CallsignSampleProvider * p) { return p->inUse() == false; });
|
||||
if (it != m_voiceInputs.end())
|
||||
{
|
||||
voiceInput = *it;
|
||||
voiceInput->active(audioDto.callsign, "");
|
||||
}
|
||||
}
|
||||
|
||||
if (voiceInput)
|
||||
{
|
||||
voiceInput->addSilentSamples(audioDto);
|
||||
}
|
||||
}
|
||||
if (voiceInput)
|
||||
{
|
||||
voiceInput->addSilentSamples(audioDto);
|
||||
}
|
||||
}
|
||||
|
||||
quint16 ReceiverSampleProvider::getId() const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
|
||||
} // ns
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
Reference in New Issue
Block a user