mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-14 16:55:36 +08:00
[AFV] Apply BiQuadFilters on float samples
This commit is contained in:
committed by
Mat Sutcliffe
parent
d757b8977f
commit
574370579d
@@ -26,7 +26,7 @@ namespace BlackSound
|
||||
QVector<qint16> convertFloatBytesTo16BitPCM(const QByteArray input)
|
||||
{
|
||||
Q_UNUSED(input)
|
||||
qFatal("Not implemented");
|
||||
// qFatal("Not implemented");
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -52,4 +52,25 @@ namespace BlackSound
|
||||
}
|
||||
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
|
||||
|
||||
@@ -22,6 +22,8 @@ namespace BlackSound
|
||||
BLACKSOUND_EXPORT QVector<qint16> convertFloatBytesTo16BitPCM(const QByteArray input);
|
||||
BLACKSOUND_EXPORT QVector<qint16> convertFromMonoToStereo(const QVector<qint16> &mono);
|
||||
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
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#include "equalizersampleprovider.h"
|
||||
#include "blacksound/audioutilities.h"
|
||||
#include <QDebug>
|
||||
|
||||
namespace BlackSound
|
||||
{
|
||||
@@ -16,19 +18,20 @@ namespace BlackSound
|
||||
int samplesRead = m_sourceProvider->readSamples(samples, count);
|
||||
if (m_bypass) return samplesRead;
|
||||
|
||||
QVector<double> doubleSamples = convertFromShortToDouble(samples);
|
||||
|
||||
for (int n = 0; n < samplesRead; n++)
|
||||
{
|
||||
// TODO stereo implementation
|
||||
|
||||
for (int band = 0; band < m_filters.size(); band++)
|
||||
{
|
||||
float s = samples[n] / 32768.0f;
|
||||
s = m_filters[band].process(s);
|
||||
samples[n] = s * 32768;
|
||||
doubleSamples[n] = m_filters[band].process(doubleSamples[n]);
|
||||
}
|
||||
|
||||
samples[n] *= m_outputGain;
|
||||
doubleSamples[n] *= m_outputGain;
|
||||
}
|
||||
|
||||
samples = convertFromDoubleToShort(doubleSamples);
|
||||
return samplesRead;
|
||||
}
|
||||
|
||||
@@ -37,11 +40,11 @@ namespace BlackSound
|
||||
switch (preset)
|
||||
{
|
||||
case VHFEmulation:
|
||||
m_filters.push_back(BiQuadFilter(BiQuadFilterType::HighPass, 44100, 310, 0.25f));
|
||||
m_filters.push_back(BiQuadFilter(BiQuadFilterType::Peak, 44100, 450, 0.75f, 17.0f));
|
||||
m_filters.push_back(BiQuadFilter(BiQuadFilterType::Peak, 44100, 1450, 1.0f, 25.0f));
|
||||
m_filters.push_back(BiQuadFilter(BiQuadFilterType::Peak, 44100, 2000, 1.0f, 25.0f));
|
||||
m_filters.push_back(BiQuadFilter(BiQuadFilterType::LowPass, 44100, 2500, 0.25f));
|
||||
m_filters.push_back(BiQuadFilter(BiQuadFilterType::HighPass, 44100, 310, 0.25));
|
||||
m_filters.push_back(BiQuadFilter(BiQuadFilterType::Peak, 44100, 450, 0.75, 17.0));
|
||||
m_filters.push_back(BiQuadFilter(BiQuadFilterType::Peak, 44100, 1450, 1.0, 25.0));
|
||||
m_filters.push_back(BiQuadFilter(BiQuadFilterType::Peak, 44100, 2000, 1.0, 25.0));
|
||||
m_filters.push_back(BiQuadFilter(BiQuadFilterType::LowPass, 44100, 2500, 0.25));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user