summaryrefslogtreecommitdiff
path: root/RTJava/benchmarks/RawSpeed/Fir/IOFirTester.java
blob: e464012249c3a8276bb116a7c72010dbf073a526 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//$Id$

package Fir;

import java.io.FileInputStream;
import java.io.DataInputStream;

public class IOFirTester extends PerformanceMeter {

    private DataInputStream mDataStream;

    private double mCoefficient[];
    private Fir mFir;
    private SampleQueue mQueue;

    private int mSampleNum;

    public IOFirTester(String sampleFileName,
                       int sampleNum,
                       String coeffFileName,
                       int coeffNum) throws java.io.IOException {

        FileInputStream ifile = new FileInputStream(coeffFileName);
        this.mDataStream = new DataInputStream(ifile);
        this.mCoefficient = new double[coeffNum];

        for (int i = 0; i < this.mCoefficient.length; i++)
            this.mCoefficient[i] = this.mDataStream.readDouble();

        ifile = new FileInputStream(sampleFileName);
        this.mDataStream = new DataInputStream(ifile);

        this.mQueue = new SampleQueue(sampleNum);
        this.mFir = new Fir(this.mCoefficient, this.mQueue);
        this.mSampleNum = sampleNum;
    }

    protected void Run() {
        try {
            for (int n = 0; n < this.mSampleNum; n++) {
                this.mQueue.AddItem(this.mDataStream.readDouble());
                this.mFir.Filter();
            }
        }
        catch (java.io.IOException e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }
}