mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 08:37:25 -05:00
fix src folder structure
This commit is contained in:
@@ -1,107 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 Dennis Sheirer
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
package buffer;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
|
||||
/**
|
||||
* Circular Buffer - implements a circular buffer with a method to get the
|
||||
* current head of the buffer, and put a new value in its place at the same
|
||||
* time
|
||||
*
|
||||
* Also provides averaging over the elements in the buffer
|
||||
*/
|
||||
public class BooleanAveragingBuffer {
|
||||
|
||||
private boolean[] mBuffer;
|
||||
private int mBufferPointer;
|
||||
|
||||
public BooleanAveragingBuffer( int length )
|
||||
{
|
||||
mBuffer = new boolean[ length ];
|
||||
|
||||
//Preload the array with false values
|
||||
Arrays.fill( mBuffer, false );
|
||||
}
|
||||
|
||||
public boolean get( boolean newValue )
|
||||
{
|
||||
//Fetch current boolean value
|
||||
boolean retVal = mBuffer[ mBufferPointer ];
|
||||
|
||||
//Load the new value into the buffer
|
||||
put( newValue );
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the newValue into this buffer and adjusts the buffer pointer
|
||||
* to prepare for the next get/put cycle
|
||||
*/
|
||||
private void put( boolean newValue )
|
||||
{
|
||||
//Store the new value to the buffer
|
||||
mBuffer[ mBufferPointer ] = newValue;
|
||||
|
||||
//Increment the buffer pointer
|
||||
mBufferPointer++;
|
||||
|
||||
//Wrap the buffer pointer around to 0 when necessary
|
||||
if( mBufferPointer >= mBuffer.length )
|
||||
{
|
||||
mBufferPointer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the newValue into the buffer, calculates the average
|
||||
* and returns that average from this method
|
||||
*
|
||||
* This effectively performs low-pass filtering
|
||||
*/
|
||||
public boolean getAverage( boolean newValue )
|
||||
{
|
||||
//Load the new value into the buffer
|
||||
put( newValue );
|
||||
|
||||
int trueCount = 0;
|
||||
|
||||
for( int x = 0; x < mBuffer.length; x++ )
|
||||
{
|
||||
if( mBuffer[ x ] )
|
||||
{
|
||||
trueCount++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the number of true values in the buffer is
|
||||
* more than half, return true, otherwise, false
|
||||
*/
|
||||
if( trueCount > (int)( mBuffer.length / 2 ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
package buffer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import sample.Listener;
|
||||
|
||||
public class CircularBuffer<T> implements Listener<T>
|
||||
{
|
||||
private ArrayList<T> mElements;
|
||||
private Listener<T> mListener;
|
||||
private int mPointer;
|
||||
private int mSize;
|
||||
|
||||
|
||||
/**
|
||||
* Circular Buffer - stores elements in an array list. Once the buffer is
|
||||
* full, new samples replace older samples and older samples are broadcast
|
||||
* to an optional listener.
|
||||
*
|
||||
* @param size - size of buffer
|
||||
*/
|
||||
public CircularBuffer( int size )
|
||||
{
|
||||
mSize = size;
|
||||
mElements = new ArrayList<T>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the element stored at index. Note: the index argument refers to
|
||||
* the internal storage index and does not indicate a temporal relationship
|
||||
* among elements. For example, if you get indexes 1, 2, and 3, you may be
|
||||
* getting ( oldest - 1, oldest, newest ) elements, if the internal pointer
|
||||
* is currently pointing to and will insert the next element at index 4.
|
||||
*
|
||||
* @param index - element index
|
||||
*
|
||||
* @return element or null
|
||||
*/
|
||||
public T get( int index )
|
||||
{
|
||||
if( index < mElements.size() )
|
||||
{
|
||||
return mElements.get( index );
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getSize()
|
||||
{
|
||||
return mSize;
|
||||
}
|
||||
|
||||
public List<T> getElements()
|
||||
{
|
||||
return Collections.unmodifiableList( mElements );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive( T element )
|
||||
{
|
||||
T previous = null;
|
||||
|
||||
if( mElements.size() > mPointer )
|
||||
{
|
||||
previous = mElements.get( mPointer );
|
||||
|
||||
mElements.set( mPointer, element );
|
||||
}
|
||||
else
|
||||
{
|
||||
mElements.add( element );
|
||||
}
|
||||
|
||||
mPointer++;
|
||||
|
||||
if( mPointer >= mSize )
|
||||
{
|
||||
mPointer = 0;
|
||||
}
|
||||
|
||||
if( previous != null && mListener != null )
|
||||
{
|
||||
mListener.receive( previous );
|
||||
}
|
||||
}
|
||||
|
||||
public void setListener( Listener<T> listener )
|
||||
{
|
||||
mListener = listener;
|
||||
}
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 Dennis Sheirer
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
package buffer;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import sample.complex.Complex;
|
||||
|
||||
/**
|
||||
* Circular sample buffer - allocates a buffer and stores samples in a circular
|
||||
* fashion, overwriting older samples with newly arrived samples. Initially
|
||||
* fills buffer with 0-valued samples
|
||||
*
|
||||
* Can be used as a delay-type buffer, to delay samples by the 'size' amount
|
||||
*/
|
||||
public class ComplexCircularBuffer
|
||||
{
|
||||
Complex[] mBuffer;
|
||||
int mBufferPointer = 0;
|
||||
|
||||
public ComplexCircularBuffer( int size )
|
||||
{
|
||||
mBuffer = new Complex[ size ];
|
||||
|
||||
Arrays.fill( mBuffer, new Complex( 1.0f, 1.0f ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sample currently pointed to in the buffer and stores the
|
||||
* new sample in its place
|
||||
* @param sample
|
||||
* @return
|
||||
*/
|
||||
public Complex get( Complex sample )
|
||||
{
|
||||
Complex retVal = mBuffer[ mBufferPointer ];
|
||||
|
||||
put( sample );
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public void put( Complex sample )
|
||||
{
|
||||
mBuffer[ mBufferPointer ] = sample;
|
||||
|
||||
mBufferPointer++;
|
||||
|
||||
if( mBufferPointer >= mBuffer.length )
|
||||
{
|
||||
mBufferPointer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public Complex[] get( int count )
|
||||
{
|
||||
Complex[] samples = new Complex[ count ];
|
||||
|
||||
int tempCounter = mBufferPointer;
|
||||
|
||||
for( int x = 0; x < count; x++ )
|
||||
{
|
||||
samples[ x ] = mBuffer[ tempCounter ];
|
||||
|
||||
tempCounter++;
|
||||
|
||||
if( tempCounter > mBuffer.length - 1 )
|
||||
{
|
||||
tempCounter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return samples;
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 Dennis Sheirer
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
package buffer;
|
||||
|
||||
import sample.complex.Complex;
|
||||
|
||||
/**
|
||||
* Implements a FIFO circular buffer for complex samples that provides access
|
||||
* to each complex sample by index number, where index 0 is the newest/latest
|
||||
* complex sample and index (length - 1) is the oldest sample in the buffer.
|
||||
*/
|
||||
public class ComplexTappedCircularBuffer
|
||||
{
|
||||
private Complex[] mBuffer;
|
||||
private int mBufferPointer = 0;
|
||||
|
||||
public ComplexTappedCircularBuffer( int length )
|
||||
{
|
||||
mBuffer = new Complex[ length ];
|
||||
|
||||
//Pre-load the buffer with 0-valued samples
|
||||
for( int x = 0; x < length; x++ )
|
||||
{
|
||||
mBuffer[ x ] = new Complex( 0, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the sample to the buffer and removes the oldest sample
|
||||
* @param sample
|
||||
*/
|
||||
public void add( Complex sample )
|
||||
{
|
||||
mBuffer[ mBufferPointer++ ] = sample;
|
||||
|
||||
//Reset the buffer pointer once it points past the end of the buffer
|
||||
if( mBufferPointer >= mBuffer.length )
|
||||
{
|
||||
mBufferPointer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a sample currently in the buffer by index position.
|
||||
*
|
||||
* Index 0 is the newest/latest sample in the buffer and index (length - 1)
|
||||
* is the oldest.
|
||||
*
|
||||
* Note: the buffer is preloaded with complex samples of 0,0 value.
|
||||
*
|
||||
* @param index where 0 is the newest/latest sample and length-1 is the oldest
|
||||
* @return complex sample from the buffer.
|
||||
* @throws ArrayIndexOutOfBoundsException if you attempt to access a sample
|
||||
* outside of the buffer size
|
||||
*/
|
||||
public Complex get( int index )
|
||||
{
|
||||
/* Since the samples are stored in a forward fashion, we have to access
|
||||
* the samples in reverse to comply with the access contract, where
|
||||
* index 0 is the newest and index (length -1) is the oldest, all
|
||||
* relative to the current buffer pointer */
|
||||
|
||||
int pointer = mBuffer.length - 1 + mBufferPointer - index;
|
||||
|
||||
if( pointer >= mBuffer.length )
|
||||
{
|
||||
pointer -= mBuffer.length;
|
||||
}
|
||||
|
||||
return mBuffer[ pointer ];
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 Dennis Sheirer
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
package buffer;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Circular sample buffer - allocates a buffer and stores samples in a circular
|
||||
* fashion, overwriting older samples with newly arrived samples. Initially
|
||||
* fills buffer with 0-valued samples
|
||||
*
|
||||
* Can be used as a delay-type buffer, to delay samples by the 'size' amount
|
||||
*/
|
||||
public class DoubleCircularBuffer
|
||||
{
|
||||
double[] mBuffer;
|
||||
int mBufferPointer = 0;
|
||||
|
||||
public DoubleCircularBuffer( int size )
|
||||
{
|
||||
mBuffer = new double[ size ];
|
||||
|
||||
Arrays.fill( mBuffer, 0.0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts the new value into the buffer and returns the oldest buffer value
|
||||
* that it replaced
|
||||
* @param newValue
|
||||
* @return
|
||||
*/
|
||||
public double get( double newValue )
|
||||
{
|
||||
double oldestSample = mBuffer[ mBufferPointer ];
|
||||
|
||||
mBuffer[ mBufferPointer ] = newValue;
|
||||
|
||||
mBufferPointer++;
|
||||
|
||||
if( mBufferPointer >= mBuffer.length )
|
||||
{
|
||||
mBufferPointer = 0;
|
||||
}
|
||||
|
||||
return oldestSample;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum from the values currently in the buffer
|
||||
*/
|
||||
public double max()
|
||||
{
|
||||
double max = 0.0d;
|
||||
|
||||
for( int x = 0; x < mBuffer.length; x++ )
|
||||
{
|
||||
if( mBuffer[ x ] > max )
|
||||
{
|
||||
max = mBuffer[ x ];
|
||||
}
|
||||
}
|
||||
|
||||
return max;
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 Dennis Sheirer
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
package buffer;
|
||||
|
||||
public class FloatAveragingBuffer
|
||||
{
|
||||
private float[] mBuffer;
|
||||
private float mAverage = 0.0f;
|
||||
private int mBufferSize;
|
||||
private int mBufferPointer;
|
||||
|
||||
public FloatAveragingBuffer( int size )
|
||||
{
|
||||
mBufferSize = size;
|
||||
mBuffer = new float[ size ];
|
||||
}
|
||||
|
||||
public float get( float newValue )
|
||||
{
|
||||
float oldValue = mBuffer[ mBufferPointer ];
|
||||
|
||||
if( Float.isInfinite( newValue ) || Float.isNaN( newValue ) )
|
||||
{
|
||||
mAverage = mAverage - ( oldValue / mBufferSize );
|
||||
|
||||
mBuffer[ mBufferPointer++ ] = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
mAverage = mAverage - ( oldValue / mBufferSize ) + ( newValue / mBufferSize );
|
||||
|
||||
mBuffer[ mBufferPointer++ ] = newValue;
|
||||
}
|
||||
|
||||
if( mBufferPointer >= mBufferSize )
|
||||
{
|
||||
mBufferPointer = 0;
|
||||
}
|
||||
|
||||
return mAverage;
|
||||
}
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 Dennis Sheirer
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
package buffer;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Circular sample buffer - allocates a buffer and stores samples in a circular
|
||||
* fashion, overwriting older samples with newly arrived samples. Initially
|
||||
* fills buffer with 0-valued samples
|
||||
*
|
||||
* Can be used as a delay-type buffer, to delay samples by the 'size' amount
|
||||
* @author denny
|
||||
*
|
||||
*/
|
||||
public class FloatCircularBuffer
|
||||
{
|
||||
float[] mBuffer;
|
||||
int mBufferPointer = 0;
|
||||
|
||||
public FloatCircularBuffer( int size )
|
||||
{
|
||||
mBuffer = new float[ size ];
|
||||
|
||||
Arrays.fill( mBuffer, (float)0.0 );
|
||||
}
|
||||
|
||||
public int getSize()
|
||||
{
|
||||
return mBuffer.length;
|
||||
}
|
||||
|
||||
public float[] getBuffer()
|
||||
{
|
||||
return mBuffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts the new value into the buffer and returns the oldest buffer value
|
||||
* that it replaced
|
||||
* @param newValue
|
||||
* @return
|
||||
*/
|
||||
public float get( float newValue )
|
||||
{
|
||||
float oldestSample = mBuffer[ mBufferPointer ];
|
||||
|
||||
mBuffer[ mBufferPointer ] = newValue;
|
||||
|
||||
mBufferPointer++;
|
||||
|
||||
if( mBufferPointer >= mBuffer.length )
|
||||
{
|
||||
mBufferPointer = 0;
|
||||
}
|
||||
|
||||
return oldestSample;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to put a new value in the buffer, while discarding
|
||||
* the old value
|
||||
*/
|
||||
public void put( float newValue )
|
||||
{
|
||||
get( newValue );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of arraySize, loaded with sampleCount of the
|
||||
* oldest samples, loaded into the array starting at index 0.
|
||||
*
|
||||
* This is useful for fetching an array filled half way with samples to
|
||||
* use in FFT processing.
|
||||
* @param arraySize - size of the array (must be larger than sampleCount)
|
||||
* @param sampleCount - number of the oldest samples in the buffer to load
|
||||
* @return
|
||||
*/
|
||||
public float[] get( int arraySize, int sampleCount )
|
||||
{
|
||||
float[] samples = new float[ arraySize ];
|
||||
|
||||
if( arraySize > sampleCount )
|
||||
{
|
||||
int tempCounter = mBufferPointer;
|
||||
|
||||
for( int x = 0; x < sampleCount; x++ )
|
||||
{
|
||||
samples[ x ] = mBuffer[ tempCounter ];
|
||||
|
||||
tempCounter++;
|
||||
|
||||
if( tempCounter > mBuffer.length )
|
||||
{
|
||||
tempCounter = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return samples;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user