package ru.r2cloud.jradio.blocks;

import java.io.IOException;

import ru.r2cloud.jradio.Context;
import ru.r2cloud.jradio.FloatInput;
import ru.r2cloud.jradio.source.SigSource;
import ru.r2cloud.jradio.source.Waveform;

public class ChannelModel implements FloatInput {

	private final FloatInput input;

	public ChannelModel(FloatInput input, float noiseVoltage, float frequencyOffsetValue, float epsilon, float[] taps, long noiseSeed) {
		FractionalResampler timingOffset = new FractionalResampler(input, 0.0f, epsilon);
		FIRFilterBlockComplex multipath = new FIRFilterBlockComplex(timingOffset, taps);
		SigSource frequencyOffset = new SigSource(Waveform.COMPLEX, 1, frequencyOffsetValue, 1.0);
		Multiply multiply = new Multiply(multipath, frequencyOffset);
		
		FastNoiseSourceComplex noise = new FastNoiseSourceComplex(noiseVoltage, noiseSeed, 1024 * 16);
		this.input = new Add(multiply, noise);
	}

	@Override
	public float readFloat() throws IOException {
		return input.readFloat();
	}

	@Override
	public void close() throws IOException {
		input.close();
	}

	@Override
	public Context getContext() {
		return input.getContext();
	}

}

@@ -440,38 +440,21 @@
 %0A%09%09F
-ractionalResampler timingOffse
+loatInput nex
 t = 
@@ -506,39 +506,35 @@
 ;%0A%09%09
-FIRFilterBlockComplex multipath
+if (taps != null) %7B%0A%09%09%09next
  = n
@@ -562,19 +562,11 @@
 lex(
-timingOffse
+nex
 t, t
@@ -571,16 +571,20 @@
  taps);%0A
+%09%09%7D%0A
 %09%09SigSou
@@ -707,17 +707,12 @@
 ply(
-multipath
+next
 , fr
@@ -727,18 +727,16 @@
 ffset);%0A
-%09%09
 %0A%09%09FastN

make multipath simulation optional