// Path: src/com/bfv/model/BufferData.java
// public class BufferData {
//     private int position;
//     private double[] data;
// 
// 
//     public BufferData(int dataSize) {
//         this.position = 0;
//         this.data = new double[dataSize];
//     }
// 
//     public int getPosition() {
//         return position;
//     }
// 
//     public void setPosition(int position) {
//         this.position = position;
//     }
// 
//     public double[] getData() {
//         return data;
//     }
// 
// 
// }
// 
// Path: src/com/bfv/util/ArrayUtil.java
// public class ArrayUtil {
//     public static double[] getMaxValue(double[] val) {
//         double max = Double.MIN_VALUE;
//         int index = 0;
//         for (int i = 0; i < val.length; i++) {
//             double v = val[i];
//             if (v > max) {
//                 max = v;
//                 index = i;
//             }
//         }
//         return new double[]{max, index};
// 
//     }
// 
//     public static double[] getMinValue(double[] val) {
//         double min = Double.MAX_VALUE;
//         int index = 0;
//         for (int i = 0; i < val.length; i++) {
//             double v = val[i];
//             if (v < min) {
//                 min = v;
//                 index = i;
//             }
//         }
//         return new double[]{min, index};
// 
//     }
// 
//     public static double[] copy(double[] dataToCopy) {
//         if (dataToCopy == null) {
//             return null;
//         }
// 
//         double[] ret = new double[dataToCopy.length];
//         System.arraycopy(dataToCopy, 0, ret, 0, dataToCopy.length);
// 
//         return ret;
//     }
// }


import com.bfv.model.BufferData;
import com.bfv.util.ArrayUtil;
import java.util.ArrayList;

/*
 BlueFlyVario flight instrument - http://www.alistairdickie.com/blueflyvario/
 Copyright (C) 2011-2012 Alistair Dickie

 BlueFlyVario is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 BlueFlyVario is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with BlueFlyVario.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.bfv;



public class DataBuffer {
    private ArrayList<DataSource> dataSources;
    private ArrayList<BufferData> data;
    private int bufferSize;
    private int position;
    private boolean full;
    private boolean empty;
    private int sampleRate;
    private int sampleRateCounter;


    public DataBuffer(ArrayList<DataSource> dataSources, int bufferSize, int sampleRate) {
        this.dataSources = dataSources;
        this.bufferSize = bufferSize;
        this.sampleRate = sampleRate;
        initBuffer();

    }


// Path: src/com/bfv/model/BufferData.java
// public class BufferData {
//     private int position;
//     private double[] data;
// 
// 
//     public BufferData(int dataSize) {
//         this.position = 0;
//         this.data = new double[dataSize];
//     }
// 
//     public int getPosition() {
//         return position;
//     }
// 
//     public void setPosition(int position) {
//         this.position = position;
//     }
// 
//     public double[] getData() {
//         return data;
//     }
// 
// 
// }
// 
// Path: src/com/bfv/util/ArrayUtil.java
// public class ArrayUtil {
//     public static double[] getMaxValue(double[] val) {
//         double max = Double.MIN_VALUE;
//         int index = 0;
//         for (int i = 0; i < val.length; i++) {
//             double v = val[i];
//             if (v > max) {
//                 max = v;
//                 index = i;
//             }
//         }
//         return new double[]{max, index};
// 
//     }
// 
//     public static double[] getMinValue(double[] val) {
//         double min = Double.MAX_VALUE;
//         int index = 0;
//         for (int i = 0; i < val.length; i++) {
//             double v = val[i];
//             if (v < min) {
//                 min = v;
//                 index = i;
//             }
//         }
//         return new double[]{min, index};
// 
//     }
// 
//     public static double[] copy(double[] dataToCopy) {
//         if (dataToCopy == null) {
//             return null;
//         }
// 
//         double[] ret = new double[dataToCopy.length];
//         System.arraycopy(dataToCopy, 0, ret, 0, dataToCopy.length);
// 
//         return ret;
//     }
// }


// Path: src/com/bfv/DataBuffer.java
import com.bfv.model.BufferData;
import com.bfv.util.ArrayUtil;
import java.util.ArrayList;

/*
 BlueFlyVario flight instrument - http://www.alistairdickie.com/blueflyvario/
 Copyright (C) 2011-2012 Alistair Dickie

 BlueFlyVario is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 BlueFlyVario is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with BlueFlyVario.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.bfv;



public class DataBuffer {
    private ArrayList<DataSource> dataSources;
    private ArrayList<BufferData> data;
    private int bufferSize;
    private int position;
    private boolean full;
    private boolean empty;
    private int sampleRate;
    private int sampleRateCounter;


    public DataBuffer(ArrayList<DataSource> dataSources, int bufferSize, int sampleRate) {
        this.dataSources = dataSources;
        this.bufferSize = bufferSize;
        this.sampleRate = sampleRate;
        initBuffer();

    }


    public synchronized void initBuffer() {
