Hi

I have a java code that records the audio in my disk but the sound quality is poor (sound of wind, swell ...) and I want to filter the sound passed through a microphone, I did some research on it and then I 'I found a source Sound Filtering For The Masses that does the filtering, my question is how to integrate this code in mine to filter the sound. I would like use the case3 / * bandpass * /

My source for recording audio
Java Code:
package com.javasrc.audio;
import javax.sound.sampled.*;

import java.io.File;
import java.io.IOException;
import java.util.Scanner;

/** Sample audio recorder */
public class Recorder extends Thread
{
	/** The TargetDataLine that we'll use to read data from */
	private final TargetDataLine line;
	
	/** The audio format type that we'll encode the audio data with */
	private final AudioFileFormat.Type targetType = AudioFileFormat.Type.WAVE;
	
	/** The AudioInputStream that we'll read the audio data from */
	private final AudioInputStream inputStream;
	
	/** The file that we're going to write data out to */
	private File file;

	/** 
	* Creates a new Audio Recorder
	* @param outputFilename
	* @throws LineUnavailableException 
	*/
	public Recorder(String outputFilename) throws LineUnavailableException
	{
		// Create an AudioFormat that specifies how the recording will be performed
		// In this example we'll 44.1Khz, 16-bit, stereo
		AudioFormat audioFormat = new AudioFormat
		(
			AudioFormat.Encoding.PCM_SIGNED, // Encoding technique
			44100.0F, // Sample Rate
			16, // Number of bits in each channel
			2, // Number of channels (2=stereo)
			4, // Number of bytes in each frame
			44100.0F, // Number of frames per second
			false // Big-endian (true) or little-endian (false)
		);  
	
		// Create our TargetDataLine that will be used to read audio data by first
		// creating a DataLine instance for our audio format type
		DataLine.Info info = new DataLine.Info(TargetDataLine.class, audioFormat);
	
		// Next we ask the AudioSystem to retrieve a line that matches the
		// DataLine Info
		line = (TargetDataLine) AudioSystem.getLine(info);
	
		// Open the TargetDataLine with the specified format
		line.open(audioFormat);
	
		// Create an AudioInputStream that we can use to read from the line
		inputStream = new AudioInputStream(line);
	
		// Create the output file
		file = new File(outputFilename);
	}
	
	public void startRecording()
	{
		// Start the TargetDataLine
		line.start();
	
		// Start our thread
		start();
	}
	
	public void stopRecording()
	{
		// Stop and close the TargetDataLine
		line.stop();
		line.close();
	}
	
	public void run()
	{
		// Ask the AudioSystem class to write audio data from the audio input stream
		// to our file in the specified data type (PCM 44.1Khz, 16-bit, stereo)
		try 
		{
			AudioSystem.write(inputStream,targetType,file);
		} 
		catch (IOException e)
		{
			e.printStackTrace();
		}	
	}
	
	public String getPath()
	{
		return file.getAbsolutePath();
	}
	
	public static void pressEnter(String text)
	{
		System.out.println(text);
		new Scanner(System.in).nextLine();
	}
	
