diff --git a/src/controller/channel/ProcessingChain.java b/src/controller/channel/ProcessingChain.java index 33330db7..c2241957 100644 --- a/src/controller/channel/ProcessingChain.java +++ b/src/controller/channel/ProcessingChain.java @@ -376,7 +376,11 @@ public class ProcessingChain implements Listener { 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 ); diff --git a/src/decode/DecodeEditor.java b/src/decode/DecodeEditor.java index 9825d225..9f1b40fd 100644 --- a/src/decode/DecodeEditor.java +++ b/src/decode/DecodeEditor.java @@ -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 } } diff --git a/src/decode/config/DecodeConfiguration.java b/src/decode/config/DecodeConfiguration.java index e99e2ea9..ed089e13 100644 --- a/src/decode/config/DecodeConfiguration.java +++ b/src/decode/config/DecodeConfiguration.java @@ -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; diff --git a/src/dsp/afc/AutomaticFrequencyControl.java b/src/dsp/afc/AutomaticFrequencyControl.java index 4912babf..6bc8b5f0 100644 --- a/src/dsp/afc/AutomaticFrequencyControl.java +++ b/src/dsp/afc/AutomaticFrequencyControl.java @@ -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 diff --git a/src/source/tuner/TunerController.java b/src/source/tuner/TunerController.java index cdca2734..27621896 100644 --- a/src/source/tuner/TunerController.java +++ b/src/source/tuner/TunerController.java @@ -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() )