9 using namespace swift::config;
11 using namespace swift::sound::sample_provider;
13 namespace swift::core::afv::audio
15 CSoundcardSampleProvider::CSoundcardSampleProvider(
int sampleRate,
const QVector<quint16> &transceiverIDs,
19 const QString on = QStringLiteral(
"%1 sample rate: %2, transceivers: %3")
22 .arg(transceiverIDs.size());
23 this->setObjectName(on);
25 m_waveFormat.setSampleRate(sampleRate);
26 m_waveFormat.setChannelCount(1);
27 m_waveFormat.setSampleFormat(QAudioFormat::Int16);
28 static_assert(Q_BYTE_ORDER == Q_LITTLE_ENDIAN);
31 m_receiverIDs = transceiverIDs;
33 constexpr
int voiceInputNumber = 4;
34 for (quint16 transceiverID : transceiverIDs)
40 m_receiverInputs.push_back(transceiverInput);
41 m_receiverIDs.push_back(transceiverID);
50 receiverInput->setBypassEffects(value);
58 if (!txTransceivers.isEmpty())
60 QVector<TxTransceiverDto> txTransceiversFiltered = txTransceivers;
62 txTransceiversFiltered.erase(
63 std::remove_if(txTransceiversFiltered.begin(), txTransceiversFiltered.end(),
64 [
this](
const TxTransceiverDto &d) { return !m_receiverIDs.contains(d.id); }),
65 txTransceiversFiltered.end());
69 auto it = std::find_if(
70 m_receiverInputs.begin(), m_receiverInputs.end(),
73 if (it != m_receiverInputs.end()) { (*it)->setMute(
true); }
81 receiverInput->setMute(
false);
92 const QVector<RxTransceiverDto> &rxTransceivers)
94 QVector<RxTransceiverDto> rxTransceiversFilteredAndSorted = rxTransceivers;
96 rxTransceiversFilteredAndSorted.erase(
97 std::remove_if(rxTransceiversFilteredAndSorted.begin(), rxTransceiversFilteredAndSorted.end(),
98 [
this](
const RxTransceiverDto &r) { return !m_receiverIDs.contains(r.id); }),
99 rxTransceiversFilteredAndSorted.end());
101 std::sort(rxTransceiversFilteredAndSorted.begin(), rxTransceiversFilteredAndSorted.end(),
103 return a.distanceRatio > b.distanceRatio;
106 if (!rxTransceiversFilteredAndSorted.isEmpty())
108 bool audioPlayed =
false;
109 QVector<quint16> handledTransceiverIDs;
110 for (
int i = 0; i < rxTransceiversFilteredAndSorted.size(); i++)
113 if (!handledTransceiverIDs.contains(rxTransceiver.
id))
115 handledTransceiverIDs.push_back(rxTransceiver.
id);
118 auto it = std::find_if(
119 m_receiverInputs.begin(), m_receiverInputs.end(),
122 if (it != m_receiverInputs.end()) { receiverInput = *it; }
124 if (!receiverInput) {
continue; }
125 if (receiverInput->
getMute()) {
continue; }
138 if (CBuildConfig::isLocalDeveloperDebugBuild())
140 receiverInput->logVoiceInputs(QStringLiteral(
"Transceiver %1 ").arg(rxTransceiver.
id), 1500);
151 auto it = std::find_if(
152 m_receiverInputs.begin(), m_receiverInputs.end(),
155 if (it != m_receiverInputs.end()) { (*it)->setFrequency(radioTransceiver.frequencyHz); }
160 const quint16 transceiverID = receiverInput->getId();
161 const bool contains = std::any_of(radioTransceivers.cbegin(), radioTransceivers.cend(),
162 [transceiverID](
const auto &tx) { return transceiverID == tx.id; });
163 if (!contains) { receiverInput->setFrequency(0); }
169 return m_receiverInputs.at(transceiverID)->getReceivingCallsignsString();
174 auto receiverInput = std::find_if(m_receiverInputs.begin(), m_receiverInputs.end(),
175 [&](
const auto receiver) { return receiver->getId() == transceiverID; });
176 if (receiverInput == m_receiverInputs.end()) {
return false; }
177 return (*receiverInput)->setGainRatio(gainRatio);
182 return m_receiverInputs.at(transceiverID)->getReceivingCallsigns();
void addSilentSamples(const IAudioDto &audioDto, uint frequency, float distanceRatio)
Add samples.
void receivingCallsignsChanged(const TransceiverReceivingCallsignsChangedArgs &args)
Receving callsigns have changed.
bool getMute() const
Mute.
void addOpusSamples(const IAudioDto &audioDto, uint frequency, float distanceRatio)
Add samples.
int readSamples(QVector< float > &samples, qint64 count)
Read samples.
bool setGainRatioForTransceiver(quint16 transceiverID, double gainRatio)
Setting gain for specified receiver.
void setBypassEffects(bool value)
Bypass effects.
swift::misc::aviation::CCallsignSet getReceivingCallsigns(quint16 transceiverID) const
Receiving callsign as single string.
void receivingCallsignsChanged(const TransceiverReceivingCallsignsChangedArgs &args)
Changed callsigns.
void updateRadioTransceivers(const QVector< TransceiverDto > &radioTransceivers)
Update all tranceivers.
QString getReceivingCallsignsString(quint16 transceiverID) const
Receiving callsign as single string.
void pttUpdate(bool active, const QVector< TxTransceiverDto > &txTransceivers)
Update PTT.
void addOpusSamples(const IAudioDto &audioDto, const QVector< RxTransceiverDto > &rxTransceivers)
Add OPUS samples.
Value object for a set of callsigns.
virtual int readSamples(QVector< float > &samples, qint64 count)
Read samples.
void addMixerInput(ISampleProvider *provider)
Add a provider.
Sample provider interface.
Free functions in swift::misc.
QString classNameShort(const QObject *object)
Class name as from QMetaObject::className without namespace.
float distanceRatio
Properties.
uint32_t frequency
Properties.
Transmit transceiver DTO.