diff --git a/src/main/java/io/github/dsheirer/dsp/filter/channelizer/ChannelizerViewer.java b/src/main/java/io/github/dsheirer/dsp/filter/channelizer/ChannelizerViewer.java index f3ffb5ef..33832fe3 100644 --- a/src/main/java/io/github/dsheirer/dsp/filter/channelizer/ChannelizerViewer.java +++ b/src/main/java/io/github/dsheirer/dsp/filter/channelizer/ChannelizerViewer.java @@ -115,7 +115,7 @@ public class ChannelizerViewer extends JFrame mTestTuner.getTunerController().getSampleRate()); mPrimarySpectrumPanel.setPreferredSize(new Dimension(1000, 200)); mPrimarySpectrumPanel.setDFTSize(mMainPanelDFTSize); - mTestTuner.getSourceManager().addComplexBufferListener(mPrimarySpectrumPanel); + mTestTuner.getTunerController().addComplexBufferListener(mPrimarySpectrumPanel); } return mPrimarySpectrumPanel; @@ -272,7 +272,7 @@ public class ChannelizerViewer extends JFrame mFrequency = frequency; TunerChannel tunerChannel = new TunerChannel(frequency, bandwidth); - mSource = mTestTuner.getSourceManager().getSource(tunerChannel); + mSource = mTestTuner.getChannelSourceManager().getSource(tunerChannel); if(mSource != null) { diff --git a/src/main/java/io/github/dsheirer/dsp/filter/channelizer/ScheduledBufferProcessor.java b/src/main/java/io/github/dsheirer/dsp/filter/channelizer/ScheduledBufferProcessor.java index 2604961e..f9b0ab0c 100644 --- a/src/main/java/io/github/dsheirer/dsp/filter/channelizer/ScheduledBufferProcessor.java +++ b/src/main/java/io/github/dsheirer/dsp/filter/channelizer/ScheduledBufferProcessor.java @@ -156,7 +156,6 @@ public class ScheduledBufferProcessor implements Listener { mQueue.drainTo(mBuffers, mMaxBuffersPerInterval); - mLog.debug("Dispatching buffers: " + mBuffers.size()); if(mListener != null) { for(E buffer: mBuffers) @@ -164,7 +163,6 @@ public class ScheduledBufferProcessor implements Listener mListener.receive(buffer); } } - mLog.debug("Finished Dispatching buffers"); mBuffers.clear(); } diff --git a/src/main/java/io/github/dsheirer/source/tuner/Tuner.java b/src/main/java/io/github/dsheirer/source/tuner/Tuner.java index d9a19e90..66c30bf7 100644 --- a/src/main/java/io/github/dsheirer/source/tuner/Tuner.java +++ b/src/main/java/io/github/dsheirer/source/tuner/Tuner.java @@ -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 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; } /** diff --git a/src/main/java/io/github/dsheirer/source/tuner/TunerModel.java b/src/main/java/io/github/dsheirer/source/tuner/TunerModel.java index 919f32d6..9c00915e 100644 --- a/src/main/java/io/github/dsheirer/source/tuner/TunerModel.java +++ b/src/main/java/io/github/dsheirer/source/tuner/TunerModel.java @@ -235,7 +235,7 @@ public class TunerModel extends AbstractTableModel implements Listener mComplexBufferBroadcaster = new Broadcaster<>(); private Broadcaster 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 listener) - { - mComplexBufferBroadcaster.addListener(listener); - } - - /** - * Removes the listener from receiving complex buffer samples - */ - @Override - public void removeComplexBufferListener(Listener 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 */ diff --git a/src/main/java/io/github/dsheirer/source/tuner/manager/TunerSourceManager.java b/src/main/java/io/github/dsheirer/source/tuner/manager/TunerChannelSourceManager.java similarity index 98% rename from src/main/java/io/github/dsheirer/source/tuner/manager/TunerSourceManager.java rename to src/main/java/io/github/dsheirer/source/tuner/manager/TunerChannelSourceManager.java index f3c659f6..e6159a0b 100644 --- a/src/main/java/io/github/dsheirer/source/tuner/manager/TunerSourceManager.java +++ b/src/main/java/io/github/dsheirer/source/tuner/manager/TunerChannelSourceManager.java @@ -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; diff --git a/src/main/java/io/github/dsheirer/source/tuner/test/SampleGenerator.java b/src/main/java/io/github/dsheirer/source/tuner/test/SampleGenerator.java index 11cf4f14..fd6d322a 100644 --- a/src/main/java/io/github/dsheirer/source/tuner/test/SampleGenerator.java +++ b/src/main/java/io/github/dsheirer/source/tuner/test/SampleGenerator.java @@ -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 + * You should have received a copy of the GNU General Public License along with this program. + * If not, see * ******************************************************************************/ 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 mComplexBufferBroadcaster = new Broadcaster<>(); private LowPhaseNoiseOscillator mOscillator; private int mSweepUpdateInterval; - private Listener 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 listener) + public void addListener(Listener 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 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) { diff --git a/src/main/java/io/github/dsheirer/source/tuner/test/TestTunerController.java b/src/main/java/io/github/dsheirer/source/tuner/test/TestTunerController.java index 4561d0c4..9867f2c2 100644 --- a/src/main/java/io/github/dsheirer/source/tuner/test/TestTunerController.java +++ b/src/main/java/io/github/dsheirer/source/tuner/test/TestTunerController.java @@ -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 listener) - { - } - @Override public void addComplexBufferListener(Listener listener) { - mSampleGenerator.setListener(listener); - mSampleGenerator.start(); + mSampleGenerator.addListener(listener); } @Override public void removeComplexBufferListener(Listener listener) { - mSampleGenerator.stop(); - mSampleGenerator.setListener(null); - } - - /** - * Stops the tuner controller sample generator and deregisters the listener - */ - public void stop() - { + mSampleGenerator.removeListener(listener); } @Override diff --git a/src/main/java/io/github/dsheirer/spectrum/SpectralDisplayPanel.java b/src/main/java/io/github/dsheirer/spectrum/SpectralDisplayPanel.java index c9719429..a5032815 100644 --- a/src/main/java/io/github/dsheirer/spectrum/SpectralDisplayPanel.java +++ b/src/main/java/io/github/dsheirer/spectrum/SpectralDisplayPanel.java @@ -435,7 +435,7 @@ public class SpectralDisplayPanel extends JPanel implements Listener