1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-23 00:18:37 -05:00

Deep redesign: SSB audio FIFO on object stack

This commit is contained in:
f4exb 2015-08-24 02:40:02 +02:00
parent 11cc3044f8
commit 67866854ca
9 changed files with 26 additions and 32 deletions

View File

@ -220,7 +220,6 @@ AMDemodGUI::AMDemodGUI(PluginAPI* pluginAPI, QWidget* parent) :
AMDemodGUI::~AMDemodGUI() AMDemodGUI::~AMDemodGUI()
{ {
m_pluginAPI->removeChannelInstance(this); m_pluginAPI->removeChannelInstance(this);
DSPEngine::instance()->removeAudioSink(m_audioFifo);
DSPEngine::instance()->removeThreadedSink(m_threadedChannelizer); DSPEngine::instance()->removeThreadedSink(m_threadedChannelizer);
delete m_threadedChannelizer; delete m_threadedChannelizer;
delete m_channelizer; delete m_channelizer;

View File

@ -7,7 +7,6 @@
class PluginAPI; class PluginAPI;
class ChannelMarker; class ChannelMarker;
class AudioFifo;
class ThreadedSampleSink; class ThreadedSampleSink;
class Channelizer; class Channelizer;
class AMDemod; class AMDemod;
@ -51,7 +50,6 @@ private:
bool m_basicSettingsShown; bool m_basicSettingsShown;
bool m_doApplySettings; bool m_doApplySettings;
AudioFifo* m_audioFifo;
ThreadedSampleSink* m_threadedChannelizer; ThreadedSampleSink* m_threadedChannelizer;
Channelizer* m_channelizer; Channelizer* m_channelizer;
AMDemod* m_amDemod; AMDemod* m_amDemod;

View File

@ -166,7 +166,6 @@ bool ChannelAnalyzer::handleMessage(const Message& cmd)
m_Bandwidth = band; m_Bandwidth = band;
m_LowCutoff = lowCutoff; m_LowCutoff = lowCutoff;
//m_interpolator.create(16, m_sampleRate, band * 2.0f);
SSBFilter->create_filter(m_LowCutoff / m_sampleRate, m_Bandwidth / m_sampleRate); SSBFilter->create_filter(m_LowCutoff / m_sampleRate, m_Bandwidth / m_sampleRate);
DSBFilter->create_dsb_filter(m_Bandwidth / m_sampleRate); DSBFilter->create_dsb_filter(m_Bandwidth / m_sampleRate);

View File

@ -21,15 +21,12 @@
#include <vector> #include <vector>
#include "dsp/samplesink.h" #include "dsp/samplesink.h"
#include "dsp/nco.h" #include "dsp/nco.h"
#include "dsp/interpolator.h"
#include "dsp/fftfilt.h" #include "dsp/fftfilt.h"
#include "audio/audiofifo.h" #include "audio/audiofifo.h"
#include "util/message.h" #include "util/message.h"
#define ssbFftLen 1024 #define ssbFftLen 1024
//class AudioFifo;
class ChannelAnalyzer : public SampleSink { class ChannelAnalyzer : public SampleSink {
public: public:
ChannelAnalyzer(SampleSink* m_sampleSink); ChannelAnalyzer(SampleSink* m_sampleSink);

View File

@ -8,7 +8,6 @@
class PluginAPI; class PluginAPI;
class ChannelMarker; class ChannelMarker;
class AudioFifo;
class ThreadedSampleSink; class ThreadedSampleSink;
class Channelizer; class Channelizer;
class NFMDemod; class NFMDemod;
@ -54,7 +53,6 @@ private:
bool m_basicSettingsShown; bool m_basicSettingsShown;
bool m_doApplySettings; bool m_doApplySettings;
AudioFifo* m_audioFifo;
ThreadedSampleSink* m_threadedChannelizer; ThreadedSampleSink* m_threadedChannelizer;
Channelizer* m_channelizer; Channelizer* m_channelizer;
NFMDemod* m_nfmDemod; NFMDemod* m_nfmDemod;

View File

@ -21,13 +21,14 @@
#include <stdio.h> #include <stdio.h>
#include "ssbdemod.h" #include "ssbdemod.h"
#include "audio/audiooutput.h" #include "audio/audiooutput.h"
#include "dsp/dspengine.h"
#include "dsp/channelizer.h" #include "dsp/channelizer.h"
MESSAGE_CLASS_DEFINITION(SSBDemod::MsgConfigureSSBDemod, Message) MESSAGE_CLASS_DEFINITION(SSBDemod::MsgConfigureSSBDemod, Message)
SSBDemod::SSBDemod(AudioFifo* audioFifo, SampleSink* sampleSink) : SSBDemod::SSBDemod(SampleSink* sampleSink) :
m_sampleSink(sampleSink), m_sampleSink(sampleSink),
m_audioFifo(audioFifo) m_audioFifo(4, 24000)
{ {
setObjectName("SSBDemod"); setObjectName("SSBDemod");
@ -38,21 +39,29 @@ SSBDemod::SSBDemod(AudioFifo* audioFifo, SampleSink* sampleSink) :
m_sampleRate = 96000; m_sampleRate = 96000;
m_frequency = 0; m_frequency = 0;
m_nco.setFreq(m_frequency, m_sampleRate); m_nco.setFreq(m_frequency, m_sampleRate);
m_interpolator.create(16, m_sampleRate, 5000); m_audioSampleRate = DSPEngine::instance()->getAudioSampleRate();
m_sampleDistanceRemain = (Real)m_sampleRate / 48000.0;
m_audioBuffer.resize(512); m_interpolator.create(16, m_sampleRate, 5000);
m_sampleDistanceRemain = (Real) m_sampleRate / m_audioSampleRate;
m_audioBuffer.resize(1<<9);
m_audioBufferFill = 0; m_audioBufferFill = 0;
m_undersampleCount = 0; m_undersampleCount = 0;
m_usb = true; m_usb = true;
SSBFilter = new fftfilt(m_LowCutoff / 48000.0, m_Bandwidth / 48000.0, ssbFftLen); SSBFilter = new fftfilt(m_LowCutoff / m_audioSampleRate, m_Bandwidth / m_audioSampleRate, ssbFftLen);
// if (!USBFilter) segfault;
DSPEngine::instance()->addAudioSink(&m_audioFifo);
} }
SSBDemod::~SSBDemod() SSBDemod::~SSBDemod()
{ {
if (SSBFilter) delete SSBFilter; if (SSBFilter)
{
delete SSBFilter;
}
DSPEngine::instance()->removeAudioSink(&m_audioFifo);
} }
void SSBDemod::configure(MessageQueue* messageQueue, Real Bandwidth, Real LowCutoff, Real volume, int spanLog2) void SSBDemod::configure(MessageQueue* messageQueue, Real Bandwidth, Real LowCutoff, Real volume, int spanLog2)
@ -78,7 +87,7 @@ void SSBDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iter
if(m_interpolator.interpolate(&m_sampleDistanceRemain, c, &ci)) if(m_interpolator.interpolate(&m_sampleDistanceRemain, c, &ci))
{ {
n_out = SSBFilter->runSSB(ci, &sideband, m_usb); n_out = SSBFilter->runSSB(ci, &sideband, m_usb);
m_sampleDistanceRemain += (Real)m_sampleRate / 48000.0; m_sampleDistanceRemain += (Real)m_sampleRate / m_audioSampleRate;
} }
else else
{ {
@ -109,7 +118,7 @@ void SSBDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iter
if (m_audioBufferFill >= m_audioBuffer.size()) if (m_audioBufferFill >= m_audioBuffer.size())
{ {
uint res = m_audioFifo->write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 1); uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 1);
if (res != m_audioBufferFill) if (res != m_audioBufferFill)
{ {
@ -121,7 +130,7 @@ void SSBDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iter
} }
} }
if (m_audioFifo->write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 0) != m_audioBufferFill) if (m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 0) != m_audioBufferFill)
{ {
qDebug("SSBDemod::feed: lost samples"); qDebug("SSBDemod::feed: lost samples");
} }
@ -156,7 +165,7 @@ bool SSBDemod::handleMessage(const Message& cmd)
m_sampleRate = notif.getSampleRate(); m_sampleRate = notif.getSampleRate();
m_nco.setFreq(-notif.getFrequencyOffset(), m_sampleRate); m_nco.setFreq(-notif.getFrequencyOffset(), m_sampleRate);
m_interpolator.create(16, m_sampleRate, m_Bandwidth); m_interpolator.create(16, m_sampleRate, m_Bandwidth);
m_sampleDistanceRemain = m_sampleRate / 48000.0; m_sampleDistanceRemain = m_sampleRate / m_audioSampleRate;
qDebug() << "SSBDemod::handleMessage: MsgChannelizerNotification: m_sampleRate: " << m_sampleRate qDebug() << "SSBDemod::handleMessage: MsgChannelizerNotification: m_sampleRate: " << m_sampleRate
<< " frequencyOffset" << notif.getFrequencyOffset(); << " frequencyOffset" << notif.getFrequencyOffset();
@ -187,7 +196,7 @@ bool SSBDemod::handleMessage(const Message& cmd)
m_LowCutoff = lowCutoff; m_LowCutoff = lowCutoff;
m_interpolator.create(16, m_sampleRate, band * 2.0f); m_interpolator.create(16, m_sampleRate, band * 2.0f);
SSBFilter->create_filter(m_LowCutoff / 48000.0f, m_Bandwidth / 48000.0f); SSBFilter->create_filter(m_LowCutoff / (float) m_audioSampleRate, m_Bandwidth / (float) m_audioSampleRate);
m_volume = cfg.getVolume(); m_volume = cfg.getVolume();
m_volume *= m_volume * 0.1; m_volume *= m_volume * 0.1;

View File

@ -28,11 +28,9 @@
#define ssbFftLen 1024 #define ssbFftLen 1024
class AudioFifo;
class SSBDemod : public SampleSink { class SSBDemod : public SampleSink {
public: public:
SSBDemod(AudioFifo* audioFifo, SampleSink* sampleSink); SSBDemod(SampleSink* sampleSink);
virtual ~SSBDemod(); virtual ~SSBDemod();
void configure(MessageQueue* messageQueue, Real Bandwidth, Real LowCutoff, Real volume, int spanLog2); void configure(MessageQueue* messageQueue, Real Bandwidth, Real LowCutoff, Real volume, int spanLog2);
@ -97,7 +95,8 @@ private:
AudioVector m_audioBuffer; AudioVector m_audioBuffer;
uint m_audioBufferFill; uint m_audioBufferFill;
AudioFifo* m_audioFifo; AudioFifo m_audioFifo;
quint32 m_audioSampleRate;
}; };
#endif // INCLUDE_SSBDEMOD_H #endif // INCLUDE_SSBDEMOD_H

View File

@ -255,12 +255,10 @@ SSBDemodGUI::SSBDemodGUI(PluginAPI* pluginAPI, QWidget* parent) :
connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool))); connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool)));
connect(this, SIGNAL(menuDoubleClickEvent()), this, SLOT(onMenuDoubleClicked())); connect(this, SIGNAL(menuDoubleClickEvent()), this, SLOT(onMenuDoubleClicked()));
m_audioFifo = new AudioFifo(4, 48000 / 2);
m_spectrumVis = new SpectrumVis(ui->glSpectrum); m_spectrumVis = new SpectrumVis(ui->glSpectrum);
m_ssbDemod = new SSBDemod(m_audioFifo, m_spectrumVis); m_ssbDemod = new SSBDemod(m_spectrumVis);
m_channelizer = new Channelizer(m_ssbDemod); m_channelizer = new Channelizer(m_ssbDemod);
m_threadedChannelizer = new ThreadedSampleSink(m_channelizer, this); m_threadedChannelizer = new ThreadedSampleSink(m_channelizer, this);
DSPEngine::instance()->addAudioSink(m_audioFifo);
DSPEngine::instance()->addThreadedSink(m_threadedChannelizer); DSPEngine::instance()->addThreadedSink(m_threadedChannelizer);
ui->deltaFrequency->setColorMapper(ColorMapper(ColorMapper::ReverseGold)); ui->deltaFrequency->setColorMapper(ColorMapper(ColorMapper::ReverseGold));
@ -289,13 +287,11 @@ SSBDemodGUI::SSBDemodGUI(PluginAPI* pluginAPI, QWidget* parent) :
SSBDemodGUI::~SSBDemodGUI() SSBDemodGUI::~SSBDemodGUI()
{ {
m_pluginAPI->removeChannelInstance(this); m_pluginAPI->removeChannelInstance(this);
DSPEngine::instance()->removeAudioSink(m_audioFifo);
DSPEngine::instance()->removeThreadedSink(m_threadedChannelizer); DSPEngine::instance()->removeThreadedSink(m_threadedChannelizer);
delete m_threadedChannelizer; delete m_threadedChannelizer;
delete m_channelizer; delete m_channelizer;
delete m_ssbDemod; delete m_ssbDemod;
delete m_spectrumVis; delete m_spectrumVis;
delete m_audioFifo;
delete m_channelMarker; delete m_channelMarker;
delete ui; delete ui;
} }

View File

@ -54,7 +54,6 @@ private:
int m_rate; int m_rate;
int m_spanLog2; int m_spanLog2;
AudioFifo* m_audioFifo;
ThreadedSampleSink* m_threadedChannelizer; ThreadedSampleSink* m_threadedChannelizer;
Channelizer* m_channelizer; Channelizer* m_channelizer;
SSBDemod* m_ssbDemod; SSBDemod* m_ssbDemod;