mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-27 02:55:44 +08:00
[AFV] Apply BiQuadFilters on float samples
This commit is contained in:
committed by
Mat Sutcliffe
parent
d757b8977f
commit
574370579d
@@ -180,7 +180,7 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
if (m_receiver->getFrequencyHz() < 30000000)
|
if (m_receiver->getFrequencyHz() < 30000000)
|
||||||
{
|
{
|
||||||
float crackleFactor = (float)(((qExp(m_distanceRatio) * qPow(m_distanceRatio, -4.0)) / 350) - 0.00776652);
|
double crackleFactor = (((qExp(m_distanceRatio) * qPow(m_distanceRatio, -4.0)) / 350.0) - 0.00776652);
|
||||||
|
|
||||||
if (crackleFactor < 0.0f) { crackleFactor = 0.0f; }
|
if (crackleFactor < 0.0f) { crackleFactor = 0.0f; }
|
||||||
if (crackleFactor > 0.20f) { crackleFactor = 0.20f; }
|
if (crackleFactor > 0.20f) { crackleFactor = 0.20f; }
|
||||||
@@ -189,15 +189,15 @@ namespace BlackCore
|
|||||||
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_voiceEq->setBypassEffects(false);
|
||||||
m_voiceEq->setOutputGain(0.38f);
|
m_voiceEq->setOutputGain(0.38);
|
||||||
m_whiteNoise->setGain(0.0);
|
m_whiteNoise->setGain(0.0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
float crackleFactor = (float)(((qExp(m_distanceRatio) * qPow(m_distanceRatio, -4.0)) / 350) - 0.00776652);
|
double crackleFactor = (((qExp(m_distanceRatio) * qPow(m_distanceRatio, -4.0)) / 350.0) - 0.00776652);
|
||||||
|
|
||||||
if (crackleFactor < 0.0f) { crackleFactor = 0.0f; }
|
if (crackleFactor < 0.0) { crackleFactor = 0.0; }
|
||||||
if (crackleFactor > 0.20f) { crackleFactor = 0.20f; }
|
if (crackleFactor > 0.20) { crackleFactor = 0.20; }
|
||||||
|
|
||||||
m_crackleSoundProvider->setGain(crackleFactor * 2);
|
m_crackleSoundProvider->setGain(crackleFactor * 2);
|
||||||
m_whiteNoise->setGain(m_whiteNoiseGainMin);
|
m_whiteNoise->setGain(m_whiteNoiseGainMin);
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace BlackSound
|
|||||||
QVector<qint16> convertFloatBytesTo16BitPCM(const QByteArray input)
|
QVector<qint16> convertFloatBytesTo16BitPCM(const QByteArray input)
|
||||||
{
|
{
|
||||||
Q_UNUSED(input)
|
Q_UNUSED(input)
|
||||||
qFatal("Not implemented");
|
// qFatal("Not implemented");
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,4 +52,25 @@ namespace BlackSound
|
|||||||
}
|
}
|
||||||
return mono;
|
return mono;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVector<double> convertFromShortToDouble(const QVector<qint16> &input)
|
||||||
|
{
|
||||||
|
QVector<double> output;
|
||||||
|
for (auto sample : input)
|
||||||
|
{
|
||||||
|
output.push_back(sample / 32768.0);
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector<qint16> convertFromDoubleToShort(const QVector<double> &input)
|
||||||
|
{
|
||||||
|
QVector<qint16> output;
|
||||||
|
for (auto sample : input)
|
||||||
|
{
|
||||||
|
output.push_back(sample * 32768);
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ namespace BlackSound
|
|||||||
BLACKSOUND_EXPORT QVector<qint16> convertFloatBytesTo16BitPCM(const QByteArray input);
|
BLACKSOUND_EXPORT QVector<qint16> convertFloatBytesTo16BitPCM(const QByteArray input);
|
||||||
BLACKSOUND_EXPORT QVector<qint16> convertFromMonoToStereo(const QVector<qint16> &mono);
|
BLACKSOUND_EXPORT QVector<qint16> convertFromMonoToStereo(const QVector<qint16> &mono);
|
||||||
BLACKSOUND_EXPORT QVector<qint16> convertFromStereoToMono(const QVector<qint16> &stereo);
|
BLACKSOUND_EXPORT QVector<qint16> convertFromStereoToMono(const QVector<qint16> &stereo);
|
||||||
|
BLACKSOUND_EXPORT QVector<double> convertFromShortToDouble(const QVector<qint16> &input);
|
||||||
|
BLACKSOUND_EXPORT QVector<qint16> convertFromDoubleToShort(const QVector<double> &input);
|
||||||
//! @}
|
//! @}
|
||||||
} // ns
|
} // ns
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
#include "equalizersampleprovider.h"
|
#include "equalizersampleprovider.h"
|
||||||
|
#include "blacksound/audioutilities.h"
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
namespace BlackSound
|
namespace BlackSound
|
||||||
{
|
{
|
||||||
@@ -16,19 +18,20 @@ namespace BlackSound
|
|||||||
int samplesRead = m_sourceProvider->readSamples(samples, count);
|
int samplesRead = m_sourceProvider->readSamples(samples, count);
|
||||||
if (m_bypass) return samplesRead;
|
if (m_bypass) return samplesRead;
|
||||||
|
|
||||||
|
QVector<double> doubleSamples = convertFromShortToDouble(samples);
|
||||||
|
|
||||||
for (int n = 0; n < samplesRead; n++)
|
for (int n = 0; n < samplesRead; n++)
|
||||||
{
|
{
|
||||||
// TODO stereo implementation
|
// TODO stereo implementation
|
||||||
|
|
||||||
for (int band = 0; band < m_filters.size(); band++)
|
for (int band = 0; band < m_filters.size(); band++)
|
||||||
{
|
{
|
||||||
float s = samples[n] / 32768.0f;
|
doubleSamples[n] = m_filters[band].process(doubleSamples[n]);
|
||||||
s = m_filters[band].process(s);
|
|
||||||
samples[n] = s * 32768;
|
|
||||||
}
|
}
|
||||||
|
doubleSamples[n] *= m_outputGain;
|
||||||
samples[n] *= m_outputGain;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
samples = convertFromDoubleToShort(doubleSamples);
|
||||||
return samplesRead;
|
return samplesRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,11 +40,11 @@ namespace BlackSound
|
|||||||
switch (preset)
|
switch (preset)
|
||||||
{
|
{
|
||||||
case VHFEmulation:
|
case VHFEmulation:
|
||||||
m_filters.push_back(BiQuadFilter(BiQuadFilterType::HighPass, 44100, 310, 0.25f));
|
m_filters.push_back(BiQuadFilter(BiQuadFilterType::HighPass, 44100, 310, 0.25));
|
||||||
m_filters.push_back(BiQuadFilter(BiQuadFilterType::Peak, 44100, 450, 0.75f, 17.0f));
|
m_filters.push_back(BiQuadFilter(BiQuadFilterType::Peak, 44100, 450, 0.75, 17.0));
|
||||||
m_filters.push_back(BiQuadFilter(BiQuadFilterType::Peak, 44100, 1450, 1.0f, 25.0f));
|
m_filters.push_back(BiQuadFilter(BiQuadFilterType::Peak, 44100, 1450, 1.0, 25.0));
|
||||||
m_filters.push_back(BiQuadFilter(BiQuadFilterType::Peak, 44100, 2000, 1.0f, 25.0f));
|
m_filters.push_back(BiQuadFilter(BiQuadFilterType::Peak, 44100, 2000, 1.0, 25.0));
|
||||||
m_filters.push_back(BiQuadFilter(BiQuadFilterType::LowPass, 44100, 2500, 0.25f));
|
m_filters.push_back(BiQuadFilter(BiQuadFilterType::LowPass, 44100, 2500, 0.25));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user