Skip to content

Commit

Permalink
#1506 Resolves issue with registering heartbeat manager to dispatcher.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Sheirer committed Mar 31, 2023
1 parent c079419 commit 8d1f704
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ public void doUpdateOutputProcessor(ChannelCalculator channelCalculator, Synthes
if(mPolyphaseChannelOutputProcessor != null)
{
mPolyphaseChannelOutputProcessor.setListener(null);
mPolyphaseChannelOutputProcessor.setHeartbeatManager(null);
mPolyphaseChannelOutputProcessor.stop();
}

Expand All @@ -223,7 +222,7 @@ public void doUpdateOutputProcessor(ChannelCalculator channelCalculator, Synthes
{
case 1:
mPolyphaseChannelOutputProcessor = new OneChannelOutputProcessor(channelCalculator.getChannelSampleRate(),
indexes, channelCalculator.getChannelCount());
indexes, channelCalculator.getChannelCount(), getHeartbeatManager());
mPolyphaseChannelOutputProcessor.setListener(this);
mPolyphaseChannelOutputProcessor.setFrequencyOffset(getFrequencyOffset());
mPolyphaseChannelOutputProcessor.start();
Expand All @@ -234,7 +233,7 @@ public void doUpdateOutputProcessor(ChannelCalculator channelCalculator, Synthes
float[] filter = filterManager.getFilter(channelCalculator.getChannelSampleRate(),
channelCalculator.getChannelBandwidth(), 2);
mPolyphaseChannelOutputProcessor = new TwoChannelOutputProcessor(channelCalculator.getChannelSampleRate(),
indexes, filter, channelCalculator.getChannelCount());
indexes, filter, channelCalculator.getChannelCount(), getHeartbeatManager());
mPolyphaseChannelOutputProcessor.setListener(this);
mPolyphaseChannelOutputProcessor.setFrequencyOffset(getFrequencyOffset());
mPolyphaseChannelOutputProcessor.start();
Expand All @@ -254,14 +253,6 @@ public void doUpdateOutputProcessor(ChannelCalculator channelCalculator, Synthes
}
}

/**
* Register this channel's heartbeat manager to receive heartbeat commands on the output processor's dispatch interval
*/
if(mPolyphaseChannelOutputProcessor != null)
{
mPolyphaseChannelOutputProcessor.setHeartbeatManager(getHeartbeatManager());
}

//Unlikely, but if we had an error designing a synthesis filter, throw an exception
if(errorMessage != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public abstract class ChannelOutputProcessor implements IPolyphaseChannelOutputP
private final static Logger mLog = LoggerFactory.getLogger(ChannelOutputProcessor.class);

private Dispatcher<List<float[]>> mChannelResultsDispatcher;
private HeartbeatManager mHeartbeatManager;
protected Listener<ComplexSamples> mComplexSamplesListener;
private int mInputChannelCount;
private long mCurrentSampleTimestamp = System.currentTimeMillis();
Expand All @@ -42,12 +43,15 @@ public abstract class ChannelOutputProcessor implements IPolyphaseChannelOutputP
* @param inputChannelCount is the number of input channels for this output processor
* @param sampleRate of the output channel. This is used to match the oscillator's sample rate to the output
* channel sample rate for frequency translation/correction.
* @param heartbeatManager to receive pings on the dispatcher thread
*/
public ChannelOutputProcessor(int inputChannelCount, double sampleRate)
public ChannelOutputProcessor(int inputChannelCount, double sampleRate, HeartbeatManager heartbeatManager)
{
mInputChannelCount = inputChannelCount;
//Process 1/10th of the sample rate per second at a rate of 20 times a second (200% of anticipated rate)
mChannelResultsDispatcher = new Dispatcher("sdrtrunk polyphase channel", (int)(sampleRate / 10), 50);
mHeartbeatManager = heartbeatManager;
mChannelResultsDispatcher = new Dispatcher("sdrtrunk polyphase channel", (int)(sampleRate / 10),
50, mHeartbeatManager);
mChannelResultsDispatcher.setListener(floats -> {
try
{
Expand All @@ -60,19 +64,6 @@ public ChannelOutputProcessor(int inputChannelCount, double sampleRate)
});
}

/**
* Sets the heartbeat manager to receive commands from the dispatcher thread on the dispatching interval.
* @param heartbeatManager to be commanded.
*/
@Override
public void setHeartbeatManager(HeartbeatManager heartbeatManager)
{
if(mChannelResultsDispatcher != null)
{
mChannelResultsDispatcher.setHeartbeatManager(heartbeatManager);
}
}

/**
* Timestamp for the current series of samples.
* @return time in milliseconds to use with assembled complex sample buffers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import io.github.dsheirer.sample.Listener;
import io.github.dsheirer.sample.complex.ComplexSamples;
import io.github.dsheirer.source.heartbeat.HeartbeatManager;
import java.util.List;

public interface IPolyphaseChannelOutputProcessor
Expand Down Expand Up @@ -51,12 +50,6 @@ public interface IPolyphaseChannelOutputProcessor
*/
void setListener(Listener<ComplexSamples> listener);

/**
* Sets a heartbeat manager to receive queues on the dispatching interval.
* @param heartbeatManager to be commanded.
*/
void setHeartbeatManager(HeartbeatManager heartbeatManager);

/**
* Sets the desired frequency offset from center. The samples will be mixed with an oscillator set to this offset
* frequency to produce an output where the desired signal is centered in the passband.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package io.github.dsheirer.dsp.filter.channelizer.output;

import io.github.dsheirer.sample.complex.ComplexSamples;
import io.github.dsheirer.source.heartbeat.HeartbeatManager;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -36,10 +37,12 @@ public class OneChannelOutputProcessor extends ChannelOutputProcessor
* @param sampleRate of the output sample stream.
* @param channelIndexes containing a single channel index.
* @param gain value to apply. This is typically the same as the channelizer's channel count.
* @param heartbeatManager to receive heartbeats on the dispatch thread
*/
public OneChannelOutputProcessor(double sampleRate, List<Integer> channelIndexes, float gain)
public OneChannelOutputProcessor(double sampleRate, List<Integer> channelIndexes, float gain,
HeartbeatManager heartbeatManager)
{
super(1, sampleRate);
super(1, sampleRate, heartbeatManager);
setPolyphaseChannelIndices(channelIndexes);
mMixerAssembler = new OneChannelMixerAssembler(gain);
mMixerAssembler.getMixer().setSampleRate(sampleRate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package io.github.dsheirer.dsp.filter.channelizer.output;

import io.github.dsheirer.sample.complex.ComplexSamples;
import io.github.dsheirer.source.heartbeat.HeartbeatManager;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -37,12 +38,14 @@ public class TwoChannelOutputProcessor extends ChannelOutputProcessor
* @param sampleRate of the output sample stream.
* @param channelIndexes containing two channel indices.
* @param gain to apply to output. Typically this is equal to the channelizer's channel count.
* @param heartbeatManager to be pinged on the dispatcher thread
*/
public TwoChannelOutputProcessor(double sampleRate, List<Integer> channelIndexes, float[] filter, float gain)
public TwoChannelOutputProcessor(double sampleRate, List<Integer> channelIndexes, float[] filter, float gain,
HeartbeatManager heartbeatManager)
{
//Set the frequency correction oscillator to 2 x output sample rate since we'll be correcting the frequency
//after synthesizing both input channels
super(2, sampleRate);
super(2, sampleRate, heartbeatManager);
setPolyphaseChannelIndices(channelIndexes);
mMixerAssembler = new TwoChannelMixerAssembler(gain);
mMixerAssembler.getMixer().setSampleRate(sampleRate);
Expand Down
9 changes: 0 additions & 9 deletions src/main/java/io/github/dsheirer/util/Dispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,6 @@ public Dispatcher(String threadName, int batchSize, long interval)
mInterval = interval;
}

/**
* Sets the heartbeat manager to receive heartbeat commands to distribute
* @param heartbeatManager to be commanded on the dispatch interval.
*/
public void setHeartbeatManager(HeartbeatManager heartbeatManager)
{
mHeartbeatManager = heartbeatManager;
}

/**
* Sets or changes the listener to receive buffers from this processor.
* @param listener to receive buffers
Expand Down

0 comments on commit 8d1f704

Please sign in to comment.