mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-19 12:07:27 -05:00
#39 WIP - finishes polyphase channel source processing of frequency
offset calculation and updating for channel frequency correction.
This commit is contained in:
@@ -303,14 +303,17 @@ public class PolyphaseChannelManager implements Listener<SourceEvent>
|
|||||||
{
|
{
|
||||||
List<Integer> indexes = mChannelCalculator.getChannelIndexes(channelSource.getTunerChannel());
|
List<Integer> indexes = mChannelCalculator.getChannelIndexes(channelSource.getTunerChannel());
|
||||||
|
|
||||||
|
long centerFrequency = mChannelCalculator.getCenterFrequencyForIndexes(indexes);
|
||||||
|
|
||||||
//If the indexes size is the same then update the current processor, otherwise create a new one
|
//If the indexes size is the same then update the current processor, otherwise create a new one
|
||||||
if(channelSource.getPolyphaseChannelOutputProcessor().getInputChannelCount() == indexes.size())
|
if(channelSource.getPolyphaseChannelOutputProcessor().getInputChannelCount() == indexes.size())
|
||||||
{
|
{
|
||||||
channelSource.getPolyphaseChannelOutputProcessor().setPolyphaseChannelIndices(indexes);
|
channelSource.getPolyphaseChannelOutputProcessor().setPolyphaseChannelIndices(indexes);
|
||||||
|
channelSource.setFrequency(centerFrequency);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
channelSource.setPolyphaseChannelOutputProcessor(getOutputProcessor(indexes));
|
channelSource.setPolyphaseChannelOutputProcessor(getOutputProcessor(indexes), centerFrequency);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(IllegalArgumentException iae)
|
catch(IllegalArgumentException iae)
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ public class PolyphaseChannelSource extends TunerChannelSource
|
|||||||
private ComplexToComplexBufferAssembler mComplexBufferAssembler = new ComplexToComplexBufferAssembler(2500);
|
private ComplexToComplexBufferAssembler mComplexBufferAssembler = new ComplexToComplexBufferAssembler(2500);
|
||||||
private IPolyphaseChannelOutputProcessor mPolyphaseChannelOutputProcessor;
|
private IPolyphaseChannelOutputProcessor mPolyphaseChannelOutputProcessor;
|
||||||
private double mChannelSampleRate;
|
private double mChannelSampleRate;
|
||||||
|
private long mCenterFrequency;
|
||||||
|
private long mFrequencyCorrection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Polyphase channelizer tuner channel source implementation. Adapts the channel array output samples from the
|
* Polyphase channelizer tuner channel source implementation. Adapts the channel array output samples from the
|
||||||
@@ -84,8 +86,11 @@ public class PolyphaseChannelSource extends TunerChannelSource
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets/updates the output processor for this channel source, replacing the existing output processor.
|
* Sets/updates the output processor for this channel source, replacing the existing output processor.
|
||||||
|
*
|
||||||
|
* @param outputProcessor to use
|
||||||
|
* @param frequency center for the channels processed by the output processor
|
||||||
*/
|
*/
|
||||||
public void setPolyphaseChannelOutputProcessor(IPolyphaseChannelOutputProcessor outputProcessor)
|
public void setPolyphaseChannelOutputProcessor(IPolyphaseChannelOutputProcessor outputProcessor, long frequency)
|
||||||
{
|
{
|
||||||
//Lock on the channel output processor to block the channel results processor thread from servicing the
|
//Lock on the channel output processor to block the channel results processor thread from servicing the
|
||||||
//channel output processor's buffer while we change out the processors.
|
//channel output processor's buffer while we change out the processors.
|
||||||
@@ -108,6 +113,13 @@ public class PolyphaseChannelSource extends TunerChannelSource
|
|||||||
{
|
{
|
||||||
existingProcessor.processChannelResults(mComplexBufferAssembler);
|
existingProcessor.processChannelResults(mComplexBufferAssembler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Finally, setup the frequency offset for the output processor and reset the frequency correction value
|
||||||
|
//to allow consumers to adjust and calculate a new frequency correction value, if needed.
|
||||||
|
mCenterFrequency = frequency;
|
||||||
|
mFrequencyCorrection = 0;
|
||||||
|
mPolyphaseChannelOutputProcessor.setFrequencyOffset(getFrequencyOffset());
|
||||||
|
broadcastConsumerSourceEvent(SourceEvent.frequencyCorrectionChange(mFrequencyCorrection));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,14 +165,7 @@ public class PolyphaseChannelSource extends TunerChannelSource
|
|||||||
@Override
|
@Override
|
||||||
public long getFrequencyCorrection()
|
public long getFrequencyCorrection()
|
||||||
{
|
{
|
||||||
IPolyphaseChannelOutputProcessor processor = mPolyphaseChannelOutputProcessor;
|
return mFrequencyCorrection;
|
||||||
|
|
||||||
if(processor != null)
|
|
||||||
{
|
|
||||||
return processor.getFrequencyCorrection();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -171,24 +176,20 @@ public class PolyphaseChannelSource extends TunerChannelSource
|
|||||||
*/
|
*/
|
||||||
protected void setFrequencyCorrection(long value)
|
protected void setFrequencyCorrection(long value)
|
||||||
{
|
{
|
||||||
if(mPolyphaseChannelOutputProcessor != null)
|
mFrequencyCorrection = value;
|
||||||
{
|
updateFrequencyOffset();
|
||||||
mPolyphaseChannelOutputProcessor.setFrequencyCorrection(value);
|
broadcastConsumerSourceEvent(SourceEvent.frequencyCorrectionChange(mFrequencyCorrection));
|
||||||
broadcastConsumerSourceEvent(SourceEvent.frequencyCorrectionChange(value));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the center frequency for the incoming sample stream channel results
|
* Sets the center frequency for the incoming sample stream channel results and resets frequency correction to zero.
|
||||||
* @param frequency in hertz
|
* @param frequency in hertz
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void setFrequency(long frequency)
|
protected void setFrequency(long frequency)
|
||||||
{
|
{
|
||||||
if(mPolyphaseChannelOutputProcessor != null)
|
mCenterFrequency = frequency;
|
||||||
{
|
setFrequencyCorrection(0);
|
||||||
mPolyphaseChannelOutputProcessor.setFrequency(frequency);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -200,4 +201,25 @@ public class PolyphaseChannelSource extends TunerChannelSource
|
|||||||
mPolyphaseChannelOutputProcessor.processChannelResults(mComplexBufferAssembler);
|
mPolyphaseChannelOutputProcessor.processChannelResults(mComplexBufferAssembler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates the frequency offset required to mix the incoming signal to the desired output baseband
|
||||||
|
*/
|
||||||
|
private long getFrequencyOffset()
|
||||||
|
{
|
||||||
|
return getTunerChannel().getFrequency() - mCenterFrequency + mFrequencyCorrection;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the frequency offset being applied by the output processor. Calculates the offset using the center
|
||||||
|
* frequency of the incoming polyphase channel results and the desired output channel frequency adjusted by any
|
||||||
|
* requested frequency correction value.
|
||||||
|
*/
|
||||||
|
private void updateFrequencyOffset()
|
||||||
|
{
|
||||||
|
synchronized(mPolyphaseChannelOutputProcessor)
|
||||||
|
{
|
||||||
|
mPolyphaseChannelOutputProcessor.setFrequencyOffset(getFrequencyOffset());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,16 +60,15 @@ public abstract class ChannelOutputProcessor implements IPolyphaseChannelOutputP
|
|||||||
mChannelResultsQueue = new OverflowableTransferQueue<>((int)(sampleRate * 3), (int)(sampleRate * 0.5));
|
mChannelResultsQueue = new OverflowableTransferQueue<>((int)(sampleRate * 3), (int)(sampleRate * 0.5));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the frequency offset to apply to the incoming samples to mix the desired signal to baseband.
|
||||||
|
* @param frequencyOffset in hertz
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setFrequency(long frequency)
|
public void setFrequencyOffset(long frequencyOffset)
|
||||||
{
|
{
|
||||||
|
mFrequencyCorrectionMixer.setFrequency(frequencyOffset);
|
||||||
}
|
mFrequencyCorrectionEnabled = (frequencyOffset != 0);
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getFrequencyCorrection()
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -160,20 +159,6 @@ public abstract class ChannelOutputProcessor implements IPolyphaseChannelOutputP
|
|||||||
mFrequencyCorrectionMixer.quadrature());
|
mFrequencyCorrectionMixer.quadrature());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Specifies a frequency correction value to be applied to channel samples output from this polyphase channelizer
|
|
||||||
* output processor.
|
|
||||||
*
|
|
||||||
* @param frequencyCorrection offset value
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setFrequencyCorrection(long frequencyCorrection)
|
|
||||||
{
|
|
||||||
mFrequencyCorrectionMixer.setFrequency(frequencyCorrection);
|
|
||||||
|
|
||||||
mFrequencyCorrectionEnabled = (frequencyCorrection != 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates if this channel has a frequency correction offset
|
* Indicates if this channel has a frequency correction offset
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -40,23 +40,12 @@ public interface IPolyphaseChannelOutputProcessor
|
|||||||
void processChannelResults(ComplexSampleListener listener);
|
void processChannelResults(ComplexSampleListener listener);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the center frequency of the incoming channel results samples
|
* 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.
|
||||||
|
*
|
||||||
* @param frequency in hertz
|
* @param frequency in hertz
|
||||||
*/
|
*/
|
||||||
void setFrequency(long frequency);
|
void setFrequencyOffset(long frequency);
|
||||||
|
|
||||||
/**
|
|
||||||
* Specifies the frequency correction (+/-) that should be applied to samples extracted from the polyphase
|
|
||||||
* channelizer output results.
|
|
||||||
*
|
|
||||||
* @param frequencyCorrection correction value
|
|
||||||
*/
|
|
||||||
void setFrequencyCorrection(long frequencyCorrection);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Current frequency correction value.
|
|
||||||
*/
|
|
||||||
long getFrequencyCorrection();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates the number of input channels processed by this output processor
|
* Indicates the number of input channels processed by this output processor
|
||||||
|
|||||||
Reference in New Issue
Block a user