Updates sample generator and test tuner controller to support multiple

complex buffer listeners.  Removes complex buffer broadcast support from
the source manager and renames it to channel source manager to convey
that it's only responsible for providing channels from the tuner.
This commit is contained in:
Denny
2018-01-15 05:34:36 -05:00
parent 5ae3cb38e1
commit 32ab0598e8
9 changed files with 60 additions and 100 deletions

View File

@@ -115,7 +115,7 @@ public class ChannelizerViewer extends JFrame
mTestTuner.getTunerController().getSampleRate()); mTestTuner.getTunerController().getSampleRate());
mPrimarySpectrumPanel.setPreferredSize(new Dimension(1000, 200)); mPrimarySpectrumPanel.setPreferredSize(new Dimension(1000, 200));
mPrimarySpectrumPanel.setDFTSize(mMainPanelDFTSize); mPrimarySpectrumPanel.setDFTSize(mMainPanelDFTSize);
mTestTuner.getSourceManager().addComplexBufferListener(mPrimarySpectrumPanel); mTestTuner.getTunerController().addComplexBufferListener(mPrimarySpectrumPanel);
} }
return mPrimarySpectrumPanel; return mPrimarySpectrumPanel;
@@ -272,7 +272,7 @@ public class ChannelizerViewer extends JFrame
mFrequency = frequency; mFrequency = frequency;
TunerChannel tunerChannel = new TunerChannel(frequency, bandwidth); TunerChannel tunerChannel = new TunerChannel(frequency, bandwidth);
mSource = mTestTuner.getSourceManager().getSource(tunerChannel); mSource = mTestTuner.getChannelSourceManager().getSource(tunerChannel);
if(mSource != null) if(mSource != null)
{ {

View File

@@ -156,7 +156,6 @@ public class ScheduledBufferProcessor<E> implements Listener<E>
{ {
mQueue.drainTo(mBuffers, mMaxBuffersPerInterval); mQueue.drainTo(mBuffers, mMaxBuffersPerInterval);
mLog.debug("Dispatching buffers: " + mBuffers.size());
if(mListener != null) if(mListener != null)
{ {
for(E buffer: mBuffers) for(E buffer: mBuffers)
@@ -164,7 +163,6 @@ public class ScheduledBufferProcessor<E> implements Listener<E>
mListener.receive(buffer); mListener.receive(buffer);
} }
} }
mLog.debug("Finished Dispatching buffers");
mBuffers.clear(); mBuffers.clear();
} }

View File

