mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 08:37:25 -05:00
Work in progress.
-Started work on new channel editor channel viewer/controller -Removed a number of unused buffer package classes -Moved automatic frequency control to be a module and removed special handling -Added IUnfilteredRealBufferListener & Provider interfaces -Completely removed the ResourceManager class
This commit is contained in:
@@ -1,33 +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 BufferOverflowException extends Exception
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public BufferOverflowException( String text )
|
||||
{
|
||||
super( text );
|
||||
}
|
||||
|
||||
public BufferOverflowException( String text, Throwable exc )
|
||||
{
|
||||
super( text, exc );
|
||||
}
|
||||
}
|
||||
@@ -1,23 +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 interface BufferOverflowListener
|
||||
{
|
||||
public void overflow( Object source, String message );
|
||||
}
|
||||
@@ -1,60 +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 ByteArrayDelayBuffer
|
||||
{
|
||||
private int mBufferSize;
|
||||
private byte[][] mBuffer = null;
|
||||
private int mBufferPointer = 0;
|
||||
|
||||
/**
|
||||
* Implements a delay buffer for byte arrays. As a new byte[] is placed
|
||||
* into the buffer, the oldest byte[] is returned
|
||||
* @param bufferSize - number of byte arrays to buffer
|
||||
*/
|
||||
public ByteArrayDelayBuffer( int bufferSize )
|
||||
{
|
||||
mBufferSize = bufferSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts new bytes into the buffer
|
||||
*
|
||||
* @return - oldest byte[] from the buffer, or null if the buffer is not
|
||||
* yet full
|
||||
*/
|
||||
public byte[] get( byte[] bytes )
|
||||
{
|
||||
if( mBuffer == null )
|
||||
{
|
||||
mBuffer = new byte[ mBufferSize ][ bytes.length ];
|
||||
}
|
||||
|
||||
byte[] returnBytes = mBuffer[ mBufferPointer ];
|
||||
|
||||
mBuffer[ mBufferPointer++ ] = bytes;
|
||||
|
||||
if( mBufferPointer >= mBufferSize )
|
||||
{
|
||||
mBufferPointer = 0;
|
||||
}
|
||||
|
||||
return returnBytes;
|
||||
}
|
||||
}
|
||||
@@ -1,23 +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 interface ByteArrayListener
|
||||
{
|
||||
public void receive( byte[] data );
|
||||
}
|
||||
@@ -1,25 +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.nio.ByteBuffer;
|
||||
|
||||
public interface ByteBufferListener
|
||||
{
|
||||
public void receive( ByteBuffer buffer );
|
||||
}
|
||||
@@ -1,33 +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 interface ByteBufferProvider
|
||||
{
|
||||
/**
|
||||
* Adds a sample listener to receive samples
|
||||
*/
|
||||
public void addByteBufferListener( ByteBufferListener listener );
|
||||
|
||||
/**
|
||||
* Removes the sample listener, if it is currently registered as a listener
|
||||
*/
|
||||
public void removeByteBufferListener( ByteBufferListener listener );
|
||||
}
|
||||
@@ -1,91 +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.nio.ByteBuffer;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import sample.complex.Complex;
|
||||
|
||||
/**
|
||||
* Provides a complex sample enumeration wrapper around a byte array containing
|
||||
* interleaved byte-length I & Q sample values in the range of 0 - 255, converting
|
||||
* those samples into complex samples with value range of -128 to 0 to 127.
|
||||
*/
|
||||
public class ComplexByteBuffer implements Enumeration<Complex>
|
||||
{
|
||||
private static float[] mValues;
|
||||
|
||||
/**
|
||||
* Creates a lookup table that converts the 8-bit valued range from 0 - 255
|
||||
* into scaled float values of -128 to 0 to 127
|
||||
*/
|
||||
static
|
||||
{
|
||||
mValues = new float[ 256 ];
|
||||
|
||||
float scale = (float)( 1.0f / 127.0f );
|
||||
|
||||
for( int x = 0; x < 256; x++ )
|
||||
{
|
||||
mValues[ x ] = (float)( x - 128 ) * scale;
|
||||
}
|
||||
}
|
||||
|
||||
private ByteBuffer mBytes;
|
||||
// private byte[] mBytes;
|
||||
// private int mPointer;
|
||||
|
||||
public ComplexByteBuffer( byte[] bytes )
|
||||
{
|
||||
mBytes = ByteBuffer.wrap( bytes );
|
||||
// mBytes = bytes;
|
||||
// mPointer = 0;
|
||||
}
|
||||
|
||||
public byte[] toArray()
|
||||
{
|
||||
// return mBytes;
|
||||
return mBytes.array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if there are more complex samples remaining.
|
||||
*/
|
||||
@Override
|
||||
public boolean hasMoreElements()
|
||||
{
|
||||
// return mPointer < mBytes.length;
|
||||
return mBytes.hasRemaining();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next complex sample.
|
||||
*
|
||||
* Note: does not check for buffer overrun. Use the hasMoreElements()
|
||||
* method to ensure you do not read past the end of the buffer.
|
||||
*/
|
||||
@Override
|
||||
public Complex nextElement()
|
||||
{
|
||||
// return new ComplexSample( mValues[ ( mBytes[ mPointer++ ] & 0xFF ) ],
|
||||
// mValues[ ( mBytes[ mPointer++ ] & 0xFF ) ] );
|
||||
return new Complex( mValues[ ( mBytes.get() & 0xFF ) ],
|
||||
mValues[ ( mBytes.get() & 0xFF ) ] );
|
||||
}
|
||||
}
|
||||
@@ -1,23 +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 interface ComplexByteBufferListener
|
||||
{
|
||||
public void receive( ComplexByteBuffer buffer );
|
||||
}
|
||||
@@ -1,73 +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.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.Arrays;
|
||||
|
||||
import sample.complex.Complex;
|
||||
|
||||
public class ComplexSampleBufferAssembler
|
||||
{
|
||||
private ByteBuffer mByteBuffer;
|
||||
private int mSizeInBytes;
|
||||
|
||||
public ComplexSampleBufferAssembler( int size )
|
||||
{
|
||||
mSizeInBytes = size * 4;
|
||||
|
||||
//Allocate a byte buffer with 4 bytes per sample (ie 2 x 16-bit samples)
|
||||
mByteBuffer = ByteBuffer.allocate( mSizeInBytes );
|
||||
mByteBuffer.order( ByteOrder.LITTLE_ENDIAN );
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the sample's bytes, left then right, little endian, into the
|
||||
* backing byte array
|
||||
*/
|
||||
public void put( Complex sample )
|
||||
{
|
||||
mByteBuffer.putShort( (short)( sample.left() * Short.MAX_VALUE ) );
|
||||
mByteBuffer.putShort( (short)( sample.right() * Short.MAX_VALUE ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if there is room for more samples in the buffer, or if it is full
|
||||
*/
|
||||
public boolean hasRemaining()
|
||||
{
|
||||
return mByteBuffer.hasRemaining();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a copy of the byte array backing this buffer
|
||||
*/
|
||||
public ByteBuffer get()
|
||||
{
|
||||
return ByteBuffer.wrap( Arrays.copyOf( mByteBuffer.array(), mSizeInBytes ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the bytes from the underlying buffer and reset the pointer to 0.
|
||||
*/
|
||||
public void clear()
|
||||
{
|
||||
mByteBuffer.clear();
|
||||
}
|
||||
}
|
||||
@@ -1,67 +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.Listener;
|
||||
|
||||
/**
|
||||
* Delay Buffer - implements a circular delay buffer backed by an object array
|
||||
*/
|
||||
public class DelayBuffer<T> implements Listener<T>
|
||||
{
|
||||
private Object[] mBuffer;
|
||||
private int mBufferPointer = 0;
|
||||
private Listener<T> mListener;
|
||||
|
||||
public DelayBuffer( int length )
|
||||
{
|
||||
mBuffer = new Object[ length ];
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings( "unchecked" )
|
||||
public void receive( T value )
|
||||
{
|
||||
Object delayed = mBuffer[ mBufferPointer ];
|
||||
|
||||
mBuffer[ mBufferPointer ] = value;
|
||||
|
||||
mBufferPointer++;
|
||||
|
||||
/* Wrap the buffer pointer around to 0 when necessary */
|
||||
if( mBufferPointer >= mBuffer.length )
|
||||
{
|
||||
mBufferPointer = 0;
|
||||
}
|
||||
|
||||
if( mListener != null && delayed != null )
|
||||
{
|
||||
mListener.receive( (T)delayed );
|
||||
}
|
||||
}
|
||||
|
||||
public void setListener( Listener<T> listener )
|
||||
{
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
public void removeListener( Listener<T> listener )
|
||||
{
|
||||
mListener = null;
|
||||
}
|
||||
}
|
||||
@@ -1,97 +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.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class FloatArrayCircularAveragingBuffer
|
||||
{
|
||||
private ArrayList<float[]> mBuffer;
|
||||
private int mBufferPointer;
|
||||
private int mBufferSize;
|
||||
private float[] mAverage;
|
||||
|
||||
public FloatArrayCircularAveragingBuffer( int bufferSize )
|
||||
{
|
||||
mBufferSize = bufferSize;
|
||||
mBuffer = new ArrayList<float[]>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the oldest float array element in the buffer with this new
|
||||
* float array element, and then returns the average of the buffer contents
|
||||
* with the newElement values included in the average array
|
||||
*/
|
||||
public float[] get( float[] newElement )
|
||||
{
|
||||
/**
|
||||
* If we've never setup the average array, or the newElements length is
|
||||
* different than what we've been processing, reset the buffer & averages
|
||||
*/
|
||||
if( mAverage == null || mAverage.length != newElement.length )
|
||||
{
|
||||
reset( newElement.length );
|
||||
}
|
||||
|
||||
float[] oldElement = mBuffer.get( mBufferPointer );
|
||||
|
||||
for( int x = 0; x < newElement.length; x++ )
|
||||
{
|
||||
/**
|
||||
* Change the current average value in each array element by the
|
||||
* difference of the new element minus the old element, divided
|
||||
* by the buffer size ... average it
|
||||
*/
|
||||
mAverage[ x ] +=
|
||||
( ( newElement[ x ] - oldElement[ x ] ) / mBufferSize );
|
||||
}
|
||||
|
||||
mBuffer.set( mBufferPointer, newElement );
|
||||
|
||||
mBufferPointer++;
|
||||
|
||||
if( mBufferPointer >= mBufferSize )
|
||||
{
|
||||
mBufferPointer = 0;
|
||||
}
|
||||
|
||||
return mAverage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears buffer and average and fills buffer with zero-valued float arrays
|
||||
*/
|
||||
private void reset( int arrayLength )
|
||||
{
|
||||
mAverage = new float[ arrayLength ];
|
||||
Arrays.fill( mAverage, 0.0f );
|
||||
|
||||
mBuffer.clear();
|
||||
mBufferPointer = 0;
|
||||
|
||||
float[] emptyArray = new float[ arrayLength ];
|
||||
Arrays.fill( emptyArray, 0.0f );
|
||||
|
||||
for( int x = 0; x < mBufferSize; x++ )
|
||||
{
|
||||
mBuffer.add( emptyArray );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,70 +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.Listener;
|
||||
|
||||
|
||||
/**
|
||||
* Assembles single samples into sample blocks (ie arrays) for broadcast to
|
||||
* registered SampleBlockListeners
|
||||
*/
|
||||
public class FloatBufferAssembler implements Listener<Float>
|
||||
{
|
||||
private Float[] mFloatBuffer;
|
||||
private int mBufferSize;
|
||||
private int mBufferPointer = 0;
|
||||
private Listener<Float[]> mListener;
|
||||
|
||||
public FloatBufferAssembler( int bufferSize )
|
||||
{
|
||||
mBufferSize = bufferSize;
|
||||
mFloatBuffer = new Float[ mBufferSize ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores received samples in the sample block and manages the storage
|
||||
* pointer. Sends sample blocks when full.
|
||||
*/
|
||||
@Override
|
||||
public void receive( Float sample )
|
||||
{
|
||||
mFloatBuffer[ mBufferPointer++ ] = sample;
|
||||
|
||||
if( mBufferPointer == mBufferSize )
|
||||
{
|
||||
if( mListener != null )
|
||||
{
|
||||
mListener.receive( Arrays.copyOf( mFloatBuffer, mBufferSize ) );
|
||||
}
|
||||
|
||||
mBufferPointer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new sampleblock listener to receive sample blocks as they are
|
||||
* assembled from the sample stream
|
||||
*/
|
||||
public void setListener( Listener<Float[]> listener )
|
||||
{
|
||||
mListener = listener;
|
||||
}
|
||||
}
|
||||
@@ -1,110 +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
|
||||
*
|
||||
* Produces no output. Obtain the average buffer value on-demand via the
|
||||
* getAverage() method
|
||||
*/
|
||||
public class FloatCircularAveragingBuffer
|
||||
{
|
||||
private float[] mBuffer;
|
||||
private int mBufferPointer = 0;
|
||||
private int mSampleCountForAveraging;
|
||||
private int mCurrentSampleCount = 0;
|
||||
private float mAverage = 0.0f;
|
||||
|
||||
public FloatCircularAveragingBuffer( int size, int sampleCountForAveraging )
|
||||
{
|
||||
mBuffer = new float[ size ];
|
||||
mSampleCountForAveraging = sampleCountForAveraging;
|
||||
Arrays.fill( mBuffer, 0.0f );
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience wrapper to throw away to put the new sample and throwaway
|
||||
* the oldest sample
|
||||
*/
|
||||
public void put( float newestSample )
|
||||
{
|
||||
get( newestSample );
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the newest sample into the buffer and returns the oldest sample
|
||||
*/
|
||||
public float get( float newestSample )
|
||||
{
|
||||
float oldestSample = mBuffer[ mBufferPointer ];
|
||||
|
||||
mBuffer[ mBufferPointer ] = newestSample;
|
||||
|
||||
mBufferPointer++;
|
||||
|
||||
if( mBufferPointer >= mBuffer.length )
|
||||
{
|
||||
mBufferPointer = 0;
|
||||
}
|
||||
|
||||
mCurrentSampleCount++;
|
||||
|
||||
if( mCurrentSampleCount >= mSampleCountForAveraging )
|
||||
{
|
||||
calculateAverage();
|
||||
|
||||
mCurrentSampleCount = 0;
|
||||
}
|
||||
|
||||
return oldestSample;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the average of the maximum and minimum values present in
|
||||
* the buffer
|
||||
*/
|
||||
private void calculateAverage()
|
||||
{
|
||||
float min = mBuffer[ 0 ];
|
||||
float max = mBuffer[ 0 ];
|
||||
|
||||
for( int x = 0; x < mBuffer.length; x++ )
|
||||
{
|
||||
if( mBuffer[ x ] < min )
|
||||
{
|
||||
min = mBuffer[ x ];
|
||||
}
|
||||
if( mBuffer[ x ] > max )
|
||||
{
|
||||
max = mBuffer[ x ];
|
||||
}
|
||||
}
|
||||
|
||||
mAverage = (float)( ( min + max ) / 2.0f );
|
||||
}
|
||||
|
||||
public float getAverage()
|
||||
{
|
||||
return mAverage;
|
||||
}
|
||||
}
|
||||
@@ -1,68 +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 - stores samples in a circular buffer
|
||||
* overwriting older samples with newly arrived samples. Initially
|
||||
* fills buffer with 0-valued samples
|
||||
*
|
||||
* Continuously calculates the average of the samples in the buffer, with the
|
||||
* average available from the average() method.
|
||||
*/
|
||||
public class FloatCircularAveragingBuffer2
|
||||
{
|
||||
private float[] mBuffer;
|
||||
private int mBufferPointer = 0;
|
||||
private float mAverage = 0.0f;
|
||||
|
||||
public FloatCircularAveragingBuffer2( int size )
|
||||
{
|
||||
mBuffer = new float[ size ];
|
||||
Arrays.fill( mBuffer, 0.0f );
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the newest sample into the buffer and returns the oldest sample
|
||||
*/
|
||||
public float get( float newestSample )
|
||||
{
|
||||
float oldestSample = mBuffer[ mBufferPointer ];
|
||||
|
||||
mBuffer[ mBufferPointer ] = newestSample;
|
||||
|
||||
mBufferPointer++;
|
||||
|
||||
if( mBufferPointer >= mBuffer.length )
|
||||
{
|
||||
mBufferPointer = 0;
|
||||
}
|
||||
|
||||
mAverage = mAverage - ( oldestSample / mBuffer.length ) +
|
||||
( newestSample / mBuffer.length );
|
||||
|
||||
return oldestSample;
|
||||
}
|
||||
|
||||
public float average()
|
||||
{
|
||||
return mAverage;
|
||||
}
|
||||
}
|
||||
@@ -1,66 +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.nio.ByteBuffer;
|
||||
|
||||
|
||||
public class FloatSampleBuffer
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private int mSize;
|
||||
private float[] mBuffer;
|
||||
private int mBufferPointer = 0;
|
||||
|
||||
public FloatSampleBuffer( int size )
|
||||
{
|
||||
super();
|
||||
mBuffer = new float[ size ];
|
||||
}
|
||||
|
||||
public void put( float sample )
|
||||
{
|
||||
if( !isFull() )
|
||||
{
|
||||
mBuffer[ mBufferPointer++ ] = sample;
|
||||
}
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
mBufferPointer = 0;
|
||||
}
|
||||
|
||||
public boolean isFull()
|
||||
{
|
||||
return mBufferPointer >= mBuffer.length;
|
||||
}
|
||||
|
||||
public byte[] getBytes()
|
||||
{
|
||||
ByteBuffer bb = ByteBuffer.allocate( mBuffer.length * 2 );
|
||||
|
||||
for( int x = 0; x < mBuffer.length; x++ )
|
||||
{
|
||||
bb.putShort( ((Float)mBuffer[ x ]).shortValue() );
|
||||
}
|
||||
|
||||
return bb.array();
|
||||
}
|
||||
}
|
||||
@@ -1,72 +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.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
public class FloatSampleBufferAssembler
|
||||
{
|
||||
private ByteBuffer mByteBuffer;
|
||||
private int mSizeInBytes;
|
||||
|
||||
public FloatSampleBufferAssembler( int size )
|
||||
{
|
||||
mSizeInBytes = size * 2;
|
||||
|
||||
//Allocate a byte buffer with 2 bytes per sample (ie 1 x 16-bit sample)
|
||||
mByteBuffer = ByteBuffer.allocate( mSizeInBytes );
|
||||
mByteBuffer.order( ByteOrder.LITTLE_ENDIAN );
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the sample's bytes, left then right, little endian, into the
|
||||
* backing byte array
|
||||
*/
|
||||
public void put( float sample )
|
||||
{
|
||||
mByteBuffer.putShort( (short)( sample * 32768 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if there is room for more samples in the buffer, or if it is full
|
||||
*/
|
||||
public boolean hasRemaining()
|
||||
{
|
||||
return mByteBuffer.hasRemaining();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a copy of the byte array backing this buffer
|
||||
*/
|
||||
public ByteBuffer get()
|
||||
{
|
||||
return mByteBuffer;
|
||||
// return ByteBuffer.wrap( Arrays.copyOf( mByteBuffer.array(), mSizeInBytes ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the bytes from the underlying buffer and reset the pointer to 0.
|
||||
*/
|
||||
public void reset()
|
||||
{
|
||||
// mByteBuffer.clear();
|
||||
mByteBuffer = ByteBuffer.allocate( mSizeInBytes );
|
||||
mByteBuffer.order( ByteOrder.LITTLE_ENDIAN );
|
||||
}
|
||||
}
|
||||
@@ -1,86 +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;
|
||||
|
||||
|
||||
/**
|
||||
* Implements a FIFO circular buffer for floats that provides access
|
||||
* to each 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 FloatTappedCircularBuffer
|
||||
{
|
||||
private Float[] mBuffer;
|
||||
private int mBufferPointer = 0;
|
||||
|
||||
public FloatTappedCircularBuffer( int length )
|
||||
{
|
||||
mBuffer = new Float[ length ];
|
||||
|
||||
//Pre-load the buffer with 0-valued samples
|
||||
for( int x = 0; x < length; x++ )
|
||||
{
|
||||
mBuffer[ x ] = Float.valueOf( 0.0f );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the sample to the buffer and removes the oldest sample
|
||||
* @param sample
|
||||
*/
|
||||
public void add( Float 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 Float 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,69 +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.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
import sample.Broadcaster;
|
||||
import sample.Listener;
|
||||
|
||||
public class FloatToByteBufferAssembler implements Listener<Float>
|
||||
{
|
||||
private Broadcaster<ByteBuffer> mBroadcaster = new Broadcaster<ByteBuffer>();
|
||||
|
||||
private int mBufferSize = 0;
|
||||
private ByteBuffer mBuffer;
|
||||
|
||||
public FloatToByteBufferAssembler( int bufferSize )
|
||||
{
|
||||
mBufferSize = bufferSize;
|
||||
resetBuffer();
|
||||
}
|
||||
|
||||
public void addByteBufferListener( Listener<ByteBuffer> listener )
|
||||
{
|
||||
mBroadcaster.addListener( listener );
|
||||
}
|
||||
|
||||
public void removeByteBufferListener( Listener<ByteBuffer> listener )
|
||||
{
|
||||
mBroadcaster.removeListener( listener );
|
||||
}
|
||||
|
||||
private void resetBuffer()
|
||||
{
|
||||
mBuffer = ByteBuffer.allocate( mBufferSize );
|
||||
mBuffer.order( ByteOrder.BIG_ENDIAN );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive( Float sample )
|
||||
{
|
||||
mBuffer.putShort( Float.valueOf( sample ).shortValue() );
|
||||
|
||||
if( mBuffer.position() >= mBufferSize )
|
||||
{
|
||||
//Buffer is full ... send it
|
||||
mBroadcaster.receive( mBuffer );
|
||||
|
||||
//Reset the buffer
|
||||
resetBuffer();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,53 +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.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import sample.complex.Complex;
|
||||
|
||||
public class ShortComplexByteBuffer implements Enumeration<Complex>
|
||||
{
|
||||
private ByteBuffer mByteBuffer;
|
||||
|
||||
public ShortComplexByteBuffer( byte[] bytes, ByteOrder endianness )
|
||||
{
|
||||
mByteBuffer = ByteBuffer.wrap( bytes );
|
||||
mByteBuffer.order( endianness );
|
||||
}
|
||||
|
||||
public byte[] array()
|
||||
{
|
||||
return mByteBuffer.array();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMoreElements()
|
||||
{
|
||||
return mByteBuffer.hasRemaining();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Complex nextElement()
|
||||
{
|
||||
return new Complex( (float)mByteBuffer.getShort(),
|
||||
(float)mByteBuffer.getShort() );
|
||||
}
|
||||
}
|
||||
@@ -1,59 +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.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import sample.complex.Complex;
|
||||
import source.mixer.MixerChannel;
|
||||
|
||||
public class StereoByteBuffer implements Enumeration<Complex>
|
||||
{
|
||||
private ByteBuffer mByteBuffer;
|
||||
|
||||
public StereoByteBuffer( byte[] bytes, int frames )
|
||||
{
|
||||
mByteBuffer = ByteBuffer.wrap( bytes );
|
||||
mByteBuffer.order( ByteOrder.LITTLE_ENDIAN );
|
||||
}
|
||||
|
||||
public byte[] array()
|
||||
{
|
||||
return mByteBuffer.array();
|
||||
}
|
||||
|
||||
public ByteBuffer getChannel( MixerChannel channel )
|
||||
{
|
||||
return StereoToMonoByteBufferConverter.getChannel( mByteBuffer, channel );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMoreElements()
|
||||
{
|
||||
return mByteBuffer.hasRemaining();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Complex nextElement()
|
||||
{
|
||||
return new Complex( (float)mByteBuffer.getShort(),
|
||||
(float)mByteBuffer.getShort() );
|
||||
}
|
||||
}
|
||||
@@ -1,24 +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 interface StereoByteBufferListener
|
||||
{
|
||||
public void receive( StereoByteBuffer buffer );
|
||||
}
|
||||
@@ -1,32 +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 interface StereoByteBufferProvider
|
||||
{
|
||||
/**
|
||||
* Adds a sample listener to receive samples
|
||||
*/
|
||||
public void addStereoByteBufferListener( StereoByteBufferListener listener );
|
||||
|
||||
/**
|
||||
* Removes the sample listener, if it is currently registered as a listener
|
||||
*/
|
||||
public void removeStereoByteBufferListener( StereoByteBufferListener listener );
|
||||
}
|
||||
@@ -1,58 +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.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
import source.mixer.MixerChannel;
|
||||
|
||||
public class StereoToMonoByteBufferConverter
|
||||
{
|
||||
public static ByteBuffer getChannel( ByteBuffer buffer, MixerChannel channel )
|
||||
{
|
||||
byte[] channelBuffer = new byte[ buffer.capacity() / 2 ];
|
||||
|
||||
|
||||
int channelBufferPointer = 0;
|
||||
|
||||
if( channel == MixerChannel.RIGHT )
|
||||
{
|
||||
//throw away the first two bytes
|
||||
buffer.get();
|
||||
buffer.get();
|
||||
}
|
||||
|
||||
while( channelBufferPointer < channelBuffer.length )
|
||||
{
|
||||
if( buffer.hasRemaining() )
|
||||
{
|
||||
channelBuffer[ channelBufferPointer++ ] = buffer.get();
|
||||
channelBuffer[ channelBufferPointer++ ] = buffer.get();
|
||||
}
|
||||
|
||||
if( buffer.hasRemaining() )
|
||||
{
|
||||
buffer.get();
|
||||
buffer.get();
|
||||
}
|
||||
}
|
||||
|
||||
return ByteBuffer.wrap( channelBuffer ).order( ByteOrder.LITTLE_ENDIAN );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user