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

@@ -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)
{

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
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