Initial commit of redesigned internal processing and audio management.

Note: Several of the decoders are currently non-functioning in this
commit.  If you want the latest functioning codebase, please checkout
the commit prior to this one.  All decoders will eventually be updated
with this new architecture.

Currently broken:
- Logging and recording
- Aux decoders (Fleetsync/MDC/LoJack/Tait)
- LTR/Passport decoders

Changes in this commit:
- Module architecture for decoders and components with central
provisioning by the DecoderFactory
- Transition from Complex sample stream processing to float buffer
processing for improved memory management
- Redesigned filter structures - to support buffers and streams
- Resolved several memory leak issues
- Universal sharing of the thread pool manager
- Added centralized audio management with call/user prioritization and
new gui with mute/volume controls
- Embedded audio metadata for eventual streaming support
- Redesigned ProcessingChain to support independent re-use
- Added new TrafficChannelManager to handle traffic channel allocations
- Traffic Channel pool size and Call timeout available in P25 and
MPT1327 configs
- Redesigned channel and decoder gui components
This commit is contained in:
denny
2015-09-01 07:10:26 -04:00
parent 538a299246
commit f4d8ea281d
570 changed files with 21578 additions and 17012 deletions

View File

@@ -23,33 +23,48 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* ComplexSample for handling left/right channel audio, or inphase/quadrature
* samples, etc.
* Complex sample and related utility methods
*/
public class ComplexSample implements Serializable
public class Complex implements Serializable
{
private final static Logger mLog =
LoggerFactory.getLogger( ComplexSample.class );
LoggerFactory.getLogger( Complex.class );
private static final long serialVersionUID = 1L;
private float mLeft;
private float mRight;
public ComplexSample( float left, float right )
public Complex( float left, float right )
{
mLeft = left;
mRight = right;
}
public ComplexSample()
public Complex()
{
this( 0.0f, 0.0f );
}
public ComplexSample copy()
public void setInphase( float inphase )
{
return new ComplexSample( mLeft, mRight );
mLeft = inphase;
}
public void setQuadrature( float quadrature )
{
mRight = quadrature;
}
public void setValues( float inphase, float quadrature )
{
mLeft = inphase;
mRight = quadrature;
}
public Complex copy()
{
return new Complex( mLeft, mRight );
}
public String toString()
@@ -67,9 +82,9 @@ public class ComplexSample implements Serializable
/**
* Returns a new sample representing the conjugate of this one
*/
public ComplexSample conjugate()
public Complex conjugate()
{
return new ComplexSample( mLeft, -mRight );
return new Complex( mLeft, -mRight );
}
/**
@@ -81,22 +96,37 @@ public class ComplexSample implements Serializable
mRight *= scalor;
}
public static ComplexSample multiply( ComplexSample sample, float scalor )
public static Complex multiply( Complex sample, float scalor )
{
return new ComplexSample( sample.left() * scalor,
return new Complex( sample.left() * scalor,
sample.right() * scalor );
}
/**
* Calculates the inphase component of multiplying two complex numbers, A and B.
*/
public static float multiplyInphase( float inphaseA, float quadratureA, float inphaseB, float quadratureB )
{
return ( inphaseA * inphaseB ) - ( quadratureA * quadratureB );
}
/**
* Calculates the quadrature component of multiplying two complex numbers, A and B.
*/
public static float multiplyQuadrature( float inphaseA, float quadratureA, float inphaseB, float quadratureB )
{
return ( quadratureA * inphaseB ) + ( inphaseA * quadratureB );
}
/**
* Multiplies this sample by the multiplier sample
*/
public void multiply( ComplexSample multiplier )
public void multiply( Complex multiplier )
{
float inphase = ( inphase() * multiplier.inphase() ) -
( quadrature() * multiplier.quadrature() );
float quadrature = ( quadrature() * multiplier.inphase() ) +
( inphase() * multiplier.quadrature() );
float inphase = multiplyInphase( inphase(), quadrature(),
multiplier.inphase(), multiplier.quadrature() );
float quadrature = multiplyQuadrature( inphase(), quadrature(),
multiplier.inphase(), multiplier.quadrature() );
mLeft = inphase;
mRight = quadrature;
@@ -105,31 +135,47 @@ public class ComplexSample implements Serializable
/**
* Multiplies both samples returning a new sample with the results
*/
public static ComplexSample multiply( ComplexSample sample1,
ComplexSample sample2 )
public static Complex multiply( Complex sample1, Complex sample2 )
{
float inphase = ( sample1.inphase() * sample2.inphase() ) -
( sample1.quadrature() * sample2.quadrature() );
float inphase = multiplyInphase( sample1.inphase(), sample1.quadrature(),
sample2.inphase(), sample2.quadrature() );
float quadrature = multiplyQuadrature( sample1.inphase(), sample1.quadrature(),
sample2.inphase(), sample2.quadrature() );
float quadrature = ( sample1.quadrature() * sample2.inphase() ) +
( sample1.inphase() * sample2.quadrature() );
return new ComplexSample( inphase, quadrature );
return new Complex( inphase, quadrature );
}
public static ComplexSample multiply( ComplexSample sample,
public static Complex multiply( Complex sample,
Float inphase, Float quadrature )
{
float i = ( sample.inphase() * inphase ) - ( sample.quadrature() * quadrature );
float q = ( sample.quadrature() * inphase ) + ( sample.inphase() * quadrature );
float i = multiplyInphase( sample.inphase(), sample.quadrature(),
inphase, quadrature );
float q = multiplyQuadrature( sample.inphase(), sample.quadrature(),
inphase, quadrature );
return new ComplexSample( i, q );
return new Complex( i, q );
}
public static Complex multiply( Float inphase, Float quadrature, Complex sample )
{
float i = multiplyInphase( inphase, quadrature, sample.inphase(), sample.quadrature() );
float q = multiplyQuadrature( inphase, quadrature, sample.inphase(), sample.quadrature() );
return new Complex( i, q );
}
public static Complex multiply( float inphaseA, float quadratureA, float inphaseB, float quadratureB )
{
float i = multiplyInphase( inphaseA, quadratureA, inphaseB, quadratureB );
float q = multiplyQuadrature( inphaseA, quadratureA, inphaseB, quadratureB );
return new Complex( i, q );
}
/**
* Adds the adder sample value to this sample
*/
public void add( ComplexSample adder )
public void add( Complex adder )
{
mLeft += adder.left();
mRight += adder.right();
@@ -138,18 +184,18 @@ public class ComplexSample implements Serializable
/**
* Adds the two complex samples returning a new complex sample with the result
*/
public static ComplexSample add( ComplexSample first, ComplexSample second )
public static Complex add( Complex first, Complex second )
{
return new ComplexSample( first.left() + second.left(),
return new Complex( first.left() + second.left(),
first.right() + second.right() );
}
/**
* Adds the two complex samples returning a new complex sample with the result
*/
public static ComplexSample subtract( ComplexSample first, ComplexSample second )
public static Complex subtract( Complex first, Complex second )
{
return new ComplexSample( first.left() - second.left(),
return new Complex( first.left() - second.left(),
first.right() - second.right() );
}
@@ -160,6 +206,11 @@ public class ComplexSample implements Serializable
{
return (float)Math.sqrt( magnitudeSquared() );
}
public static float magnitude( float inphase, float quadrature )
{
return (float)Math.sqrt( ( inphase * inphase ) + ( quadrature * quadrature ) );
}
/**
* Magnitude squared of this sample
@@ -293,9 +344,9 @@ public class ComplexSample implements Serializable
* @param angle in radians
* @return
*/
public static ComplexSample fromAngle( float angle )
public static Complex fromAngle( float angle )
{
return new ComplexSample( (float)Math.cos( angle ),
return new Complex( (float)Math.cos( angle ),
(float)Math.sin( angle ) );
}
@@ -346,16 +397,21 @@ public class ComplexSample implements Serializable
*/
public float envelope()
{
float realAbsolute = realAbsolute();
float imagAbsolute = imaginaryAbsolute();
return envelope( mLeft, mRight );
}
public static float envelope( float inphase, float quadrature )
{
float inphaseAbsolute = Math.abs( inphase );
float quadratureAbsolute = Math.abs( quadrature );
if( realAbsolute > imagAbsolute )
if( inphaseAbsolute > quadratureAbsolute )
{
return realAbsolute + ( 0.4f * imagAbsolute );
return inphaseAbsolute + ( 0.4f * quadratureAbsolute );
}
else
{
return imagAbsolute + ( 0.4f * realAbsolute );
return quadratureAbsolute + ( 0.4f * inphaseAbsolute );
}
}
@@ -363,11 +419,11 @@ public class ComplexSample implements Serializable
{
double angle = Math.PI; //180 degrees
ComplexSample s1 = new ComplexSample( (float)Math.sin( angle ), (float)Math.cos( angle ) );
Complex s1 = new Complex( (float)Math.sin( angle ), (float)Math.cos( angle ) );
ComplexSample tap = new ComplexSample( 1.0f, -0.1f );
Complex tap = new Complex( 1.0f, -0.1f );
ComplexSample convolved = ComplexSample.multiply( s1, tap );
Complex convolved = Complex.multiply( s1, tap );
mLog.debug( "s: " + s1.toString() +
" t: " + tap.toString() +

View File

@@ -1,6 +1,8 @@
package sample.complex;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class ComplexBuffer
{
@@ -32,6 +34,21 @@ public class ComplexBuffer
return mSamples;
}
/**
* Converts this sample buffer into a list of complex samples
*/
public List<Complex> getComplexSamples()
{
List<Complex> samples = new ArrayList<Complex>();
for( int x = 0; x < mSamples.length; x += 2 )
{
samples.add( new Complex( mSamples[ x ], mSamples[ x + 1 ] ) );
}
return samples;
}
/**
* Cleanup method to nullify all data and references
*/

View File

@@ -0,0 +1,30 @@
package sample.complex;
import sample.Listener;
/**
* Real sample buffer to stream converter
*/
public class ComplexBufferToStreamConverter implements Listener<ComplexBuffer>
{
private ComplexSampleListener mListener;
@Override
public void receive( ComplexBuffer buffer )
{
if( mListener != null )
{
float[] samples = buffer.getSamples();
for( int x = 0; x < samples.length; x += 2 )
{
mListener.receive( samples[ x ], samples[ x + 1 ] );
}
}
}
public void setListener( ComplexSampleListener listener )
{
mListener = listener;
}
}

View File

@@ -23,17 +23,17 @@ import java.util.List;
import sample.Listener;
import sample.Provider;
public class ComplexSampleAssembler implements Listener<ComplexSample>,
Provider<List<ComplexSample>>
public class ComplexSampleAssembler implements Listener<Complex>,
Provider<List<Complex>>
{
private ArrayList mBuffer;
private int mBufferSize;
private Listener<List<ComplexSample>> mListener;
private Listener<List<Complex>> mListener;
public ComplexSampleAssembler( int bufferSize )
{
mBufferSize = bufferSize;
mBuffer = new ArrayList<ComplexSample>();
mBuffer = new ArrayList<Complex>();
}
public void dispose()
@@ -43,7 +43,7 @@ public class ComplexSampleAssembler implements Listener<ComplexSample>,
}
@Override
public void receive( ComplexSample sample )
public void receive( Complex sample )
{
mBuffer.add( sample );
@@ -59,13 +59,13 @@ public class ComplexSampleAssembler implements Listener<ComplexSample>,
}
@Override
public void setListener( Listener<List<ComplexSample>> listener )
public void setListener( Listener<List<Complex>> listener )
{
mListener = listener;
}
@Override
public void removeListener( Listener<List<ComplexSample>> listener )
public void removeListener( Listener<List<Complex>> listener )
{
mListener = null;
}

View File

@@ -21,5 +21,5 @@ import java.util.List;
public interface ComplexSampleListListener
{
public void receive( List<ComplexSample> samples );
public void receive( List<Complex> samples );
}

View File

@@ -21,26 +21,26 @@ package sample.complex;
public class ComplexSampleUtils
{
public static ComplexSample multiply( ComplexSample a,
ComplexSample b )
public static Complex multiply( Complex a,
Complex b )
{
return new ComplexSample(
return new Complex(
( a.inphase() * b.inphase() ) - ( a.quadrature() * b.quadrature() ),
( ( a.quadrature() * b.inphase() ) + ( a.inphase() * b.quadrature() ) ) );
}
public static ComplexSample minus( ComplexSample a, ComplexSample b )
public static Complex minus( Complex a, Complex b )
{
return new ComplexSample( a.inphase() - b.inphase(),
return new Complex( a.inphase() - b.inphase(),
a.quadrature() - b.quadrature() );
}
public static double magnitude( ComplexSample sample )
public static double magnitude( Complex sample )
{
return Math.sqrt( magnitudeSquared( sample ) );
}
public static int magnitudeSquared( ComplexSample sample )
public static int magnitudeSquared( Complex sample )
{
return (int)( ( sample.inphase() * sample.inphase() ) +
( sample.quadrature() * sample.quadrature() ) );

View File

@@ -0,0 +1,80 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2015 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 sample.complex;
import sample.Listener;
/**
* Assembles complex float samples into a ComplexBuffer containing an array of floats
*/
public class ComplexToComplexBufferAssembler implements ComplexSampleListener
{
private int mBufferSize;
private float[] mBuffer;
private int mBufferPointer;
private Listener<ComplexBuffer> mListener;
public ComplexToComplexBufferAssembler( int bufferSize )
{
assert( bufferSize % 2 == 0 );
mBufferSize = bufferSize;
mBuffer = new float[ mBufferSize ];
}
public void dispose()
{
mListener = null;
mBuffer = null;
}
public void reset()
{
mBuffer = new float[ mBufferSize ];
mBufferPointer = 0;
}
@Override
public void receive( float i, float q )
{
mBuffer[ mBufferPointer ] = i;
mBufferPointer++;
mBuffer[ mBufferPointer ] = q;
mBufferPointer++;
if( mBufferPointer >= mBufferSize )
{
if( mListener != null )
{
mListener.receive( new ComplexBuffer( mBuffer ) );
}
mBuffer = new float[ mBufferSize ];
mBufferPointer = 0;
}
}
public void setListener( Listener<ComplexBuffer> listener )
{
mListener = listener;
}
}

View File

@@ -0,0 +1,8 @@
package sample.complex;
import sample.Listener;
public interface IComplexBufferListener
{
public Listener<ComplexBuffer> getComplexBufferListener();
}

View File

@@ -0,0 +1,56 @@
package sample.complex;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sample.Listener;
public class RateCounter_CB implements Listener<ComplexBuffer>
{
private final static Logger mLog =
LoggerFactory.getLogger( RateCounter_CB.class );
private Listener<ComplexBuffer> mListener;
private long mCount;
private long mStartTime = -1;
private String mName;
public RateCounter_CB()
{
mName = "UNNAMED";
}
public RateCounter_CB( String name )
{
mName = name;
}
@Override
public void receive( ComplexBuffer buffer )
{
if( mStartTime == -1 )
{
mStartTime = System.currentTimeMillis();
}
mCount += ( buffer.getSamples().length / 2 );
long elapsed = System.currentTimeMillis() - mStartTime;
if( elapsed != 0 )
{
mLog.debug( "[" + mName + "] Sample Rate: " + ( mCount / elapsed ) + " kHz" );
}
if( mListener != null )
{
mListener.receive( buffer );
}
}
public void setListener( Listener<ComplexBuffer> listener )
{
mListener = listener;
}
}

View File

@@ -22,7 +22,7 @@ package sample.complex;
* ComplexSample objects, send this class to the thread as a sentinal value
* to kill the processing thread.
*/
public class ThreadKiller extends ComplexSample
public class ThreadKiller extends Complex
{
private static final long serialVersionUID = 1L;