mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 02:35:33 +08:00
AFV initial commit
This commit is contained in:
committed by
Mat Sutcliffe
parent
7030302e73
commit
b5a2f2ad13
189
src/blackcore/afv/audio/receiversampleprovider.cpp
Normal file
189
src/blackcore/afv/audio/receiversampleprovider.cpp
Normal file
@@ -0,0 +1,189 @@
|
||||
#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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
voiceInput->setBypassEffects(value);
|
||||
}
|
||||
}
|
||||
|
||||
void ReceiverSampleProvider::setFrequency(const uint &frequency)
|
||||
{
|
||||
if (frequency != m_frequency)
|
||||
{
|
||||
for (CallsignSampleProvider *voiceInput : m_voiceInputs)
|
||||
{
|
||||
voiceInput->clear();
|
||||
}
|
||||
}
|
||||
m_frequency = frequency;
|
||||
}
|
||||
|
||||
int ReceiverSampleProvider::activeCallsigns() const
|
||||
{
|
||||
int numberOfCallsigns = std::count_if(m_voiceInputs.begin(), m_voiceInputs.end(), [] (const CallsignSampleProvider *p)
|
||||
{
|
||||
return p->inUse() == true;
|
||||
});
|
||||
return numberOfCallsigns;
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
// 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 (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;
|
||||
|
||||
// return volume.Read(buffer, offset, 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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
quint16 ReceiverSampleProvider::getId() const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
Reference in New Issue
Block a user