#39 WIP - finishes polyphase channel source processing of frequency

offset calculation and updating for channel frequency correction.
This commit is contained in:
Denny
2017-12-10 06:26:44 -05:00
parent d2085052f6
commit f38184fd83
4 changed files with 56 additions and 57 deletions

View File

@@ -303,14 +303,17 @@ public class PolyphaseChannelManager implements Listener<SourceEvent>
{
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(channelSource.getPolyphaseChannelOutputProcessor().getInputChannelCount() == indexes.size())
{
channelSource.getPolyphaseChannelOutputProcessor().setPolyphaseChannelIndices(indexes);
channelSource.setFrequency(centerFrequency);
}
else
{
channelSource.setPolyphaseChannelOutputProcessor(getOutputProcessor(indexes));
channelSource.setPolyphaseChannelOutputProcessor(getOutputProcessor(indexes), centerFrequency);
}
}
catch(IllegalArgumentException iae)

View File

@@ -36,6 +36,8 @@ public class PolyphaseChannelSource extends TunerChannelSource
private ComplexToComplexBufferAssembler mComplexBufferAssembler = new ComplexToComplexBufferAssembler(2500);
private IPolyphaseChannelOutputProcessor mPolyphaseChannelOutputProcessor;
private double mChannelSampleRate;
private long mCenterFrequency;
private long mFrequencyCorrection;
/**
* 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.
*
* @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
//channel output processor's buffer while we change out the processors.
@@ -108,6 +113,13 @@ public class PolyphaseChannelSource extends TunerChannelSource
{
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
public long getFrequencyCorrection()
{
IPolyphaseChannelOutputProcessor processor = mPolyphaseChannelOutputProcessor;
if(processor != null)
{
return processor.getFrequencyCorrection();
}
return 0;
return mFrequencyCorrection;
}
/**
@@ -171,24 +176,20 @@ public class PolyphaseChannelSource extends TunerChannelSource
*/
protected void setFrequencyCorrection(long value)
{
if(mPolyphaseChannelOutputProcessor != null)
{
mPolyphaseChannelOutputProcessor.setFrequencyCorrection(value);
broadcastConsumerSourceEvent(SourceEvent.frequencyCorrectionChange(value));
}
mFrequencyCorrection = value;
updateFrequencyOffset();
broadcastConsumerSourceEvent(SourceEvent.frequencyCorrectionChange(mFrequencyCorrection));
}
/**
* 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
*/
@Override
protected void setFrequency(long frequency)
{
if(mPolyphaseChannelOutputProcessor != null)
{
mPolyphaseChannelOutputProcessor.setFrequency(frequency);
}
mCenterFrequency = frequency;
setFrequencyCorrection(0);
}
@Override
@@ -200,4 +201,25 @@ public class PolyphaseChannelSource extends TunerChannelSource
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());
}
}
}

View File

@@ -60,16 +60,15 @@ public abstract class ChannelOutputProcessor implements IPolyphaseChannelOutputP
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
public void setFrequency(long frequency)
public void setFrequencyOffset(long frequencyOffset)
{
}
@Override
public long getFrequencyCorrection()
{
return 0;
mFrequencyCorrectionMixer.setFrequency(frequencyOffset);
mFrequencyCorrectionEnabled = (frequencyOffset != 0);
}
@Override
@@ -160,20 +159,6 @@ public abstract class ChannelOutputProcessor implements IPolyphaseChannelOutputP
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
*/

View File

@@ -40,23 +40,12 @@ public interface IPolyphaseChannelOutputProcessor
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
*/
void setFrequency(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();
void setFrequencyOffset(long frequency);
/**
* Indicates the number of input channels processed by this output processor