mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 16:47:31 -05:00
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:
@@ -20,18 +20,18 @@ import io.github.dsheirer.sample.Listener;
|
||||
import io.github.dsheirer.source.ISourceEventProcessor;
|
||||
import io.github.dsheirer.source.SourceEvent;
|
||||
import io.github.dsheirer.source.tuner.TunerEvent.Event;
|
||||
import io.github.dsheirer.source.tuner.manager.AbstractSourceManager;
|
||||
import io.github.dsheirer.source.tuner.manager.TunerSourceManager;
|
||||
import io.github.dsheirer.source.tuner.manager.ChannelSourceManager;
|
||||
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
|
||||
* abstract source manager to provide access to Digital Drop Channel (DDC) resources.
|
||||
* Tuner provides an interface to a software or hardware tuner controller that provides I/Q sample data coupled with a
|
||||
* channel source manager to provide access to Digital Drop Channel (DDC) resources.
|
||||
*/
|
||||
public abstract class Tuner implements ISourceEventProcessor
|
||||
{
|
||||
private Broadcaster<TunerEvent> mTunerEventBroadcaster = new Broadcaster<>();
|
||||
private ChannelSourceManager mChannelSourceManager;
|
||||
private TunerController mTunerController;
|
||||
private AbstractSourceManager mSourceManager;
|
||||
private String mName;
|
||||
|
||||
/**
|
||||
@@ -46,9 +46,9 @@ public abstract class Tuner implements ISourceEventProcessor
|
||||
//Register to receive frequency and sample rate change notifications
|
||||
mTunerController.addListener(this::process);
|
||||
|
||||
mSourceManager = new TunerSourceManager(mTunerController);
|
||||
mChannelSourceManager = new TunerChannelSourceManager(mTunerController);
|
||||
//Register to receive channel count change notifications
|
||||
mSourceManager.addSourceEventListener(this::process);
|
||||
mChannelSourceManager.addSourceEventListener(this::process);
|
||||
}
|
||||
|
||||
@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.
|
||||
*/
|
||||
public AbstractSourceManager getSourceManager()
|
||||
public ChannelSourceManager getChannelSourceManager()
|
||||
{
|
||||
return mSourceManager;
|
||||
return mChannelSourceManager;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -235,7 +235,7 @@ public class TunerModel extends AbstractTableModel implements Listener<TunerEven
|
||||
return 0;
|
||||
}
|
||||
case CHANNEL_COUNT:
|
||||
return tuner.getSourceManager().getTunerChannelCount();
|
||||
return tuner.getChannelSourceManager().getTunerChannelCount();
|
||||
case SPECTRAL_DISPLAY_MAIN:
|
||||
return "Main";
|
||||
case SPECTRAL_DISPLAY_NEW:
|
||||
@@ -278,7 +278,7 @@ public class TunerModel extends AbstractTableModel implements Listener<TunerEven
|
||||
|
||||
try
|
||||
{
|
||||
retVal = tuner.getSourceManager().getSource(tunerChannel);
|
||||
retVal = tuner.getChannelSourceManager().getSource(tunerChannel);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
|
||||
@@ -17,8 +17,6 @@ package io.github.dsheirer.source.tuner.manager;
|
||||
|
||||
import io.github.dsheirer.sample.Broadcaster;
|
||||
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.SourceEvent;
|
||||
import io.github.dsheirer.source.tuner.channel.TunerChannel;
|
||||
@@ -27,12 +25,11 @@ import io.github.dsheirer.source.tuner.channel.TunerChannelSource;
|
||||
import java.util.SortedSet;
|
||||
|
||||
/**
|
||||
* Interface to define the functionality of a source manager for handling tuner channel management, complex buffer
|
||||
* listeners, and source event listeners.
|
||||
* Interface to define the functionality of a channel source manager for handling tuner channel management and source
|
||||
* 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<>();
|
||||
|
||||
/**
|
||||
@@ -57,41 +54,6 @@ public abstract class AbstractSourceManager implements IComplexBufferProvider, I
|
||||
*/
|
||||
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
|
||||
*/
|
||||
@@ -26,20 +26,20 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
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 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
|
||||
* 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
|
||||
*/
|
||||
public TunerSourceManager(TunerController tunerController)
|
||||
public TunerChannelSourceManager(TunerController tunerController)
|
||||
{
|
||||
mTunerController = tunerController;
|
||||
|
||||
@@ -1,24 +1,22 @@
|
||||
/*******************************************************************************
|
||||
* sdrtrunk
|
||||
* Copyright (C) 2014-2017 Dennis Sheirer
|
||||
* sdr-trunk
|
||||
* Copyright (C) 2014-2018 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
|
||||
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
|
||||
* later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of 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
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
* You should have received a copy of the GNU General Public License along with this program.
|
||||
* If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
******************************************************************************/
|
||||
package io.github.dsheirer.source.tuner.test;
|
||||
|
||||
import io.github.dsheirer.dsp.mixer.LowPhaseNoiseOscillator;
|
||||
import io.github.dsheirer.sample.Broadcaster;
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
import io.github.dsheirer.sample.complex.ComplexBuffer;
|
||||
import io.github.dsheirer.sample.complex.TimestampedComplexBuffer;
|
||||
@@ -33,9 +31,9 @@ public class SampleGenerator
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger(SampleGenerator.class);
|
||||
|
||||
private Broadcaster<ComplexBuffer> mComplexBufferBroadcaster = new Broadcaster<>();
|
||||
private LowPhaseNoiseOscillator mOscillator;
|
||||
private int mSweepUpdateInterval;
|
||||
private Listener<ComplexBuffer> mListener;
|
||||
private long mInterval;
|
||||
private int mSamplesPerInterval;
|
||||
private ScheduledFuture<?> mScheduledFuture;
|
||||
@@ -93,7 +91,7 @@ public class SampleGenerator
|
||||
/**
|
||||
* Starts the generator producing samples
|
||||
*/
|
||||
public void start()
|
||||
private void start()
|
||||
{
|
||||
if(mScheduledFuture == null)
|
||||
{
|
||||
@@ -109,7 +107,7 @@ public class SampleGenerator
|
||||
/**
|
||||
* Stops the generator from producing samples
|
||||
*/
|
||||
public void stop()
|
||||
private void stop()
|
||||
{
|
||||
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
|
||||
* argument to de-register the listener.
|
||||
* Registers the listener to receive samples and auto-starts the generator if this is the first listener.
|
||||
*
|
||||
* @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
|
||||
public void run()
|
||||
{
|
||||
if(mListener != null)
|
||||
if(mComplexBufferBroadcaster.hasListeners())
|
||||
{
|
||||
float[] samples = mOscillator.generate(mSamplesPerInterval);
|
||||
mListener.receive(new TimestampedComplexBuffer(samples));
|
||||
|
||||
mComplexBufferBroadcaster.receive(new TimestampedComplexBuffer(samples));
|
||||
|
||||
if(mSweepUpdateInterval != 0)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
public void addComplexBufferListener(Listener<ComplexBuffer> listener)
|
||||
{
|
||||
mSampleGenerator.setListener(listener);
|
||||
mSampleGenerator.start();
|
||||
mSampleGenerator.addListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeComplexBufferListener(Listener<ComplexBuffer> listener)
|
||||
{
|
||||
mSampleGenerator.stop();
|
||||
mSampleGenerator.setListener(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the tuner controller sample generator and deregisters the listener
|
||||
*/
|
||||
public void stop()
|
||||
{
|
||||
mSampleGenerator.removeListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user