@@ -20,18 +20,18 @@ import io.github.dsheirer.sample.Listener;
import io.github.dsheirer.source.ISourceEventProcessor; import io.github.dsheirer.source.ISourceEventProcessor;
import io.github.dsheirer.source.SourceEvent; import io.github.dsheirer.source.SourceEvent;
import io.github.dsheirer.source.tuner.TunerEvent.Event; import io.github.dsheirer.source.tuner.TunerEvent.Event;
import io.github.dsheirer.source.tuner.manager.AbstractSourceManager; import io.github.dsheirer.source.tuner.manager.ChannelSourceManager;
import io.github.dsheirer.source.tuner.manager.TunerSourceManager; import io.github.dsheirer.source.tuner.manager.TunerChannelSourceManager;
/** /**
* Tuner provides an interface to a software or hardware tuner controller that provides I/Q sample data coupled with an * Tuner provides an interface to a software or hardware tuner controller that provides I/Q sample data coupled with a
* abstract source manager to provide access to Digital Drop Channel (DDC) resources. * channel source manager to provide access to Digital Drop Channel (DDC) resources.
*/ */
public abstract class Tuner implements ISourceEventProcessor public abstract class Tuner implements ISourceEventProcessor
{ {
private Broadcaster<TunerEvent> mTunerEventBroadcaster = new Broadcaster<>(); private Broadcaster<TunerEvent> mTunerEventBroadcaster = new Broadcaster<>();
private ChannelSourceManager mChannelSourceManager;
private TunerController mTunerController; private TunerController mTunerController;
private AbstractSourceManager mSourceManager;
private String mName; private String mName;
/** /**
@@ -46,9 +46,9 @@ public abstract class Tuner implements ISourceEventProcessor
//Register to receive frequency and sample rate change notifications //Register to receive frequency and sample rate change notifications
mTunerController.addListener(this::process); mTunerController.addListener(this::process);
mSourceManager = new TunerSourceManager(mTunerController); mChannelSourceManager = new TunerChannelSourceManager(mTunerController);
//Register to receive channel count change notifications //Register to receive channel count change notifications
mSourceManager.addSourceEventListener(this::process); mChannelSourceManager.addSourceEventListener(this::process);
} }
@Override @Override
@@ -73,9 +73,9 @@ public abstract class Tuner implements ISourceEventProcessor
/** /**
* Source Manager. Provides access to registering for complex buffer samples and source event notifications. * Source Manager. Provides access to registering for complex buffer samples and source event notifications.
*/ */
public AbstractSourceManager getSourceManager() public ChannelSourceManager getChannelSourceManager()
{ {
return mSourceManager; return mChannelSourceManager;
} }
/** /**

View File

@@ -235,7 +235,7 @@ public class TunerModel extends AbstractTableModel implements Listener<TunerEven
return 0; return 0;
} }
case CHANNEL_COUNT: case CHANNEL_COUNT:
return tuner.getSourceManager().getTunerChannelCount(); return tuner.getChannelSourceManager().getTunerChannelCount();
case SPECTRAL_DISPLAY_MAIN: case SPECTRAL_DISPLAY_MAIN:
return "Main"; return "Main";
case SPECTRAL_DISPLAY_NEW: case SPECTRAL_DISPLAY_NEW:
@@ -278,7 +278,7 @@ public class TunerModel extends AbstractTableModel implements Listener<TunerEven
try try
{ {
retVal = tuner.getSourceManager().getSource(tunerChannel); retVal = tuner.getChannelSourceManager().getSource(tunerChannel);
} }
catch(Exception e) catch(Exception e)
{ {

View File

@@ -17,8 +17,6 @@ package io.github.dsheirer.source.tuner.manager;
import io.github.dsheirer.sample.Broadcaster; import io.github.dsheirer.sample.Broadcaster;
import io.github.dsheirer.sample.Listener; import io.github.dsheirer.sample.Listener;
import io.github.dsheirer.sample.complex.ComplexBuffer;
import io.github.dsheirer.sample.complex.IComplexBufferProvider;
import io.github.dsheirer.source.ISourceEventProcessor; import io.github.dsheirer.source.ISourceEventProcessor;
import io.github.dsheirer.source.SourceEvent; import io.github.dsheirer.source.SourceEvent;
import io.github.dsheirer.source.tuner.channel.TunerChannel; import io.github.dsheirer.source.tuner.channel.TunerChannel;
@@ -27,12 +25,11 @@ import io.github.dsheirer.source.tuner.channel.TunerChannelSource;
import java.util.SortedSet; import java.util.SortedSet;
/** /**
* Interface to define the functionality of a source manager for handling tuner channel management, complex buffer * Interface to define the functionality of a channel source manager for handling tuner channel management and source
* listeners, and source event listeners. * event listeners.
*/ */
public abstract class AbstractSourceManager implements IComplexBufferProvider, ISourceEventProcessor public abstract class ChannelSourceManager implements ISourceEventProcessor
{ {
private Broadcaster<ComplexBuffer> mComplexBufferBroadcaster = new Broadcaster<>();
private Broadcaster<SourceEvent> mSourceEventBroadcaster = new Broadcaster<>(); private Broadcaster<SourceEvent> mSourceEventBroadcaster = new Broadcaster<>();
/** /**
@@ -57,41 +54,6 @@ public abstract class AbstractSourceManager implements IComplexBufferProvider, I
*/ */
public abstract TunerChannelSource getSource(TunerChannel tunerChannel); public abstract TunerChannelSource getSource(TunerChannel tunerChannel);
/**
* Adds the listener to receive complex buffer samples
*/
@Override
public void addComplexBufferListener(Listener<ComplexBuffer> listener)
{
mComplexBufferBroadcaster.addListener(listener);
}
/**
* Removes the listener from receiving complex buffer samples
*/
@Override
public void removeComplexBufferListener(Listener<ComplexBuffer> listener)
{
mComplexBufferBroadcaster.removeListener(listener);
}
/**
* Indicates if there are any complex buffer listeners registered with this source manager
*/
@Override
public boolean hasComplexBufferListeners()
{
return mComplexBufferBroadcaster.hasListeners();
}
/**
* Broadcasts the buffer to any registered listeners
*/
protected void broadcast(ComplexBuffer complexBuffer)
{
mComplexBufferBroadcaster.broadcast(complexBuffer);
}
/** /**
* Adds a listener to receive source events * Adds a listener to receive source events
*/ */

View File

@@ -26,20 +26,20 @@ import org.slf4j.LoggerFactory;
import java.util.SortedSet; import java.util.SortedSet;
public class TunerSourceManager extends AbstractSourceManager public class TunerChannelSourceManager extends ChannelSourceManager
{ {
private final static Logger mLog = LoggerFactory.getLogger(TunerSourceManager.class); private final static Logger mLog = LoggerFactory.getLogger(TunerChannelSourceManager.class);
private PolyphaseChannelManager mPolyphaseChannelManager; private PolyphaseChannelManager mPolyphaseChannelManager;
private TunerController mTunerController; private TunerController mTunerController;
/** /**
* TunerSourceManager is responsible for managing the tuner's center tuned frequency and providing access to * TunerChannelSourceManager is responsible for managing the tuner's center tuned frequency and providing access to
* polyphase tuner channel sources (ie DDCs). This class is responsible for determining IF a requested channel can * polyphase tuner channel sources (ie DDCs). This class is responsible for determining IF a requested channel can
* be provided and then adjusting the center frequency and provisioning a DDC Polyphase Tuner channel source. * be provided and then adjusting the center frequency and provisioning a DDC Polyphase Tuner channel source.
* *
* @param tunerController with a center tuned frequency that will be managed by this instance * @param tunerController with a center tuned frequency that will be managed by this instance
*/ */
public TunerSourceManager(TunerController tunerController) public TunerChannelSourceManager(TunerController tunerController)
{ {
mTunerController = tunerController; mTunerController = tunerController;

View File

@@ -1,24 +1,22 @@
/******************************************************************************* /*******************************************************************************
* sdrtrunk * sdr-trunk
* Copyright (C) 2014-2017 Dennis Sheirer * Copyright (C) 2014-2018 Dennis Sheirer
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
* it under the terms of the GNU General Public License as published by * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
* the Free Software Foundation, either version 3 of the License, or * later version.
* (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* but WITHOUT ANY WARRANTY; without even the implied warranty of * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License along with this program.
* along with this program. If not, see <http://www.gnu.org/licenses/> * If not, see <http://www.gnu.org/licenses/>
* *
******************************************************************************/ ******************************************************************************/
package io.github.dsheirer.source.tuner.test; package io.github.dsheirer.source.tuner.test;
import io.github.dsheirer.dsp.mixer.LowPhaseNoiseOscillator; import io.github.dsheirer.dsp.mixer.LowPhaseNoiseOscillator;
import io.github.dsheirer.sample.Broadcaster;
import io.github.dsheirer.sample.Listener; import io.github.dsheirer.sample.Listener;
import io.github.dsheirer.sample.complex.ComplexBuffer; import io.github.dsheirer.sample.complex.ComplexBuffer;
import io.github.dsheirer.sample.complex.TimestampedComplexBuffer; import io.github.dsheirer.sample.complex.TimestampedComplexBuffer;
@@ -33,9 +31,9 @@ public class SampleGenerator
{ {
private final static Logger mLog = LoggerFactory.getLogger(SampleGenerator.class); private final static Logger mLog = LoggerFactory.getLogger(SampleGenerator.class);
private Broadcaster<ComplexBuffer> mComplexBufferBroadcaster = new Broadcaster<>();
private LowPhaseNoiseOscillator mOscillator; private LowPhaseNoiseOscillator mOscillator;
private int mSweepUpdateInterval; private int mSweepUpdateInterval;
private Listener<ComplexBuffer> mListener;
private long mInterval; private long mInterval;
private int mSamplesPerInterval; private int mSamplesPerInterval;
private ScheduledFuture<?> mScheduledFuture; private ScheduledFuture<?> mScheduledFuture;
@@ -93,7 +91,7 @@ public class SampleGenerator
/** /**
* Starts the generator producing samples * Starts the generator producing samples
*/ */
public void start() private void start()
{ {
if(mScheduledFuture == null) if(mScheduledFuture == null)
{ {
@@ -109,7 +107,7 @@ public class SampleGenerator
/** /**
* Stops the generator from producing samples * Stops the generator from producing samples
*/ */
public void stop() private void stop()
{ {
if(mScheduledFuture != null) if(mScheduledFuture != null)
{ {
@@ -123,14 +121,31 @@ public class SampleGenerator
} }
/** /**
* Registers the listener to receive samples once the generator starts. Note: invoke this method with null * Registers the listener to receive samples and auto-starts the generator if this is the first listener.
* argument to de-register the listener.
* *
* @param listener to receive complex sample buffers * @param listener to receive complex sample buffers
*/ */
public void setListener(Listener<ComplexBuffer> listener) public void addListener(Listener<ComplexBuffer> listener)
{ {
mListener = listener; mComplexBufferBroadcaster.addListener(listener);
if(mComplexBufferBroadcaster.getListenerCount() == 1)
{
start();
}
}
/**
* Removes the listener and stops the sample generator if there are no more listeners.
*/
public void removeListener(Listener<ComplexBuffer> listener)
{
mComplexBufferBroadcaster.removeListener(listener);
if(mComplexBufferBroadcaster.getListenerCount() == 0)
{
stop();
}
} }
/** /**
@@ -168,10 +183,11 @@ public class SampleGenerator
@Override @Override
public void run() public void run()
{ {
if(mListener != null) if(mComplexBufferBroadcaster.hasListeners())
{ {
float[] samples = mOscillator.generate(mSamplesPerInterval); float[] samples = mOscillator.generate(mSamplesPerInterval);
mListener.receive(new TimestampedComplexBuffer(samples));
mComplexBufferBroadcaster.receive(new TimestampedComplexBuffer(samples));
if(mSweepUpdateInterval != 0) if(mSweepUpdateInterval != 0)
{ {

View File

@@ -66,32 +66,16 @@ public class TestTunerController extends TunerController
} }
} }
/**
* Starts the tuner controller producing samples that will be delivered to the specified listener
*/
public void start(Listener<ComplexBuffer> listener)
{
}
@Override @Override
public void addComplexBufferListener(Listener<ComplexBuffer> listener) public void addComplexBufferListener(Listener<ComplexBuffer> listener)
{ {
mSampleGenerator.setListener(listener); mSampleGenerator.addListener(listener);
mSampleGenerator.start();
} }
@Override @Override
public void removeComplexBufferListener(Listener<ComplexBuffer> listener) public void removeComplexBufferListener(Listener<ComplexBuffer> listener)
{ {
mSampleGenerator.stop(); mSampleGenerator.removeListener(listener);
mSampleGenerator.setListener(null);
}
/**
* Stops the tuner controller sample generator and deregisters the listener
*/
public void stop()
{
} }
@Override @Override

View File

@@ -435,7 +435,7 @@ public class SpectralDisplayPanel extends JPanel implements Listener<ComplexBuff
mTuner.getTunerController().addListener(this); mTuner.getTunerController().addListener(this);
//Register the dft processor to receive samples from the tuner //Register the dft processor to receive samples from the tuner
mTuner.getSourceManager().addComplexBufferListener(mDFTProcessor); mTuner.getTunerController().addComplexBufferListener(mDFTProcessor);
mSpectrumPanel.setSampleSize(mTuner.getSampleSize()); mSpectrumPanel.setSampleSize(mTuner.getSampleSize());