mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-05-24 11:12:27 -04:00
SSB Modulator: interim state (2)
This commit is contained in:
parent
e9faec07c5
commit
bcb13d556a
@ -34,8 +34,11 @@ MESSAGE_CLASS_DEFINITION(SSBMod::MsgReportFileSourceStreamData, Message)
|
|||||||
MESSAGE_CLASS_DEFINITION(SSBMod::MsgReportFileSourceStreamTiming, Message)
|
MESSAGE_CLASS_DEFINITION(SSBMod::MsgReportFileSourceStreamTiming, Message)
|
||||||
|
|
||||||
const int SSBMod::m_levelNbSamples = 480; // every 10ms
|
const int SSBMod::m_levelNbSamples = 480; // every 10ms
|
||||||
|
const int SSBMod::m_ssbFftLen = 1024;
|
||||||
|
|
||||||
SSBMod::SSBMod() :
|
SSBMod::SSBMod() :
|
||||||
|
m_SSBFilter(0),
|
||||||
|
m_DSBFilter(0),
|
||||||
m_audioFifo(4, 48000),
|
m_audioFifo(4, 48000),
|
||||||
m_settingsMutex(QMutex::Recursive),
|
m_settingsMutex(QMutex::Recursive),
|
||||||
m_fileSize(0),
|
m_fileSize(0),
|
||||||
@ -70,10 +73,21 @@ SSBMod::SSBMod() :
|
|||||||
m_cwKeyer.setSampleRate(m_config.m_audioSampleRate);
|
m_cwKeyer.setSampleRate(m_config.m_audioSampleRate);
|
||||||
m_cwKeyer.setWPM(13);
|
m_cwKeyer.setWPM(13);
|
||||||
m_cwKeyer.setMode(CWKeyer::CWNone);
|
m_cwKeyer.setMode(CWKeyer::CWNone);
|
||||||
|
|
||||||
|
m_SSBFilter = new fftfilt(m_config.m_lowCutoff / m_config.m_audioSampleRate, m_config.m_bandwidth / m_config.m_audioSampleRate, m_ssbFftLen);
|
||||||
|
m_DSBFilter = new fftfilt((2.0f * m_config.m_bandwidth) / m_config.m_audioSampleRate, 2 * m_ssbFftLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
SSBMod::~SSBMod()
|
SSBMod::~SSBMod()
|
||||||
{
|
{
|
||||||
|
if (m_SSBFilter) {
|
||||||
|
delete m_SSBFilter;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_DSBFilter) {
|
||||||
|
delete m_DSBFilter;
|
||||||
|
}
|
||||||
|
|
||||||
DSPEngine::instance()->removeAudioSource(&m_audioFifo);
|
DSPEngine::instance()->removeAudioSource(&m_audioFifo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,23 +156,23 @@ void SSBMod::pull(Sample& sample)
|
|||||||
|
|
||||||
void SSBMod::modulateSample()
|
void SSBMod::modulateSample()
|
||||||
{
|
{
|
||||||
Real t;
|
Complex c;
|
||||||
|
|
||||||
pullAF(t);
|
pullAF(c);
|
||||||
calculateLevel(t);
|
calculateLevel(c);
|
||||||
|
|
||||||
m_modSample.real(0.0f); // TOOO
|
m_modSample.real(0.0f); // TOOO
|
||||||
m_modSample.imag(0.0f);
|
m_modSample.imag(0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SSBMod::pullAF(Real& sample)
|
void SSBMod::pullAF(Complex& sample)
|
||||||
{
|
{
|
||||||
int16_t audioSample[2];
|
int16_t audioSample[2];
|
||||||
|
|
||||||
switch (m_afInput)
|
switch (m_afInput)
|
||||||
{
|
{
|
||||||
case SSBModInputTone:
|
case SSBModInputTone:
|
||||||
sample = m_toneNco.next();
|
sample = m_toneNco.nextIQ();
|
||||||
break;
|
break;
|
||||||
case SSBModInputFile:
|
case SSBModInputFile:
|
||||||
// sox f4exb_call.wav --encoding float --endian little f4exb_call.raw
|
// sox f4exb_call.wav --encoding float --endian little f4exb_call.raw
|
||||||
@ -176,31 +190,37 @@ void SSBMod::pullAF(Real& sample)
|
|||||||
|
|
||||||
if (m_ifstream.eof())
|
if (m_ifstream.eof())
|
||||||
{
|
{
|
||||||
sample = 0.0f;
|
sample.real() = 0.0f;
|
||||||
|
sample.imag() = 0.0f;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_ifstream.read(reinterpret_cast<char*>(&sample), sizeof(Real));
|
Real real;
|
||||||
sample *= m_running.m_volumeFactor;
|
m_ifstream.read(reinterpret_cast<char*>(&real), sizeof(Real));
|
||||||
|
sample.real() = real * m_running.m_volumeFactor;
|
||||||
|
sample.imag() = 0.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sample = 0.0f;
|
sample.real() = 0.0f;
|
||||||
|
sample.imag() = 0.0f;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SSBModInputAudio:
|
case SSBModInputAudio:
|
||||||
m_audioFifo.read(reinterpret_cast<quint8*>(audioSample), 1, 10);
|
m_audioFifo.read(reinterpret_cast<quint8*>(audioSample), 1, 10);
|
||||||
sample = ((audioSample[0] + audioSample[1]) / 65536.0f) * m_running.m_volumeFactor;
|
sample.real() = ((audioSample[0] + audioSample[1]) / 65536.0f) * m_running.m_volumeFactor;
|
||||||
|
sample.imag() = 0.0f;
|
||||||
break;
|
break;
|
||||||
case SSBModInputCWTone:
|
case SSBModInputCWTone:
|
||||||
if (m_cwKeyer.getSample())
|
if (m_cwKeyer.getSample())
|
||||||
{
|
{
|
||||||
sample = m_toneNco.next();
|
sample = m_toneNco.nextIQ();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sample = 0.0f;
|
sample.real() = 0.0f;
|
||||||
|
sample.imag() = 0.0f;
|
||||||
m_toneNco.setPhase(0);
|
m_toneNco.setPhase(0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -211,12 +231,14 @@ void SSBMod::pullAF(Real& sample)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SSBMod::calculateLevel(Real& sample)
|
void SSBMod::calculateLevel(Complex& sample)
|
||||||
{
|
{
|
||||||
|
Real t = sample.real(); // TODO: possibly adjust depending on sample type
|
||||||
|
|
||||||
if (m_levelCalcCount < m_levelNbSamples)
|
if (m_levelCalcCount < m_levelNbSamples)
|
||||||
{
|
{
|
||||||
m_peakLevel = std::max(std::fabs(m_peakLevel), sample);
|
m_peakLevel = std::max(std::fabs(m_peakLevel), t);
|
||||||
m_levelSum += sample * sample;
|
m_levelSum += t * t;
|
||||||
m_levelCalcCount++;
|
m_levelCalcCount++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -267,7 +289,7 @@ bool SSBMod::handleMessage(const Message& cmd)
|
|||||||
m_settingsMutex.lock();
|
m_settingsMutex.lock();
|
||||||
|
|
||||||
band = cfg.getBandwidth();
|
band = cfg.getBandwidth();
|
||||||
lowCutoff = cfg.getLoCutoff();
|
lowCutoff = cfg.getLowCutoff();
|
||||||
|
|
||||||
if (band < 0) // negative means LSB
|
if (band < 0) // negative means LSB
|
||||||
{
|
{
|
||||||
@ -289,10 +311,6 @@ bool SSBMod::handleMessage(const Message& cmd)
|
|||||||
m_config.m_bandwidth = band;
|
m_config.m_bandwidth = band;
|
||||||
m_config.m_lowCutoff = lowCutoff;
|
m_config.m_lowCutoff = lowCutoff;
|
||||||
|
|
||||||
// TODO: move to apply
|
|
||||||
SSBFilter->create_filter(m_config.m_lowCutoff / (float) m_config.m_audioSampleRate, m_config.m_bandwidth / (float) m_config.m_audioSampleRate);
|
|
||||||
DSBFilter->create_dsb_filter((2.0f * m_config.m_bandwidth) / (float) m_config.m_audioSampleRate);
|
|
||||||
|
|
||||||
m_config.m_toneFrequency = cfg.getToneFrequency();
|
m_config.m_toneFrequency = cfg.getToneFrequency();
|
||||||
m_config.m_volumeFactor = cfg.getVolumeFactor();
|
m_config.m_volumeFactor = cfg.getVolumeFactor();
|
||||||
m_config.m_spanLog2 = cfg.getSpanLog2();
|
m_config.m_spanLog2 = cfg.getSpanLog2();
|
||||||
@ -366,6 +384,13 @@ bool SSBMod::handleMessage(const Message& cmd)
|
|||||||
|
|
||||||
void SSBMod::apply()
|
void SSBMod::apply()
|
||||||
{
|
{
|
||||||
|
if ((m_config.m_bandwidth != m_running.m_bandwidth) ||
|
||||||
|
(m_config.m_lowCutoff != m_running.m_lowCutoff) ||
|
||||||
|
(m_config.m_audioSampleRate != m_running.m_audioSampleRate))
|
||||||
|
{
|
||||||
|
m_SSBFilter->create_filter(m_config.m_lowCutoff / (float) m_config.m_audioSampleRate, m_config.m_bandwidth / (float) m_config.m_audioSampleRate);
|
||||||
|
m_DSBFilter->create_dsb_filter((2.0f * m_config.m_bandwidth) / (float) m_config.m_audioSampleRate);
|
||||||
|
}
|
||||||
|
|
||||||
if ((m_config.m_inputFrequencyOffset != m_running.m_inputFrequencyOffset) ||
|
if ((m_config.m_inputFrequencyOffset != m_running.m_inputFrequencyOffset) ||
|
||||||
(m_config.m_outputSampleRate != m_running.m_outputSampleRate))
|
(m_config.m_outputSampleRate != m_running.m_outputSampleRate))
|
||||||
@ -404,6 +429,7 @@ void SSBMod::apply()
|
|||||||
m_running.m_inputFrequencyOffset = m_config.m_inputFrequencyOffset;
|
m_running.m_inputFrequencyOffset = m_config.m_inputFrequencyOffset;
|
||||||
m_running.m_bandwidth = m_config.m_bandwidth;
|
m_running.m_bandwidth = m_config.m_bandwidth;
|
||||||
m_running.m_lowCutoff = m_config.m_lowCutoff;
|
m_running.m_lowCutoff = m_config.m_lowCutoff;
|
||||||
|
m_running.m_usb = m_config.m_usb;
|
||||||
m_running.m_toneFrequency = m_config.m_toneFrequency;
|
m_running.m_toneFrequency = m_config.m_toneFrequency;
|
||||||
m_running.m_volumeFactor = m_config.m_volumeFactor;
|
m_running.m_volumeFactor = m_config.m_volumeFactor;
|
||||||
m_running.m_audioSampleRate = m_config.m_audioSampleRate;
|
m_running.m_audioSampleRate = m_config.m_audioSampleRate;
|
||||||
|
@ -342,8 +342,9 @@ private:
|
|||||||
Real m_interpolatorDistance;
|
Real m_interpolatorDistance;
|
||||||
Real m_interpolatorDistanceRemain;
|
Real m_interpolatorDistanceRemain;
|
||||||
bool m_interpolatorConsumed;
|
bool m_interpolatorConsumed;
|
||||||
fftfilt* SSBFilter;
|
fftfilt* m_SSBFilter;
|
||||||
fftfilt* DSBFilter;
|
fftfilt* m_DSBFilter;
|
||||||
|
static const int m_ssbFftLen;
|
||||||
|
|
||||||
Real m_magsq;
|
Real m_magsq;
|
||||||
MovingAverage<Real> m_movingAverage;
|
MovingAverage<Real> m_movingAverage;
|
||||||
@ -371,8 +372,8 @@ private:
|
|||||||
static const int m_levelNbSamples;
|
static const int m_levelNbSamples;
|
||||||
|
|
||||||
void apply();
|
void apply();
|
||||||
void pullAF(Real& sample);
|
void pullAF(Complex& sample);
|
||||||
void calculateLevel(Real& sample);
|
void calculateLevel(Complex& sample);
|
||||||
void modulateSample();
|
void modulateSample();
|
||||||
void openFileStream();
|
void openFileStream();
|
||||||
void seekFileStream(int seekPercentage);
|
void seekFileStream(int seekPercentage);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user