package VQVAD;

import java.util.ArrayList;

import edu.cmu.sphinx.frontend.BaseDataProcessor;
import edu.cmu.sphinx.frontend.Data;
import edu.cmu.sphinx.frontend.DataProcessingException;
import edu.cmu.sphinx.frontend.DataProcessor;
import edu.cmu.sphinx.frontend.DoubleData;
import edu.cmu.sphinx.frontend.FrontEnd;
import edu.cmu.sphinx.frontend.denoise.Denoise;
import edu.cmu.sphinx.frontend.frequencywarp.MelFrequencyFilterBank;
import edu.cmu.sphinx.frontend.transform.DiscreteCosineTransform;
import edu.cmu.sphinx.frontend.transform.DiscreteCosineTransform2;
import edu.cmu.sphinx.frontend.transform.DiscreteFourierTransform;
import edu.cmu.sphinx.util.props.S4Double;
import edu.cmu.sphinx.util.props.S4Integer;

public class MFCCPipeline extends BaseDataProcessor {

	final protected FrontEnd frontend;
	protected SingleDataBuffer singleDataBuffer;

	public MFCCPipeline(double minFreq, double maxFreq, int numFilters) {
		final ArrayList<DataProcessor> pipeline = new ArrayList<DataProcessor>();

		singleDataBuffer = new SingleDataBuffer();

		Denoise denoise;
		// Load default configuration for Denoise component.
		try {
			denoise = new Denoise(
				0.7, /*Denoise.class.getField("LAMBDA_POWER")
				        .getAnnotation(S4Double.class)
				        .defaultValue(),*/
				0.995, /*Denoise.class.getField("LAMBDA_A")
				        .getAnnotation(S4Double.class)
				        .defaultValue(),*/
				0.85, /*Denoise.class.getField("LAMBDA_B")
				        .getAnnotation(S4Double.class)
				        .defaultValue(),*/
				Denoise.class.getField("LAMBDA_T")
				        .getAnnotation(S4Double.class)
				        .defaultValue(),
				Denoise.class.getField("MU_T")
				        .getAnnotation(S4Double.class)
				        .defaultValue(),
				4, /*Denoise.class.getField("EXCITATION_THRESHOLD")
				        .getAnnotation(S4Double.class)
				        .defaultValue(),*/
				200, /*Denoise.class.getField("MAX_GAIN")
				        .getAnnotation(S4Double.class)
				        .defaultValue(),*/
				10 /*Denoise.class.getField("SMOOTH_WINDOW")
				        .getAnnotation(S4Integer.class)
				        .defaultValue()*/);
		} catch (NoSuchFieldException e) {
			throw new RuntimeException("Programming error: field does not exist. Original exception:" + e.getMessage());
		} catch (SecurityException e) {
			throw new RuntimeException("VM does not allow access to our own annotations. Original exception:" + e.getMessage());
		}

		pipeline.add(singleDataBuffer);
		pipeline.add(new DiscreteFourierTransform());
		pipeline.add(new MelFrequencyFilterBank(minFreq, maxFreq, numFilters));
		pipeline.add(denoise);
		pipeline.add(new DiscreteCosineTransform2(numFilters, 12));

		frontend = new FrontEnd(pipeline);
	}

	@Override
	public Data getData() throws DataProcessingException {
		frontend.setPredecessor(getPredecessor());

		Data buffered = singleDataBuffer.getBufferedData();
		Data processed = frontend.getData();

		if (buffered instanceof DoubleData && processed instanceof DoubleData) {
			return new MFCCPacket((DoubleData) buffered, (DoubleData) processed);
		}

		return processed;
	}
}

@@ -346,158 +346,44 @@
 end.
-denoise.Denoise;%0Aimport edu.cmu.sphinx.frontend.frequencywarp.MelFrequencyFilterBank;%0Aimport edu.cmu.sphinx.frontend.transform.DiscreteCosineTransform
+frequencywarp.MelFrequencyFilterBank
 ;%0Aim
@@ -517,95 +517,8 @@
 orm;
-%0Aimport edu.cmu.sphinx.util.props.S4Double;%0Aimport edu.cmu.sphinx.util.props.S4Integer;
 %0A%0Apu
@@ -853,1384 +853,8 @@
 %0A%0A%09%09
-Denoise denoise;%0A%09%09// Load default configuration for Denoise component.%0A%09%09try %7B%0A%09%09%09denoise = new Denoise(%0A%09%09%09%090.7, /*Denoise.class.getField(%22LAMBDA_POWER%22)%0A%09%09%09%09        .getAnnotation(S4Double.class)%0A%09%09%09%09        .defaultValue(),*/%0A%09%09%09%090.995, /*Denoise.class.getField(%22LAMBDA_A%22)%0A%09%09%09%09        .getAnnotation(S4Double.class)%0A%09%09%09%09        .defaultValue(),*/%0A%09%09%09%090.85, /*Denoise.class.getField(%22LAMBDA_B%22)%0A%09%09%09%09        .getAnnotation(S4Double.class)%0A%09%09%09%09        .defaultValue(),*/%0A%09%09%09%09Denoise.class.getField(%22LAMBDA_T%22)%0A%09%09%09%09        .getAnnotation(S4Double.class)%0A%09%09%09%09        .defaultValue(),%0A%09%09%09%09Denoise.class.getField(%22MU_T%22)%0A%09%09%09%09        .getAnnotation(S4Double.class)%0A%09%09%09%09        .defaultValue(),%0A%09%09%09%094, /*Denoise.class.getField(%22EXCITATION_THRESHOLD%22)%0A%09%09%09%09        .getAnnotation(S4Double.class)%0A%09%09%09%09        .defaultValue(),*/%0A%09%09%09%09200, /*Denoise.class.getField(%22MAX_GAIN%22)%0A%09%09%09%09        .getAnnotation(S4Double.class)%0A%09%09%09%09        .defaultValue(),*/%0A%09%09%09%0910 /*Denoise.class.getField(%22SMOOTH_WINDOW%22)%0A%09%09%09%09        .getAnnotation(S4Integer.class)%0A%09%09%09%09        .defaultValue()*/);%0A%09%09%7D catch (NoSuchFieldException e) %7B%0A%09%09%09throw new RuntimeException(%22Programming error: field does not exist. Original exception:%22 + e.getMessage());%0A%09%09%7D catch (SecurityException e) %7B%0A%09%09%09throw new RuntimeException(%22VM does not allow access to our own annotations. Original exception:%22 + e.getMessage());%0A%09%09%7D%0A%0A%09%09
 pipe
@@ -925,16 +925,62 @@
 ansform(
+));%0A%09%09pipeline.add(new Denoise(0.7, 0.995, 0.5
 ));%0A%09%09pi
@@ -1053,33 +1053,8 @@
 ));%0A
-%09%09pipeline.add(denoise);%0A
 %09%09pi

Use specsub denoise in MFCC pipeline