	public static void main(String...args)
	{
		// Setting fileName
		
	//	Recorder r = new Recorder(fileName);
		
		String fileName = "default.wav"; // default;
		
		if(args.length == 0)
			
			System.out.println("Usage: java Recorder <filename>\n" +
					"Default file will be used\n");
		else
			fileName = args[0];
		
		try 
		{
			// Create a recorder that writes WAVE data to the specified filename
			Recorder r = new Recorder(fileName);
			
			// Start the recorder
			pressEnter("Press ENTER to start recording");
			r.startRecording();
			
			// Stop the recorder
		    pressEnter("Press ENTER to stop recording");
			r.stopRecording();
	
			System.out.println("Recording complete : "+r.getPath());
		} 
		catch (LineUnavailableException e) 
		{
			e.printStackTrace();
		}
	}
	
	
}
and the filring source is :
Java Code:
	
    double i1, i2, o1, o2;  /* temporary variables */
    double a0, a1, a2;  /* coefficients */
    double b0, b1, b2;  /* coefficients */
    double f;         /* last Frequency used */
    double q;         /* last Q used */
    double g;         /* last Gain used */
    long t;  /* last Type used */

    static int maxfilterunits=10;

	double FilterCell(long Unit, double Input, double Frequency, double Q, double Gain, int Type)
	{
		/* --------------------------------------------------------------- */
		double Output=0,S,omega,A,sn,cs,alpha,beta,temp1,temp2,temp3,temp4;
		/* -- check if frequency, Q, gain or type has changed.. and, if so, update coefficients */
		if ( ( Frequency != f ) || ( Q != q ) || ( Gain != g ) || ( Type != t ) ) {
			f = Frequency; q = Q; g = Gain; t = Type; /* remember last frequency, q, gain and type */
			switch (Type) {
			case 0:                                               /* no filtering */
				b0 = Math.pow( 10.0, Gain / 20.0 );               /* convert from dB to linear */
				break;
			case 1:                                               /* lowpass */
				Gain = Math.pow( 10.0, Gain / 20.0 );                   /* convert from dB to linear */
				omega = ( Math.PI*2 * Frequency ) / 44100;
				sn = Math.sin( omega ); cs = Math.cos( omega );
				alpha = sn / ( 2.0 * Q );
				a0 = 1.0 / ( 1.0 + alpha );
				a1 = ( -2.0 * cs ) * a0;
				a2 = ( 1.0 - alpha ) * a0;
				b1 = ( 1.0 - cs ) * a0 * Gain;
				b0 = b1 * 0.5;
				break;
			case 2:                                               /* highpass */
				Gain = Math.pow( 10.0, Gain / 20.0 );                   /* convert from dB to linear */
				omega = ( Math.PI*2 * Frequency ) / 44100;
				sn = Math.sin( omega ); cs = Math.cos( omega );
				alpha = sn / ( 2.0 * Q );
				a0 = 1.0 / ( 1.0 + alpha );
				a1 = ( -2.0 * cs ) * a0;
				a2 = ( 1.0 - alpha ) * a0;
				b1 = -( 1.0 + cs ) * a0 * Gain;
				b0 = -b1 * 0.5;
				break;
			case 3:                                               /* bandpass */
				Gain = Math.pow( 10.0, Gain / 20.0 );                   /* convert from dB to linear */
				omega = ( Math.PI*2 * Frequency ) / 44100;
				sn =Math.sin( omega ); cs = Math.cos( omega );
				alpha = sn / ( 2.0 * Q );
				a0 = 1.0 / ( 1.0 + alpha );
				a1 = ( -2.0 * cs ) * a0;
				a2 = ( 1.0 - alpha ) * a0;
				b0 = alpha * a0 * Gain;
				break;
			case 4:                                               /* notch */
				Gain = Math.pow( 10.0, Gain / 20.0 );                   /* convert from dB to linear */
				omega = ( Math.PI*2 * Frequency ) / 44100;
				sn = Math.sin( omega ); cs = Math.cos( omega );
				alpha = sn / ( 2.0 * Q );
				a0 = 1.0 / ( 1.0 + alpha );
				a1 = ( -2.0 * cs ) * a0;
				a2 = ( 1.0 - alpha ) * a0;
				b0 = a0 * Gain;
				b1 = a1 * Gain;
				break;
			case 5:                                               /* lowshelf */
				/* "shelf slope" 1.0 = max slope, because neither Q nor bandwidth is used in */
				/* those filters (note: true only for lowshelf and highshelf, not peaking). */
				S = 1.0; /* used only by lowshelf and highshelf */
				A = Math.pow( 10.0 , ( Gain / 40.0 ) );                 /* Gain is expressed in dB */
				omega = ( Math.PI*2 * Frequency ) / 44100;
				sn = Math.sin( omega ); cs = Math.cos( omega );
				temp1 = A + 1.0; temp2 = A - 1.0; temp3 = temp1 * cs; temp4 = temp2 * cs;
				beta = sn * Math.sqrt( ( A * A + 1.0 ) / S - temp2 * temp2 );
				a0 = 1.0 / ( temp1 + temp4 + beta );
				a1 = ( -2.0 * ( temp2 + temp3 ) ) * a0;
				a2 = ( temp1 + temp4 - beta ) * a0;
				b0 = ( A * ( temp1 - temp4 + beta ) ) * a0;
				b1 = ( 2.0 * A * ( temp2 - temp3 ) ) * a0;
				b2 = ( A * ( temp1 - temp4 - beta ) ) * a0;
				break;
			case 6:                                               /* highshelf */
				/* "shelf slope" 1.0 = max slope, because neither Q nor bandwidth is used in */
				/* those filters (note: true only for lowshelf and highshelf, not peaking). */
				S = 1.0; /* used only by lowshelf and highshelf */
				A = Math.pow( 10.0, ( Gain / 40.0 ) );                  /* Gain is expressed in dB */
				omega = ( Math.PI*2 * Frequency ) / 44100;
				sn = Math.sin( omega ); cs = Math.cos( omega );
				temp1 = A + 1.0; temp2 = A - 1.0; temp3 = temp1 * cs; temp4 = temp2 * cs;
				beta = sn * Math.sqrt( ( A * A + 1.0 ) / S - temp2 * temp2 );
				a0 = 1.0 / ( temp1 - temp4 + beta );
				a1 = ( 2.0 * ( temp2 - temp3 ) ) * a0;
				a2 = ( temp1 - temp4 - beta ) * a0;
				b0 = ( A * ( temp1 + temp4 + beta ) ) * a0;
				b1 = ( -2.0 * A * ( temp2 + temp3 ) ) * a0;
				b2 = ( A * ( temp1 + temp4 - beta ) ) * a0;
				break;
			case 7:                                               /* peaking */
				A = Math.pow( 10.0, ( Gain / 40.0 ) );                  /* Gain is expressed in dB */
				omega = ( Math.PI*2 * Frequency ) / 44100;
				sn = Math.sin( omega ); cs = Math.cos( omega );
				alpha = sn / ( 2.0 * Q );
				temp1 = alpha * A;
				temp2 = alpha / A;
				a0 = 1.0 / ( 1.0 + temp2 );
				a1 = ( -2.0 * cs ) * a0;
				a2 = ( 1.0 - temp2 ) * a0;
				b0 = ( 1.0 + temp1 ) * a0;
				b2 = ( 1.0 - temp1 ) * a0;
				break;
			}
		}
		/* -- filter loop: if you don't change the parameters of the filter dynamically, ~only this code will be executed. */
		switch (Type) {
		case 0:                                                  /* no filtering */
			Output = b0*Input;
			Output = Input;
			break;
		case 1:                                                  /* lowpass */
		case 2:                                                  /* highpass */
			Output = b0*Input + b1*i1 + b0*i2 - a1*o1 - a2*o2;
			break;
		case 3:                                                  /* bandpass */
			
			Output = b0*Input - b0*i2 - a1*o1 - a2*o2;
			break;
		case 4:                                                  /* notch */
			Output = b0*Input + b1*i1 + b0*i2 - a1*o1 - a2*o2;
			break;
		case 5:                                                  /* low shelving */
		case 6:                                                  /* high shelving */
			Output = b0*Input + b1*i1 + b2*i2 - a1*o1 - a2*o2;
			break;
		case 7:                                                  /* peaking */
			Output = b0*Input + a1*i1 + b2*i2 - a1*o1 - a2*o2;
			break;
		}
		o2=o1; o1=Output; i2=i1; i1=Input; /* update variables for recursion */
		return(Output);
	}
	


}
Thank you