package ru.r2cloud.jradio;

public abstract class DopplerValueSource implements FloatValueSource {

	private final float correctPeriodSamples;
	private final long correctPeriodMillis;
	private final long satelliteFrequency;
	private long currentSample = 0;
	private long nextShift = 0;
	private float currentShift = 0;
	private long currentTimeMillis;
	private float shiftPerSample;

	protected DopplerValueSource(float sampleRate, long satelliteFrequency, long correctPeriodMillis, long startTimeMillis) {
		this.correctPeriodMillis = correctPeriodMillis;
		this.correctPeriodSamples = sampleRate * ((float)correctPeriodMillis / 1000);
		this.currentTimeMillis = startTimeMillis;
		this.satelliteFrequency = satelliteFrequency;
		this.nextShift = satelliteFrequency - getDopplerFrequency(satelliteFrequency, currentTimeMillis);
	}

	@Override
	public float getValue() {
		if (currentSample % correctPeriodSamples == 0) {
			currentShift = nextShift;
			currentTimeMillis += correctPeriodMillis;
			nextShift = satelliteFrequency - getDopplerFrequency(satelliteFrequency, currentTimeMillis);
			//linear shift between 2 frequency samples
			shiftPerSample = (nextShift - currentShift) / correctPeriodSamples;
			currentSample++;
			return currentShift;
		}
		currentSample++;
		currentShift += shiftPerSample;
		return currentShift;
	}

	public abstract long getDopplerFrequency(long satelliteFrequency, long currentTimeMillis);

}

@@ -108,21 +108,20 @@
 e final 
-f
 lo
-at
+ng
  correct
@@ -579,16 +579,24 @@
 mples = 
+(long) (
 sampleRa
@@ -608,16 +608,17 @@
 ((float)
+ 
 correctP
@@ -636,16 +636,17 @@
  / 1000)
+)
 ;%0A%09%09this
@@ -731,16 +731,66 @@
 quency;%0A
+%09%09this.currentSample = this.correctPeriodSamples;%0A
 %09%09this.n
@@ -947,9 +947,10 @@
 ple 
-%25
+%3E=
  cor
@@ -970,13 +970,8 @@
 ples
- == 0
 ) %7B%0A
@@ -1145,16 +1145,17 @@
 );%0A%09%09%09//
+ 
 linear s
@@ -1270,26 +1270,28 @@
 urrentSample
-++
+ = 0
 ;%0A%09%09%09return 

fix doppler correction