Frequency limit for Automatic Frequency Control to prevent the controller from walking too far.

Defaults to a maximum of 3kHz, but can be set to as high as 15 kHz.
This commit is contained in:
dennis.sheirer
2014-10-26 22:36:06 +00:00
parent 08f321fda4
commit d1ab661754
5 changed files with 71 additions and 9 deletions

View File

@@ -376,7 +376,11 @@ public class ProcessingChain implements Listener<Message>
{
TunerChannelSource tcs = (TunerChannelSource)mSource;
mAFC = new AutomaticFrequencyControl( tcs );
int maximumCorrection = mChannel
.getDecodeConfiguration().getAFCMaximumCorrection();
mAFC = new AutomaticFrequencyControl( tcs,
maximumCorrection );
/* Register AFC to receive frequency change events */
tcs.addListener( mAFC );

View File

@@ -21,6 +21,13 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JSpinner;
import javax.swing.SpinnerModel;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import controller.Editor;
import decode.config.DecodeConfiguration;
@@ -32,6 +39,7 @@ public class DecodeEditor extends Editor
protected DecodeConfiguration mConfig;
protected JCheckBox mAFC;
protected JSpinner mAFCMaximumCorrection;
public DecodeEditor( DecodeConfiguration config )
{
@@ -49,8 +57,42 @@ public class DecodeEditor extends Editor
mConfig.setAFC( mAFC.isSelected() );
}
} );
mAFC.setToolTipText( "AFC automatically adjusts the center "
+ "frequency of the channel to correct/compensate for "
+ "inaccuracies and frequency drift in the tuner" );
add( mAFC, "wrap" );
add( mAFC, "span" );
int initial = mConfig.getAFCMaximumCorrection();
SpinnerModel model = new SpinnerNumberModel( initial, 0, 15000, 1 );
mAFCMaximumCorrection = new JSpinner( model );
JSpinner.NumberEditor editor =
(JSpinner.NumberEditor)mAFCMaximumCorrection.getEditor();
editor.getTextField().setHorizontalAlignment( SwingConstants.CENTER );
mAFCMaximumCorrection.setToolTipText( "Sets the maximum frequency "
+ "correction value in hertz, 0 - 15kHz" );
mAFCMaximumCorrection.addChangeListener( new ChangeListener()
{
@Override
public void stateChanged( ChangeEvent e )
{
int value = ((SpinnerNumberModel)mAFCMaximumCorrection
.getModel()).getNumber().intValue();
mConfig.setAFCMaximumCorrection( value );
save();
}
} );
add( mAFCMaximumCorrection );
add( new JLabel( "Correction Limit Hz" ), "growx, push" );
}
}
@@ -62,14 +104,12 @@ public class DecodeEditor extends Editor
@Override
public void save()
{
// TODO Auto-generated method stub
}
@Override
public void reset()
{
// TODO Auto-generated method stub
}
}

View File

@@ -35,6 +35,7 @@ public abstract class DecodeConfiguration extends Configuration
{
private DecoderType mDecoderType = DecoderType.NBFM;
private boolean mAFCEnabled = true;
private int mAFCMaxCorrection = 3000;
public DecodeConfiguration()
{
@@ -67,6 +68,16 @@ public abstract class DecodeConfiguration extends Configuration
mAFCEnabled = enabled;
}
public int getAFCMaximumCorrection()
{
return mAFCMaxCorrection;
}
public void setAFCMaximumCorrection( int max )
{
mAFCMaxCorrection = max;
}
public boolean supportsAFC()
{
return true;

View File

@@ -24,6 +24,7 @@ public class AutomaticFrequencyControl implements SimplexSampleListener,
private int mSkipThreshold = 4;
private int mErrorCorrection = 0;
private long mCurrentFrequency;
private int mMaximumCorrection;
private FrequencyChangeListener mListener;
public enum Mode
@@ -31,9 +32,11 @@ public class AutomaticFrequencyControl implements SimplexSampleListener,
NORMAL,FAST;
}
public AutomaticFrequencyControl( FrequencyChangeListener listener )
public AutomaticFrequencyControl( FrequencyChangeListener listener,
int maximumCorrection )
{
mListener = listener;
mMaximumCorrection = maximumCorrection;
}
public void dispose()
@@ -150,6 +153,14 @@ public class AutomaticFrequencyControl implements SimplexSampleListener,
if( correction != 0 )
{
mErrorCorrection -= correction;
if( Math.abs( mErrorCorrection ) > mMaximumCorrection )
{
mErrorCorrection = ( mErrorCorrection < 0 ) ?
-mMaximumCorrection :
mMaximumCorrection;
}
dispatch();
}
else

View File

@@ -135,10 +135,6 @@ public abstract class TunerController implements Tunable
long maxLockedFrequency = mTunedChannels
.get( mTunedChannels.size() - 1 ).getMaxFrequency();
mLog.debug( "Tuner Controller min [" + minLockedFrequency +
"] max [" + maxLockedFrequency +
"] bw [" + getBandwidth() + "]" );
//Requested channel is higher than min locked frequency
if( minLockedFrequency <= channel.getMinFrequency() &&
( channel.getMaxFrequency() - minLockedFrequency ) <= getBandwidth() )