mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-21 13:05:43 -05:00
Merge pull request #79 from DSheirer/53_audio_sample_rate_to_8kHz
53 audio sample rate to 8k hz
This commit is contained in:
1
.idea/dictionaries/denny.xml
generated
1
.idea/dictionaries/denny.xml
generated
@@ -4,6 +4,7 @@
|
||||
<w>esnid</w>
|
||||
<w>fleetsync</w>
|
||||
<w>ident</w>
|
||||
<w>polyphase</w>
|
||||
<w>talkgroup</w>
|
||||
<w>tgid</w>
|
||||
</words>
|
||||
|
||||
9
.idea/libraries/jmbe_interface_0_3_3.xml
generated
Normal file
9
.idea/libraries/jmbe_interface_0_3_3.xml
generated
Normal file
@@ -0,0 +1,9 @@
|
||||
<component name="libraryTable">
|
||||
<library name="jmbe-interface-0.3.3">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/imports/jmbe-interface-0.3.3.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
||||
Binary file not shown.
@@ -4,6 +4,9 @@
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/images" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/config" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$" type="java-resource" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
@@ -11,11 +14,12 @@
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$MODULE_DIR$/../jmbe/jmbe/library/jmbe-0.3.2.jar!/" />
|
||||
<root url="jar://$MODULE_DIR$/../jmbe/jmbe/library/jmbe-0.3.3.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="library" name="jmbe-interface-0.3.3" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -35,7 +35,7 @@ public class AudioFormats
|
||||
IMBE_FRAME_RATE,
|
||||
LITTLE_ENDIAN );
|
||||
|
||||
public static AudioFormat PCM_SIGNED_8KHZ_16BITS =
|
||||
public static AudioFormat PCM_SIGNED_8KHZ_16BITS_MONO =
|
||||
new AudioFormat( AudioFormat.Encoding.PCM_SIGNED,
|
||||
PCM_8KHZ_RATE,
|
||||
PCM_SAMPLE_SIZE_BITS,
|
||||
@@ -44,6 +44,15 @@ public class AudioFormats
|
||||
PCM_8KHZ_RATE,
|
||||
LITTLE_ENDIAN );
|
||||
|
||||
public static AudioFormat PCM_SIGNED_8KHZ_16BITS_STEREO =
|
||||
new AudioFormat( AudioFormat.Encoding.PCM_SIGNED,
|
||||
PCM_8KHZ_RATE,
|
||||
PCM_SAMPLE_SIZE_BITS,
|
||||
TWO_CHANNELS,
|
||||
PCM_FRAME_SIZE_BYTES_STEREO,
|
||||
PCM_8KHZ_RATE,
|
||||
LITTLE_ENDIAN );
|
||||
|
||||
public static AudioFormat PCM_SIGNED_48KHZ_16BITS_MONO =
|
||||
new AudioFormat( AudioFormat.Encoding.PCM_SIGNED,
|
||||
PCM_48KHZ_RATE,
|
||||
@@ -66,11 +75,11 @@ public class AudioFormats
|
||||
* Source Data Line Info for a 48 kHz, 16-bits signed PCM one channel
|
||||
*/
|
||||
public static final Line.Info MONO_SOURCE_DATALINE_INFO =
|
||||
new DataLine.Info( SourceDataLine.class, PCM_SIGNED_48KHZ_16BITS_MONO );
|
||||
new DataLine.Info( SourceDataLine.class, PCM_SIGNED_8KHZ_16BITS_MONO);
|
||||
|
||||
/**
|
||||
* Source Data Line Info for a 48 kHz, 16-bits signed PCM two channels
|
||||
*/
|
||||
public static final Line.Info STEREO_SOURCE_DATALINE_INFO =
|
||||
new DataLine.Info( SourceDataLine.class, PCM_SIGNED_48KHZ_16BITS_STEREO );
|
||||
new DataLine.Info( SourceDataLine.class, PCM_SIGNED_8KHZ_16BITS_STEREO);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,10 @@ package audio;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
import dsp.filter.design.FilterDesignException;
|
||||
import dsp.filter.fir.FIRFilterSpecification;
|
||||
import dsp.filter.fir.remez.RemezFIRFilterDesigner;
|
||||
import dsp.filter.polyphase.PolyphaseFIRDecimatingFilter_RB;
|
||||
import module.Module;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@@ -36,7 +40,39 @@ public class AudioModule extends Module implements IAudioPacketProvider,
|
||||
ISquelchStateListener,
|
||||
Listener<RealBuffer>
|
||||
{
|
||||
protected static final Logger mLog = LoggerFactory.getLogger( AudioModule.class );
|
||||
protected static final Logger mLog = LoggerFactory.getLogger(AudioModule.class);
|
||||
|
||||
private static float[] mDecimationCoefficients;
|
||||
|
||||
static
|
||||
{
|
||||
//Band-pass filter to both decimate (48kHz to 8kHz) and block 0 - 300 Hz (LTR signalling).
|
||||
FIRFilterSpecification specification = FIRFilterSpecification.bandPassBuilder()
|
||||
.sampleRate( 48000 )
|
||||
.stopFrequency1( 150 )
|
||||
.passFrequencyBegin( 300 )
|
||||
.passFrequencyEnd( 3500 )
|
||||
.stopFrequency2( 4000 )
|
||||
.stopRipple( 0.0004 )
|
||||
.passRipple( 0.008)
|
||||
.build();
|
||||
|
||||
RemezFIRFilterDesigner designer = new RemezFIRFilterDesigner(specification);
|
||||
|
||||
try
|
||||
{
|
||||
if (!designer.isValid())
|
||||
{
|
||||
throw new FilterDesignException("Couldn't design the audio decimation filter");
|
||||
}
|
||||
|
||||
mDecimationCoefficients = designer.getImpulseResponse();
|
||||
}
|
||||
catch (FilterDesignException e)
|
||||
{
|
||||
mLog.debug("Error designing filter", e);
|
||||
}
|
||||
}
|
||||
|
||||
/* Provides a unique identifier for this audio module instance to use as a
|
||||
* source identifier for all audio packets */
|
||||
@@ -48,15 +84,26 @@ public class AudioModule extends Module implements IAudioPacketProvider,
|
||||
private SquelchStateListener mSquelchStateListener = new SquelchStateListener();
|
||||
private SquelchState mSquelchState = SquelchState.SQUELCH;
|
||||
private Listener<AudioPacket> mAudioPacketListener;
|
||||
private PolyphaseFIRDecimatingFilter_RB mAudioDecimationFilter;
|
||||
|
||||
//TODO: remove this -- is being replaced by the DemodulatedAudioFilterModule
|
||||
private RealFIRFilter_R_R mAudioFilter = new RealFIRFilter_R_R(
|
||||
Filters.FIR_BANDPASS_AUDIO_48KHZ.getCoefficients(), 2.0f );
|
||||
|
||||
public AudioModule( boolean record )
|
||||
public AudioModule(boolean record)
|
||||
{
|
||||
mSourceID = ++UNIQUE_ID;
|
||||
mAudioMetadata = new AudioMetadata( mSourceID, record );
|
||||
mAudioMetadata = new AudioMetadata(mSourceID, record);
|
||||
|
||||
mAudioDecimationFilter = new PolyphaseFIRDecimatingFilter_RB(mDecimationCoefficients, 6, 2.0f);
|
||||
mAudioDecimationFilter.setListener(new Listener<RealBuffer>()
|
||||
{
|
||||
@Override
|
||||
public void receive(RealBuffer realBuffer)
|
||||
{
|
||||
if (mAudioPacketListener != null)
|
||||
{
|
||||
AudioPacket packet = new AudioPacket(realBuffer.getSamples(), mAudioMetadata.copyOf());
|
||||
mAudioPacketListener.receive(packet);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,7 +120,7 @@ public class AudioModule extends Module implements IAudioPacketProvider,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start( ScheduledExecutorService executor )
|
||||
public void start(ScheduledExecutorService executor)
|
||||
{
|
||||
/* No start operations provided */
|
||||
}
|
||||
@@ -82,10 +129,10 @@ public class AudioModule extends Module implements IAudioPacketProvider,
|
||||
public void stop()
|
||||
{
|
||||
/* Issue an end audio packet in case a recorder is still rolling */
|
||||
if( mAudioPacketListener != null )
|
||||
if (mAudioPacketListener != null)
|
||||
{
|
||||
mAudioPacketListener.receive( new AudioPacket( AudioPacket.Type.END,
|
||||
mAudioMetadata.copyOf() ) );
|
||||
mAudioPacketListener.receive(new AudioPacket(AudioPacket.Type.END,
|
||||
mAudioMetadata.copyOf()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,22 +141,17 @@ public class AudioModule extends Module implements IAudioPacketProvider,
|
||||
* metadata and sends to the registered listener
|
||||
*/
|
||||
@Override
|
||||
public void receive( RealBuffer buffer )
|
||||
public void receive(RealBuffer buffer)
|
||||
{
|
||||
if( mAudioPacketListener != null && mSquelchState == SquelchState.UNSQUELCH )
|
||||
if (mAudioPacketListener != null && mSquelchState == SquelchState.UNSQUELCH)
|
||||
{
|
||||
/* We make a copy of the samples, so that we don't affect any other
|
||||
* processes that might be concurrently processing the same buffer */
|
||||
float[] audio = Arrays.copyOf( buffer.getSamples(), buffer.getSamples().length );
|
||||
mAudioDecimationFilter.receive(buffer);
|
||||
|
||||
mAudioFilter.filter( audio );
|
||||
|
||||
AudioPacket packet = new AudioPacket( audio, mAudioMetadata.copyOf() );
|
||||
|
||||
if( mAudioPacketListener != null )
|
||||
{
|
||||
mAudioPacketListener.receive( packet );
|
||||
}
|
||||
// /* We make a copy of the samples, so that we don't affect any other
|
||||
// * processes that might be concurrently processing the same buffer */
|
||||
// float[] audio = Arrays.copyOf( buffer.getSamples(), buffer.getSamples().length );
|
||||
//
|
||||
// mAudioFilter.filter( audio );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +168,7 @@ public class AudioModule extends Module implements IAudioPacketProvider,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAudioPacketListener( Listener<AudioPacket> listener )
|
||||
public void setAudioPacketListener(Listener<AudioPacket> listener)
|
||||
{
|
||||
mAudioPacketListener = listener;
|
||||
}
|
||||
@@ -156,15 +198,15 @@ public class AudioModule extends Module implements IAudioPacketProvider,
|
||||
public class ChannelEventListener implements Listener<ChannelEvent>
|
||||
{
|
||||
@Override
|
||||
public void receive( ChannelEvent event )
|
||||
public void receive(ChannelEvent event)
|
||||
{
|
||||
switch( event.getEvent() )
|
||||
switch (event.getEvent())
|
||||
{
|
||||
case NOTIFICATION_STATE_RESET:
|
||||
mAudioMetadata.reset();
|
||||
break;
|
||||
case NOTIFICATION_SELECTION_CHANGE:
|
||||
mAudioMetadata.setSelected( event.getChannel().isSelected() );
|
||||
mAudioMetadata.setSelected(event.getChannel().isSelected());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -178,12 +220,12 @@ public class AudioModule extends Module implements IAudioPacketProvider,
|
||||
public class SquelchStateListener implements Listener<SquelchState>
|
||||
{
|
||||
@Override
|
||||
public void receive( SquelchState state )
|
||||
public void receive(SquelchState state)
|
||||
{
|
||||
if( state == SquelchState.SQUELCH && mAudioPacketListener != null )
|
||||
if (state == SquelchState.SQUELCH && mAudioPacketListener != null)
|
||||
{
|
||||
mAudioPacketListener.receive( new AudioPacket( AudioPacket.Type.END,
|
||||
mAudioMetadata.copyOf() ) );
|
||||
mAudioPacketListener.receive(new AudioPacket(AudioPacket.Type.END,
|
||||
mAudioMetadata.copyOf()));
|
||||
}
|
||||
|
||||
mSquelchState = state;
|
||||
|
||||
@@ -5,7 +5,7 @@ import audio.metadata.AudioMetadata;
|
||||
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014,2015 Dennis Sheirer
|
||||
* Copyright (C) 2014,2016 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
|
||||
|
||||
@@ -33,14 +33,14 @@ import controller.ThreadPoolManager;
|
||||
*/
|
||||
public class MonoAudioOutput extends AudioOutput
|
||||
{
|
||||
private final static int BUFFER_SIZE = 48000;
|
||||
private final static int BUFFER_SIZE = 8000;
|
||||
|
||||
public MonoAudioOutput( ThreadPoolManager threadPoolManager, Mixer mixer )
|
||||
{
|
||||
super( threadPoolManager,
|
||||
mixer,
|
||||
MixerChannel.MONO,
|
||||
AudioFormats.PCM_SIGNED_48KHZ_16BITS_MONO,
|
||||
AudioFormats.PCM_SIGNED_8KHZ_16BITS_MONO,
|
||||
AudioFormats.MONO_SOURCE_DATALINE_INFO,
|
||||
BUFFER_SIZE );
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import controller.ThreadPoolManager;
|
||||
*/
|
||||
public class StereoAudioOutput extends AudioOutput
|
||||
{
|
||||
private final static int BUFFER_SIZE = 96000;
|
||||
private final static int BUFFER_SIZE = 16000;
|
||||
|
||||
public StereoAudioOutput( ThreadPoolManager threadPoolManager,
|
||||
Mixer mixer, MixerChannel channel )
|
||||
@@ -41,7 +41,7 @@ public class StereoAudioOutput extends AudioOutput
|
||||
super( threadPoolManager,
|
||||
mixer,
|
||||
channel,
|
||||
AudioFormats.PCM_SIGNED_48KHZ_16BITS_STEREO,
|
||||
AudioFormats.PCM_SIGNED_8KHZ_16BITS_STEREO,
|
||||
AudioFormats.STEREO_SOURCE_DATALINE_INFO,
|
||||
BUFFER_SIZE );
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/* ....Show License.... */
|
||||
.chart {
|
||||
-fx-background-image: url("../../../../images/Curve-fitted-background.png");
|
||||
-fx-background-image: url("../../../Curve-fitted-background.png");
|
||||
-fx-padding: 15 25 15 15;
|
||||
}
|
||||
.chart-plot-background {
|
||||
-fx-background-color: red;
|
||||
-fx-background-image: url("../../../../images/Curve-fitted-chart-background.png"),
|
||||
url("../../../../images/Curve-fitted-graph-gridlines.png");
|
||||
-fx-background-image: url("../../../Curve-fitted-chart-background.png"),
|
||||
url("../../../Curve-fitted-graph-gridlines.png");
|
||||
-fx-background-size: cover, auto;
|
||||
-fx-background-repeat: no-repeat, repeat;
|
||||
-fx-background-position: 0% 0%, 0% 100%;
|
||||
|
||||
@@ -40,37 +40,35 @@ public class FilterViewer extends Application
|
||||
*/
|
||||
private float[] getFilter()
|
||||
{
|
||||
FIRFilterSpecification specification = FIRFilterSpecification.lowPassBuilder()
|
||||
.sampleRate( 10000 )
|
||||
.gridDensity( 16 )
|
||||
.passBandCutoff( 1300 )
|
||||
.passBandAmplitude( 1.0 )
|
||||
.passBandRipple( 0.01 )
|
||||
.stopBandStart( 2675 )
|
||||
.stopBandAmplitude( 0.0 )
|
||||
.stopBandRipple( 0.001 )
|
||||
.build();
|
||||
|
||||
// FIRFilterSpecification specification = FIRFilterSpecification.highPassBuilder()
|
||||
// .sampleRate( 8000 )
|
||||
// FIRFilterSpecification specification = FIRFilterSpecification.lowPassBuilder()
|
||||
// .sampleRate( 48000 )
|
||||
// .gridDensity( 16 )
|
||||
// .stopBandCutoff( 2000 )
|
||||
// .stopBandAmplitude( 0.0 )
|
||||
// .stopBandRipple( 0.003 )
|
||||
// .passBandStart( 3000 )
|
||||
// .passBandCutoff( 3000 )
|
||||
// .passBandAmplitude( 1.0 )
|
||||
// .passBandRipple( 0.001 )
|
||||
// .passBandRipple( 0.01 )
|
||||
// .stopBandStart( 4000 )
|
||||
// .stopBandAmplitude( 0.0 )
|
||||
// .stopBandRipple( 0.027 )
|
||||
// .build();
|
||||
|
||||
FIRFilterSpecification specification = FIRFilterSpecification.highPassBuilder()
|
||||
.sampleRate( 8000 )
|
||||
.stopBandCutoff( 250 )
|
||||
.stopBandAmplitude( 0.0 )
|
||||
.stopBandRipple( 0.01 )
|
||||
.passBandStart( 300 )
|
||||
.passBandAmplitude( 1.0 )
|
||||
.passBandRipple( 0.01 )
|
||||
.build();
|
||||
|
||||
// FIRFilterSpecification specification = FIRFilterSpecification.bandPassBuilder()
|
||||
// .sampleRate( 8000 )
|
||||
// .order( 164 )
|
||||
// .stopFrequency1( 1100 )
|
||||
// .passFrequencyBegin( 1200 )
|
||||
// .passFrequencyEnd( 2400 )
|
||||
// .stopFrequency2( 2500 )
|
||||
// .stopRipple( 0.01 )
|
||||
// .passRipple( 0.01 )
|
||||
// .sampleRate( 48000 )
|
||||
// .stopFrequency1( 150 )
|
||||
// .passFrequencyBegin( 200 )
|
||||
// .passFrequencyEnd( 3950 )
|
||||
// .stopFrequency2( 4000 )
|
||||
// .stopRipple( 0.0005 )
|
||||
// .passRipple( 0.003)
|
||||
// .build();
|
||||
|
||||
float[] taps = null;
|
||||
|
||||
116
src/dsp/filter/polyphase/FilterStage.java
Normal file
116
src/dsp/filter/polyphase/FilterStage.java
Normal file
@@ -0,0 +1,116 @@
|
||||
/*******************************************************************************
|
||||
* sdrtrunk
|
||||
* Copyright (C) 2014-2016 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 dsp.filter.polyphase;
|
||||
|
||||
public class FilterStage
|
||||
{
|
||||
private float[] mBuffer;
|
||||
private int mBufferSize;
|
||||
private int mBufferPointer;
|
||||
private int[][] mIndexMap;
|
||||
private float[] mCoefficients;
|
||||
|
||||
/**
|
||||
* Single stage of a polyphase filter implemented with a circular sample buffer that uses an index map to ensure
|
||||
* correct alignment of samples to filter taps.
|
||||
*
|
||||
* @param coefficients
|
||||
*/
|
||||
public FilterStage(float[] coefficients)
|
||||
{
|
||||
mCoefficients = coefficients;
|
||||
|
||||
mBufferSize = mCoefficients.length;
|
||||
|
||||
mBuffer = new float[mBufferSize];
|
||||
|
||||
//Note: buffer pointer starts at an illegal index but is decremented before first usage
|
||||
mBufferPointer = mBufferSize;
|
||||
|
||||
generateIndexMap(mBufferSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Coefficients used by this filter stage.
|
||||
*/
|
||||
public float[] getCoefficients()
|
||||
{
|
||||
return mCoefficients;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleanup prior to disposal
|
||||
*/
|
||||
public void dispose()
|
||||
{
|
||||
mCoefficients = null;
|
||||
mIndexMap = null;
|
||||
mBuffer = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the sample into the sample buffer
|
||||
*/
|
||||
private void load(float sample)
|
||||
{
|
||||
mBufferPointer--;
|
||||
|
||||
if (mBufferPointer < 0)
|
||||
{
|
||||
mBufferPointer += mBufferSize;
|
||||
}
|
||||
|
||||
mBuffer[mBufferPointer] = sample;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies convolution against the currently loaded buffer samples.
|
||||
*/
|
||||
public float filter(float sample)
|
||||
{
|
||||
load(sample);
|
||||
|
||||
float accumulator = 0.0f;
|
||||
|
||||
for (int x = 0; x < mBufferSize; x++)
|
||||
{
|
||||
accumulator += mCoefficients[x] * mBuffer[mIndexMap[mBufferPointer][x]];
|
||||
}
|
||||
|
||||
return accumulator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a circular buffer index map to support lookup of the translated index based on the current buffer
|
||||
* pointer and the desired sample index.
|
||||
*/
|
||||
private void generateIndexMap(int size)
|
||||
{
|
||||
mIndexMap = new int[size][size];
|
||||
|
||||
for (int x = 0; x < size; x++)
|
||||
{
|
||||
for (int y = 0; y < size; y++)
|
||||
{
|
||||
int z = x + y;
|
||||
|
||||
mIndexMap[x][y] = z < size ? z : z - size;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
212
src/dsp/filter/polyphase/PolyphaseFIRDecimatingFilter_RB.java
Normal file
212
src/dsp/filter/polyphase/PolyphaseFIRDecimatingFilter_RB.java
Normal file
@@ -0,0 +1,212 @@
|
||||
/*******************************************************************************
|
||||
* sdrtrunk
|
||||
* Copyright (C) 2014-2016 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 dsp.filter.polyphase;
|
||||
|
||||
import dsp.filter.design.FilterDesignException;
|
||||
import dsp.filter.fir.FIRFilter;
|
||||
import dsp.filter.fir.FIRFilterSpecification;
|
||||
import dsp.filter.fir.remez.RemezFIRFilterDesigner;
|
||||
import dsp.mixer.Oscillator;
|
||||
import gui.SDRTrunk;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sample.Listener;
|
||||
import sample.real.RealBuffer;
|
||||
import sample.real.RealToRealBufferAssembler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class PolyphaseFIRDecimatingFilter_RB extends FIRFilter implements Listener<RealBuffer>
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger( PolyphaseFIRDecimatingFilter_RB.class );
|
||||
|
||||
private List<FilterStage> mFilterStages = new ArrayList<>();
|
||||
private int mFilterStagePointer;
|
||||
private Listener<RealBuffer> mListener;
|
||||
private RealToRealBufferAssembler mAssembler;
|
||||
private int mDecimationRatio;
|
||||
private float mAccumulator = 0.0f;
|
||||
private float mGain = 1.0f;
|
||||
|
||||
/**
|
||||
* Polyphase filter stage for decimating real-valued sample buffers by the decimation ratio. Creates a number of
|
||||
* polyphase filter arms/stages equal to the decimation ratio.
|
||||
*
|
||||
* Note: output real-valued buffer sizes are determined by the first input buffer that is presented to the filter
|
||||
* where the output buffer size is equal to the floor of the input buffer size divided by the decimation ratio.
|
||||
*
|
||||
* @param coefficients of a low pass filter designed for the input sample rate with a cutoff frequency that conforms
|
||||
* to the nyquist frequency for an output sample rate equal to the input sample rate divided by the decimation ratio.
|
||||
*
|
||||
* @param decimationRatio to decimate the input sample rate by.
|
||||
* @param gain to apply to the filtered output. Use a value of 1.0 to apply no gain.
|
||||
*/
|
||||
public PolyphaseFIRDecimatingFilter_RB(float[] coefficients, int decimationRatio, float gain)
|
||||
{
|
||||
mDecimationRatio = decimationRatio;
|
||||
mGain = gain;
|
||||
|
||||
createFilterStages(coefficients, mDecimationRatio);
|
||||
mFilterStagePointer = mFilterStages.size() - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates polyphase filter stages (arms) from the set of coefficients.
|
||||
*
|
||||
* @param coefficients for the low-pass filter
|
||||
* @param decimationRatio to determine the number of polyphase filter stages.
|
||||
*/
|
||||
private void createFilterStages(float[] coefficients, int decimationRatio)
|
||||
{
|
||||
int tapSize = (int)Math.ceil((double)coefficients.length / (double)decimationRatio);
|
||||
|
||||
float[][] coefficientSets = new float[decimationRatio][tapSize];
|
||||
|
||||
int stagePointer = 0;
|
||||
int coefficientPointer = 0;
|
||||
|
||||
//Split the coefficients up into polyphase stage coefficient sets
|
||||
for(int x = 0; x < coefficients.length; x++)
|
||||
{
|
||||
coefficientSets[stagePointer++][coefficientPointer] = coefficients[x];
|
||||
|
||||
if(stagePointer >= decimationRatio)
|
||||
{
|
||||
stagePointer = 0;
|
||||
coefficientPointer++;
|
||||
}
|
||||
}
|
||||
|
||||
//Create the stages
|
||||
for(int x = 0; x < decimationRatio; x++)
|
||||
{
|
||||
mFilterStages.add(new FilterStage(coefficientSets[x]));
|
||||
}
|
||||
}
|
||||
|
||||
public void dispose()
|
||||
{
|
||||
mListener = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(RealBuffer buffer)
|
||||
{
|
||||
if(mAssembler == null)
|
||||
{
|
||||
mAssembler = new RealToRealBufferAssembler(buffer.getSamples().length / mDecimationRatio);
|
||||
mAssembler.setListener(mListener);
|
||||
}
|
||||
|
||||
for(float sample: buffer.getSamples())
|
||||
{
|
||||
filter(sample);
|
||||
}
|
||||
|
||||
int a = 0;
|
||||
}
|
||||
|
||||
private void filter(float sample)
|
||||
{
|
||||
FilterStage stage = mFilterStages.get(mFilterStagePointer--);
|
||||
|
||||
mAccumulator += stage.filter(sample);
|
||||
|
||||
if(mFilterStagePointer < 0)
|
||||
{
|
||||
mAssembler.receive(mAccumulator * mGain);
|
||||
mAccumulator = 0.0f;
|
||||
|
||||
mFilterStagePointer = mFilterStages.size() - 1;
|
||||
}
|
||||
}
|
||||
|
||||
public void setListener(Listener<RealBuffer> listener)
|
||||
{
|
||||
mListener = listener;
|
||||
|
||||
if(mAssembler != null)
|
||||
{
|
||||
mAssembler.setListener(mListener);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeListener()
|
||||
{
|
||||
mListener = null;
|
||||
|
||||
if(mAssembler != null)
|
||||
{
|
||||
mAssembler.setListener(null);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
FIRFilterSpecification specification = FIRFilterSpecification.lowPassBuilder()
|
||||
.sampleRate( 48000 )
|
||||
.gridDensity( 16 )
|
||||
.passBandCutoff( 3000 )
|
||||
.passBandAmplitude( 1.0 )
|
||||
.passBandRipple( 0.01 )
|
||||
.stopBandStart( 4000 )
|
||||
.stopBandAmplitude( 0.0 )
|
||||
.stopBandRipple( 0.027 )
|
||||
.build();
|
||||
|
||||
RemezFIRFilterDesigner designer = new RemezFIRFilterDesigner(specification);
|
||||
|
||||
try
|
||||
{
|
||||
if(!designer.isValid())
|
||||
{
|
||||
throw new FilterDesignException("Couldn't design the filter");
|
||||
}
|
||||
|
||||
float[] coefficients = designer.getImpulseResponse();
|
||||
PolyphaseFIRDecimatingFilter_RB filter = new PolyphaseFIRDecimatingFilter_RB(coefficients, 6, 1.0f);
|
||||
filter.setListener(new Listener<RealBuffer>()
|
||||
{
|
||||
@Override
|
||||
public void receive(RealBuffer realBuffer)
|
||||
{
|
||||
mLog.info("Filtered: " + Arrays.toString(realBuffer.getSamples()));
|
||||
}
|
||||
});
|
||||
|
||||
Oscillator oscillator = new Oscillator(3400, 48000);
|
||||
|
||||
float[] samples = new float[500];
|
||||
for(int x = 0; x < 500; x++)
|
||||
{
|
||||
samples[x] = oscillator.getFloat();
|
||||
oscillator.rotate();
|
||||
}
|
||||
|
||||
RealBuffer buffer = new RealBuffer(samples);
|
||||
filter.receive(buffer);
|
||||
}
|
||||
catch(FilterDesignException e)
|
||||
{
|
||||
mLog.debug("Error designing filter", e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,22 @@
|
||||
package dsp.filter;
|
||||
/*******************************************************************************
|
||||
* sdrtrunk
|
||||
* Copyright (C) 2014-2016 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 dsp.filter.polyphase;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -43,9 +43,9 @@ import audio.metadata.MetadataType;
|
||||
|
||||
public class LTRNetDecoderState extends DecoderState
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger( LTRNetDecoderState.class );
|
||||
private final static Logger mLog = LoggerFactory.getLogger(LTRNetDecoderState.class);
|
||||
|
||||
private DecimalFormat mDecimalFormatter = new DecimalFormat( "0.00000" );
|
||||
private DecimalFormat mDecimalFormatter = new DecimalFormat("0.00000");
|
||||
|
||||
private TreeSet<String> mTalkgroups = new TreeSet<String>();
|
||||
private TreeSet<String> mTalkgroupsFirstHeard = new TreeSet<String>();
|
||||
@@ -53,11 +53,11 @@ public class LTRNetDecoderState extends DecoderState
|
||||
private TreeSet<Integer> mUniqueIDs = new TreeSet<Integer>();
|
||||
private TreeSet<String> mNeighborIDs = new TreeSet<String>();
|
||||
private TreeSet<String> mSiteIDs = new TreeSet<String>();
|
||||
private HashMap<Integer,Long> mReceiveFrequencies =
|
||||
new HashMap<Integer,Long>();
|
||||
private HashMap<Integer,Long> mTransmitFrequencies =
|
||||
new HashMap<Integer,Long>();
|
||||
private HashMap<Integer,String> mActiveCalls = new HashMap<Integer,String>();
|
||||
private HashMap<Integer, Long> mReceiveFrequencies =
|
||||
new HashMap<Integer, Long>();
|
||||
private HashMap<Integer, Long> mTransmitFrequencies =
|
||||
new HashMap<Integer, Long>();
|
||||
private HashMap<Integer, String> mActiveCalls = new HashMap<Integer, String>();
|
||||
|
||||
private String mTalkgroup;
|
||||
private Alias mTalkgroupAlias;
|
||||
@@ -65,9 +65,9 @@ public class LTRNetDecoderState extends DecoderState
|
||||
private int mChannelNumber;
|
||||
private long mFrequency = 0;
|
||||
|
||||
public LTRNetDecoderState( AliasList aliasList )
|
||||
public LTRNetDecoderState(AliasList aliasList)
|
||||
{
|
||||
super( aliasList );
|
||||
super(aliasList);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -77,80 +77,80 @@ public class LTRNetDecoderState extends DecoderState
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive( Message message )
|
||||
public void receive(Message message)
|
||||
{
|
||||
if( message.isValid() )
|
||||
if (message.isValid())
|
||||
{
|
||||
State state = State.IDLE;
|
||||
|
||||
if( message instanceof LTRNetOSWMessage )
|
||||
if (message instanceof LTRNetOSWMessage)
|
||||
{
|
||||
LTRNetOSWMessage ltr = (LTRNetOSWMessage)message;
|
||||
LTRNetOSWMessage ltr = (LTRNetOSWMessage) message;
|
||||
|
||||
switch( ltr.getMessageType() )
|
||||
switch (ltr.getMessageType())
|
||||
{
|
||||
case CA_ENDD:
|
||||
if( mChannelNumber == 0 )
|
||||
if (mChannelNumber == 0)
|
||||
{
|
||||
mChannelNumber = ltr.getChannel();
|
||||
broadcast( ChangedAttribute.CHANNEL_NUMBER );
|
||||
broadcast(ChangedAttribute.CHANNEL_NUMBER);
|
||||
}
|
||||
|
||||
/* Process FCC Station ID Events */
|
||||
if( ltr.getGroup() == 254 )
|
||||
if (ltr.getGroup() == 254)
|
||||
{
|
||||
if( mCurrentCallEvent == null ||
|
||||
if (mCurrentCallEvent == null ||
|
||||
mCurrentCallEvent.getCallEventType() !=
|
||||
CallEventType.STATION_ID )
|
||||
CallEventType.STATION_ID)
|
||||
{
|
||||
mCurrentCallEvent = new LTRCallEvent.Builder(
|
||||
DecoderType.LTR_NET, CallEventType.STATION_ID )
|
||||
.aliasList( getAliasList() )
|
||||
.channel( String.valueOf( mChannelNumber ) )
|
||||
.frequency( mFrequency )
|
||||
.to( ltr.getTalkgroupID() )
|
||||
DecoderType.LTR_NET, CallEventType.STATION_ID)
|
||||
.aliasList(getAliasList())
|
||||
.channel(String.valueOf(mChannelNumber))
|
||||
.frequency(mFrequency)
|
||||
.to(ltr.getTalkgroupID())
|
||||
.build();
|
||||
|
||||
broadcast( mCurrentCallEvent );
|
||||
broadcast(mCurrentCallEvent);
|
||||
|
||||
broadcast( new DecoderStateEvent( this,
|
||||
Event.START, State.DATA ) );
|
||||
broadcast(new DecoderStateEvent(this,
|
||||
Event.START, State.DATA));
|
||||
}
|
||||
else
|
||||
{
|
||||
broadcast( new DecoderStateEvent( this,
|
||||
Event.CONTINUATION, State.DATA ) );
|
||||
broadcast(new DecoderStateEvent(this,
|
||||
Event.CONTINUATION, State.DATA));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
processCallEndMessage( ltr );
|
||||
processCallEndMessage(ltr);
|
||||
}
|
||||
break;
|
||||
case CA_STRT:
|
||||
if( mChannelNumber == 0 )
|
||||
if (mChannelNumber == 0)
|
||||
{
|
||||
mChannelNumber = ltr.getChannel();
|
||||
broadcast( ChangedAttribute.CHANNEL_NUMBER );
|
||||
broadcast(ChangedAttribute.CHANNEL_NUMBER);
|
||||
}
|
||||
|
||||
/* If the call event channel matches our current channel
|
||||
* then it's a call, otherwise it's a call detect. */
|
||||
if( ltr.getChannel() == mChannelNumber )
|
||||
if (ltr.getChannel() == mChannelNumber)
|
||||
{
|
||||
processCallMessage( ltr );
|
||||
processCallMessage(ltr);
|
||||
}
|
||||
else
|
||||
{
|
||||
processCallDetectMessage( ltr );
|
||||
processCallDetectMessage(ltr);
|
||||
}
|
||||
|
||||
break;
|
||||
case SY_IDLE:
|
||||
if( mChannelNumber != ltr.getChannel() )
|
||||
if (mChannelNumber != ltr.getChannel())
|
||||
{
|
||||
mChannelNumber = ltr.getChannel();
|
||||
broadcast( ChangedAttribute.CHANNEL_NUMBER );
|
||||
broadcast(ChangedAttribute.CHANNEL_NUMBER);
|
||||
}
|
||||
break;
|
||||
case MA_CHNH:
|
||||
@@ -159,26 +159,26 @@ public class LTRNetDecoderState extends DecoderState
|
||||
break;
|
||||
case FQ_RXHI:
|
||||
case FQ_RXLO:
|
||||
if( ltr.getFrequency() > 0 )
|
||||
if (ltr.getFrequency() > 0)
|
||||
{
|
||||
mReceiveFrequencies.put( ltr.getHomeRepeater(),
|
||||
ltr.getFrequency() );
|
||||
mReceiveFrequencies.put(ltr.getHomeRepeater(),
|
||||
ltr.getFrequency());
|
||||
}
|
||||
break;
|
||||
case FQ_TXHI:
|
||||
case FQ_TXLO:
|
||||
if( ltr.getFrequency() > 0 )
|
||||
if (ltr.getFrequency() > 0)
|
||||
{
|
||||
mTransmitFrequencies.put( ltr.getHomeRepeater(),
|
||||
ltr.getFrequency() );
|
||||
mTransmitFrequencies.put(ltr.getHomeRepeater(),
|
||||
ltr.getFrequency());
|
||||
}
|
||||
break;
|
||||
case ID_NBOR:
|
||||
String neighborID = ltr.getNeighborID();
|
||||
|
||||
if( neighborID != null )
|
||||
if (neighborID != null)
|
||||
{
|
||||
mNeighborIDs.add( neighborID );
|
||||
mNeighborIDs.add(neighborID);
|
||||
}
|
||||
break;
|
||||
case ID_UNIQ:
|
||||
@@ -186,59 +186,59 @@ public class LTRNetDecoderState extends DecoderState
|
||||
|
||||
int uniqueID = ltr.getRadioUniqueID();
|
||||
|
||||
if( uniqueID != LTRNetOSWMessage.INT_NULL_VALUE )
|
||||
if (uniqueID != LTRNetOSWMessage.INT_NULL_VALUE)
|
||||
{
|
||||
mUniqueIDs.add( uniqueID );
|
||||
mUniqueIDs.add(uniqueID);
|
||||
}
|
||||
|
||||
if( getCurrentLTRCallEvent() == null )
|
||||
if (getCurrentLTRCallEvent() == null)
|
||||
{
|
||||
mCurrentCallEvent = new LTRCallEvent.Builder(
|
||||
DecoderType.LTR_NET, CallEventType.REGISTER )
|
||||
.aliasList( getAliasList() )
|
||||
.channel( String.valueOf( mChannelNumber ) )
|
||||
.frequency( mFrequency )
|
||||
.from( String.valueOf( uniqueID ) )
|
||||
DecoderType.LTR_NET, CallEventType.REGISTER)
|
||||
.aliasList(getAliasList())
|
||||
.channel(String.valueOf(mChannelNumber))
|
||||
.frequency(mFrequency)
|
||||
.from(String.valueOf(uniqueID))
|
||||
.build();
|
||||
}
|
||||
else
|
||||
{
|
||||
mCurrentCallEvent.setFromID(
|
||||
String.valueOf( ltr.getRadioUniqueID() ) );
|
||||
mCurrentCallEvent.setDetails( "Unique ID" );
|
||||
String.valueOf(ltr.getRadioUniqueID()));
|
||||
mCurrentCallEvent.setDetails("Unique ID");
|
||||
|
||||
broadcast( mCurrentCallEvent );
|
||||
broadcast(mCurrentCallEvent);
|
||||
}
|
||||
|
||||
mTalkgroup = String.valueOf( uniqueID );
|
||||
broadcast( ChangedAttribute.TO_TALKGROUP );
|
||||
mTalkgroup = String.valueOf(uniqueID);
|
||||
broadcast(ChangedAttribute.TO_TALKGROUP);
|
||||
|
||||
mTalkgroupAlias = ltr.getRadioUniqueIDAlias();
|
||||
broadcast( ChangedAttribute.TO_TALKGROUP_ALIAS );
|
||||
broadcast(ChangedAttribute.TO_TALKGROUP_ALIAS);
|
||||
break;
|
||||
case ID_SITE:
|
||||
String siteID = ltr.getSiteID();
|
||||
|
||||
if( siteID != null )
|
||||
if (siteID != null)
|
||||
{
|
||||
mSiteIDs.add( siteID );
|
||||
mSiteIDs.add(siteID);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if( message instanceof LTRNetISWMessage )
|
||||
else if (message instanceof LTRNetISWMessage)
|
||||
{
|
||||
LTRNetISWMessage ltr = ((LTRNetISWMessage)message);
|
||||
LTRNetISWMessage ltr = ((LTRNetISWMessage) message);
|
||||
|
||||
switch( ltr.getMessageType() )
|
||||
switch (ltr.getMessageType())
|
||||
{
|
||||
case CA_STRT:
|
||||
processCallMessage( ltr );
|
||||
processCallMessage(ltr);
|
||||
break;
|
||||
case CA_ENDD:
|
||||
processCallEndMessage( ltr );
|
||||
processCallEndMessage(ltr);
|
||||
break;
|
||||
case ID_ESNH:
|
||||
case ID_ESNL:
|
||||
@@ -246,33 +246,33 @@ public class LTRNetDecoderState extends DecoderState
|
||||
|
||||
String esn = ltr.getESN();
|
||||
|
||||
if( !esn.contains( "xxxx" ) )
|
||||
if (!esn.contains("xxxx"))
|
||||
{
|
||||
mESNs.add( ltr.getESN() );
|
||||
mESNs.add(ltr.getESN());
|
||||
}
|
||||
|
||||
mDescription = "ESN";
|
||||
broadcast( ChangedAttribute.DESCRIPTION );
|
||||
broadcast(ChangedAttribute.DESCRIPTION);
|
||||
|
||||
mTalkgroup = ltr.getESN();
|
||||
broadcast( ChangedAttribute.TO_TALKGROUP );
|
||||
broadcast(ChangedAttribute.TO_TALKGROUP);
|
||||
|
||||
mTalkgroupAlias = ltr.getESNAlias();
|
||||
broadcast( ChangedAttribute.TO_TALKGROUP_ALIAS );
|
||||
broadcast(ChangedAttribute.TO_TALKGROUP_ALIAS);
|
||||
|
||||
broadcast( new DecoderStateEvent( this, Event.DECODE, State.DATA ) );
|
||||
broadcast(new DecoderStateEvent(this, Event.DECODE, State.DATA));
|
||||
|
||||
if( mCurrentCallEvent == null )
|
||||
if (mCurrentCallEvent == null)
|
||||
{
|
||||
mCurrentCallEvent = new LTRCallEvent.Builder(
|
||||
DecoderType.LTR_NET, CallEventType.REGISTER_ESN )
|
||||
.aliasList( getAliasList() )
|
||||
.details( "ESN:" + ltr.getESN() )
|
||||
.frequency( mFrequency )
|
||||
.from( ltr.getESN() )
|
||||
DecoderType.LTR_NET, CallEventType.REGISTER_ESN)
|
||||
.aliasList(getAliasList())
|
||||
.details("ESN:" + ltr.getESN())
|
||||
.frequency(mFrequency)
|
||||
.from(ltr.getESN())
|
||||
.build();
|
||||
|
||||
broadcast( mCurrentCallEvent );
|
||||
broadcast(mCurrentCallEvent);
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -281,36 +281,36 @@ public class LTRNetDecoderState extends DecoderState
|
||||
|
||||
int uniqueid = ltr.getRadioUniqueID();
|
||||
|
||||
if( uniqueid != LTRNetISWMessage.INT_NULL_VALUE )
|
||||
if (uniqueid != LTRNetISWMessage.INT_NULL_VALUE)
|
||||
{
|
||||
mUniqueIDs.add( uniqueid );
|
||||
mUniqueIDs.add(uniqueid);
|
||||
|
||||
mDescription = "REGISTER UID";
|
||||
broadcast( ChangedAttribute.DESCRIPTION );
|
||||
broadcast(ChangedAttribute.DESCRIPTION);
|
||||
|
||||
mTalkgroup = String.valueOf( uniqueid );
|
||||
broadcast( ChangedAttribute.TO_TALKGROUP );
|
||||
mTalkgroup = String.valueOf(uniqueid);
|
||||
broadcast(ChangedAttribute.TO_TALKGROUP);
|
||||
|
||||
mTalkgroupAlias = ltr.getRadioUniqueIDAlias();
|
||||
broadcast( ChangedAttribute.TO_TALKGROUP_ALIAS );
|
||||
broadcast(ChangedAttribute.TO_TALKGROUP_ALIAS);
|
||||
|
||||
if( getCurrentLTRCallEvent() == null )
|
||||
if (getCurrentLTRCallEvent() == null)
|
||||
{
|
||||
mCurrentCallEvent = new LTRCallEvent.Builder(
|
||||
DecoderType.LTR_NET, CallEventType.REGISTER )
|
||||
.aliasList( getAliasList() )
|
||||
.channel( String.valueOf( mChannelNumber ) )
|
||||
.frequency( mFrequency )
|
||||
.from( String.valueOf( uniqueid ) )
|
||||
DecoderType.LTR_NET, CallEventType.REGISTER)
|
||||
.aliasList(getAliasList())
|
||||
.channel(String.valueOf(mChannelNumber))
|
||||
.frequency(mFrequency)
|
||||
.from(String.valueOf(uniqueid))
|
||||
.build();
|
||||
}
|
||||
else
|
||||
{
|
||||
mCurrentCallEvent.setFromID(
|
||||
String.valueOf( ltr.getRadioUniqueID() ) );
|
||||
mCurrentCallEvent.setDetails( "Unique ID" );
|
||||
String.valueOf(ltr.getRadioUniqueID()));
|
||||
mCurrentCallEvent.setDetails("Unique ID");
|
||||
|
||||
broadcast( mCurrentCallEvent );
|
||||
broadcast(mCurrentCallEvent);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -323,9 +323,9 @@ public class LTRNetDecoderState extends DecoderState
|
||||
|
||||
public LTRCallEvent getCurrentLTRCallEvent()
|
||||
{
|
||||
if( mCurrentCallEvent != null )
|
||||
if (mCurrentCallEvent != null)
|
||||
{
|
||||
return (LTRCallEvent)mCurrentCallEvent;
|
||||
return (LTRCallEvent) mCurrentCallEvent;
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -336,228 +336,228 @@ public class LTRNetDecoderState extends DecoderState
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append( "Activity Summary\n" );
|
||||
sb.append( "Decoder:\tLTR-Net\n\n" );
|
||||
sb.append("Activity Summary\n");
|
||||
sb.append("Decoder:\tLTR-Net\n\n");
|
||||
|
||||
if( mSiteIDs.isEmpty() )
|
||||
if (mSiteIDs.isEmpty())
|
||||
{
|
||||
sb.append( "Site:\tUnknown\n" );
|
||||
sb.append("Site:\tUnknown\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
Iterator<String> it = mSiteIDs.iterator();
|
||||
|
||||
while( it.hasNext() )
|
||||
while (it.hasNext())
|
||||
{
|
||||
sb.append( "Site:\t" );
|
||||
sb.append("Site:\t");
|
||||
|
||||
String siteID = it.next();
|
||||
|
||||
sb.append( siteID );
|
||||
sb.append(siteID);
|
||||
|
||||
if( hasAliasList() )
|
||||
if (hasAliasList())
|
||||
{
|
||||
Alias siteAlias = getAliasList().getSiteID( String.valueOf( siteID ) );
|
||||
Alias siteAlias = getAliasList().getSiteID(String.valueOf(siteID));
|
||||
|
||||
if( siteAlias != null )
|
||||
if (siteAlias != null)
|
||||
{
|
||||
sb.append( " " );
|
||||
sb.append( siteAlias.getName() );
|
||||
sb.append(" ");
|
||||
sb.append(siteAlias.getName());
|
||||
}
|
||||
}
|
||||
|
||||
sb.append( "\n" );
|
||||
sb.append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
sb.append( "\nLCNs (transmit | receive)\n" );
|
||||
sb.append("\nLCNs (transmit | receive)\n");
|
||||
|
||||
if( mReceiveFrequencies.isEmpty() && mTransmitFrequencies.isEmpty() )
|
||||
if (mReceiveFrequencies.isEmpty() && mTransmitFrequencies.isEmpty())
|
||||
{
|
||||
sb.append( " None\n" );
|
||||
sb.append(" None\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
for( int x = 1; x < 21; x++ )
|
||||
for (int x = 1; x < 21; x++)
|
||||
{
|
||||
long rcv = 0;
|
||||
|
||||
if( mReceiveFrequencies.containsKey( x ) )
|
||||
if (mReceiveFrequencies.containsKey(x))
|
||||
{
|
||||
rcv = mReceiveFrequencies.get( x );
|
||||
rcv = mReceiveFrequencies.get(x);
|
||||
}
|
||||
|
||||
long xmt = 0;
|
||||
|
||||
if( mTransmitFrequencies.containsKey( x ) )
|
||||
if (mTransmitFrequencies.containsKey(x))
|
||||
{
|
||||
xmt = mTransmitFrequencies.get( x );
|
||||
xmt = mTransmitFrequencies.get(x);
|
||||
}
|
||||
|
||||
if( rcv > 0 || xmt > 0 )
|
||||
if (rcv > 0 || xmt > 0)
|
||||
{
|
||||
if( x < 10 )
|
||||
if (x < 10)
|
||||
{
|
||||
sb.append( " " );
|
||||
sb.append(" ");
|
||||
}
|
||||
|
||||
sb.append( x );
|
||||
sb.append( ": " );
|
||||
sb.append(x);
|
||||
sb.append(": ");
|
||||
|
||||
if( xmt == 0 )
|
||||
if (xmt == 0)
|
||||
{
|
||||
sb.append( "---.-----" );
|
||||
sb.append("---.-----");
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.append( mDecimalFormatter.format( (double)xmt/1E6d ) );
|
||||
sb.append(mDecimalFormatter.format((double) xmt / 1E6d));
|
||||
}
|
||||
sb.append( " | " );
|
||||
sb.append(" | ");
|
||||
|
||||
if( rcv == 0 )
|
||||
if (rcv == 0)
|
||||
{
|
||||
sb.append( "---.-----" );
|
||||
sb.append("---.-----");
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.append( mDecimalFormatter.format( (double)rcv/1E6d ) );
|
||||
sb.append(mDecimalFormatter.format((double) rcv / 1E6d));
|
||||
}
|
||||
|
||||
if( x == mChannelNumber )
|
||||
if (x == mChannelNumber)
|
||||
{
|
||||
sb.append( " **" );
|
||||
sb.append(" **");
|
||||
}
|
||||
|
||||
sb.append( "\n" );
|
||||
sb.append("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sb.append( "\nTalkgroups\n" );
|
||||
sb.append("\nTalkgroups\n");
|
||||
|
||||
if( mTalkgroups.isEmpty() )
|
||||
if (mTalkgroups.isEmpty())
|
||||
{
|
||||
sb.append( " None\n" );
|
||||
sb.append(" None\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
Iterator<String> it = mTalkgroups.iterator();
|
||||
|
||||
while( it.hasNext() )
|
||||
while (it.hasNext())
|
||||
{
|
||||
String tgid = it.next();
|
||||
|
||||
sb.append( " " );
|
||||
sb.append( tgid );
|
||||
sb.append( " " );
|
||||
sb.append(" ");
|
||||
sb.append(tgid);
|
||||
sb.append(" ");
|
||||
|
||||
if( hasAliasList() )
|
||||
if (hasAliasList())
|
||||
{
|
||||
Alias alias = getAliasList().getTalkgroupAlias( tgid );
|
||||
Alias alias = getAliasList().getTalkgroupAlias(tgid);
|
||||
|
||||
if( alias != null )
|
||||
if (alias != null)
|
||||
{
|
||||
sb.append( alias.getName() );
|
||||
sb.append(alias.getName());
|
||||
}
|
||||
}
|
||||
|
||||
sb.append( "\n" );
|
||||
sb.append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
sb.append( "\nRadio Unique IDs\n" );
|
||||
sb.append("\nRadio Unique IDs\n");
|
||||
|
||||
if( mUniqueIDs.isEmpty() )
|
||||
if (mUniqueIDs.isEmpty())
|
||||
{
|
||||
sb.append( " None\n" );
|
||||
sb.append(" None\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
Iterator<Integer> it = mUniqueIDs.iterator();
|
||||
|
||||
while( it.hasNext() )
|
||||
while (it.hasNext())
|
||||
{
|
||||
int uid = it.next();
|
||||
|
||||
sb.append( " " );
|
||||
sb.append( uid );
|
||||
sb.append( " " );
|
||||
sb.append(" ");
|
||||
sb.append(uid);
|
||||
sb.append(" ");
|
||||
|
||||
if( hasAliasList() )
|
||||
if (hasAliasList())
|
||||
{
|
||||
Alias alias = getAliasList().getUniqueID( uid );
|
||||
Alias alias = getAliasList().getUniqueID(uid);
|
||||
|
||||
if( alias != null )
|
||||
if (alias != null)
|
||||
{
|
||||
sb.append( alias.getName() );
|
||||
sb.append(alias.getName());
|
||||
}
|
||||
}
|
||||
|
||||
sb.append( "\n" );
|
||||
sb.append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
sb.append( "\nESNs\n" );
|
||||
sb.append("\nESNs\n");
|
||||
|
||||
if( mESNs.isEmpty() )
|
||||
if (mESNs.isEmpty())
|
||||
{
|
||||
sb.append( " None\n" );
|
||||
sb.append(" None\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
Iterator<String> it = mESNs.iterator();
|
||||
|
||||
while( it.hasNext() )
|
||||
while (it.hasNext())
|
||||
{
|
||||
String esn = it.next();
|
||||
|
||||
sb.append( " " );
|
||||
sb.append( esn );
|
||||
sb.append( " " );
|
||||
sb.append(" ");
|
||||
sb.append(esn);
|
||||
sb.append(" ");
|
||||
|
||||
if( hasAliasList() )
|
||||
if (hasAliasList())
|
||||
{
|
||||
Alias alias = getAliasList().getESNAlias( esn );
|
||||
Alias alias = getAliasList().getESNAlias(esn);
|
||||
|
||||
if( alias != null )
|
||||
if (alias != null)
|
||||
{
|
||||
sb.append( alias.getName() );
|
||||
sb.append(alias.getName());
|
||||
}
|
||||
}
|
||||
|
||||
sb.append( "\n" );
|
||||
sb.append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
sb.append( "\nNeighbor Sites\n" );
|
||||
sb.append("\nNeighbor Sites\n");
|
||||
|
||||
if( mNeighborIDs.isEmpty() )
|
||||
if (mNeighborIDs.isEmpty())
|
||||
{
|
||||
sb.append( " None\n" );
|
||||
sb.append(" None\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
Iterator<String> it = mNeighborIDs.iterator();
|
||||
|
||||
while( it.hasNext() )
|
||||
while (it.hasNext())
|
||||
{
|
||||
String neighbor = it.next();
|
||||
|
||||
sb.append( " " );
|
||||
sb.append( neighbor );
|
||||
sb.append( " " );
|
||||
sb.append(" ");
|
||||
sb.append(neighbor);
|
||||
sb.append(" ");
|
||||
|
||||
if( hasAliasList() )
|
||||
if (hasAliasList())
|
||||
{
|
||||
Alias alias = getAliasList().getSiteID( String.valueOf( neighbor ) );
|
||||
Alias alias = getAliasList().getSiteID(String.valueOf(neighbor));
|
||||
|
||||
if( alias != null )
|
||||
if (alias != null)
|
||||
{
|
||||
sb.append( alias.getName() );
|
||||
sb.append(alias.getName());
|
||||
}
|
||||
}
|
||||
|
||||
sb.append( "\n" );
|
||||
sb.append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -567,124 +567,132 @@ public class LTRNetDecoderState extends DecoderState
|
||||
/**
|
||||
* Call Detect - current channel messages indicate a call on another channel
|
||||
*/
|
||||
private void processCallDetectMessage( LTRNetMessage message )
|
||||
private void processCallDetectMessage(LTRNetMessage message)
|
||||
{
|
||||
if( !mActiveCalls.containsKey( message.getChannel() ) ||
|
||||
!mActiveCalls.get( message.getChannel() ).contentEquals( message.getTalkgroupID() ) )
|
||||
if (!mActiveCalls.containsKey(message.getChannel()) ||
|
||||
!mActiveCalls.get(message.getChannel()).contentEquals(message.getTalkgroupID()))
|
||||
{
|
||||
mActiveCalls.put( message.getChannel(), message.getTalkgroupID() );
|
||||
mActiveCalls.put(message.getChannel(), message.getTalkgroupID());
|
||||
|
||||
int channel = message.getChannel();
|
||||
|
||||
long frequency = 0;
|
||||
|
||||
if( mTransmitFrequencies.containsKey( channel ) )
|
||||
if (mTransmitFrequencies.containsKey(channel))
|
||||
{
|
||||
frequency = mTransmitFrequencies.get( channel );
|
||||
frequency = mTransmitFrequencies.get(channel);
|
||||
}
|
||||
|
||||
broadcast( new LTRCallEvent.Builder( DecoderType.LTR_NET, CallEventType.CALL_DETECT )
|
||||
.aliasList( getAliasList() )
|
||||
.channel( String.valueOf( message.getChannel() ) )
|
||||
.frequency( frequency )
|
||||
.to( message.getTalkgroupID() )
|
||||
.build() );
|
||||
broadcast(new LTRCallEvent.Builder(DecoderType.LTR_NET, CallEventType.CALL_DETECT)
|
||||
.aliasList(getAliasList())
|
||||
.channel(String.valueOf(message.getChannel()))
|
||||
.frequency(frequency)
|
||||
.to(message.getTalkgroupID())
|
||||
.build());
|
||||
}
|
||||
|
||||
broadcast( new DecoderStateEvent( this, Event.CONTINUATION, State.IDLE ) );
|
||||
broadcast(new DecoderStateEvent(this, Event.CONTINUATION, State.IDLE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the talkgroup is different than the talkgroup specified in
|
||||
* the current call event
|
||||
*/
|
||||
private boolean isDifferentTalkgroup( String talkgroup )
|
||||
private boolean isDifferentTalkgroup(String talkgroup)
|
||||
{
|
||||
return talkgroup != null &&
|
||||
mCurrentCallEvent != null &&
|
||||
mCurrentCallEvent.getToID() != null &&
|
||||
!mCurrentCallEvent.getToID().contentEquals( talkgroup );
|
||||
!mCurrentCallEvent.getToID().contentEquals(talkgroup);
|
||||
}
|
||||
|
||||
private void processCallMessage( LTRNetMessage message )
|
||||
private boolean isValidTalkgroup(String talkgroup)
|
||||
{
|
||||
return talkgroup != null && !talkgroup.matches("0-00-000");
|
||||
}
|
||||
|
||||
private void processCallMessage(LTRNetMessage message)
|
||||
{
|
||||
int group = message.getGroup();
|
||||
|
||||
/* Process call registration */
|
||||
if( group == 253 )
|
||||
if (group == 253)
|
||||
{
|
||||
broadcast( new DecoderStateEvent( this, Event.START, State.DATA ) );
|
||||
broadcast(new DecoderStateEvent(this, Event.START, State.DATA));
|
||||
mDescription = "REGISTER";
|
||||
broadcast( ChangedAttribute.DESCRIPTION );
|
||||
broadcast(ChangedAttribute.DESCRIPTION);
|
||||
}
|
||||
/* Process call */
|
||||
else
|
||||
{
|
||||
String talkgroup = message.getTalkgroupID();
|
||||
|
||||
if (isValidTalkgroup(talkgroup))
|
||||
{
|
||||
final LTRCallEvent current = getCurrentLTRCallEvent();
|
||||
|
||||
/* If this is a new call or the talkgroup is different from the current
|
||||
* call, create a new call event */
|
||||
if( current == null || isDifferentTalkgroup( talkgroup ) )
|
||||
if (current == null || isDifferentTalkgroup(talkgroup))
|
||||
{
|
||||
/* Invalidate the current call */
|
||||
if( current != null )
|
||||
if (current != null)
|
||||
{
|
||||
current.setValid( false );
|
||||
broadcast( current );
|
||||
current.setValid(false);
|
||||
broadcast(current);
|
||||
}
|
||||
|
||||
mTalkgroup = message.getTalkgroupID();
|
||||
broadcast( ChangedAttribute.TO_TALKGROUP );
|
||||
broadcast(ChangedAttribute.TO_TALKGROUP);
|
||||
|
||||
/* A talkgroup must be seen at least once before it will be added
|
||||
* to the mTalkgroups list that is used in the activity summary,
|
||||
* so that we don't pollute the summary with one-off error talkgroups */
|
||||
if( mTalkgroupsFirstHeard.contains( mTalkgroup ) )
|
||||
if (mTalkgroupsFirstHeard.contains(mTalkgroup))
|
||||
{
|
||||
mTalkgroups.add( mTalkgroup );
|
||||
mTalkgroups.add(mTalkgroup);
|
||||
}
|
||||
else
|
||||
{
|
||||
mTalkgroupsFirstHeard.add( mTalkgroup );
|
||||
mTalkgroupsFirstHeard.add(mTalkgroup);
|
||||
}
|
||||
|
||||
mTalkgroupAlias = message.getTalkgroupIDAlias();
|
||||
broadcast( ChangedAttribute.TO_TALKGROUP_ALIAS );
|
||||
broadcast(ChangedAttribute.TO_TALKGROUP_ALIAS);
|
||||
|
||||
CallEvent callEvent = new LTRCallEvent.Builder( DecoderType.LTR_NET, CallEventType.CALL )
|
||||
.aliasList( getAliasList() )
|
||||
.channel( String.valueOf( message.getChannel() ) )
|
||||
.frequency( mFrequency )
|
||||
.to( message.getTalkgroupID() )
|
||||
CallEvent callEvent = new LTRCallEvent.Builder(DecoderType.LTR_NET, CallEventType.CALL)
|
||||
.aliasList(getAliasList())
|
||||
.channel(String.valueOf(message.getChannel()))
|
||||
.frequency(mFrequency)
|
||||
.to(message.getTalkgroupID())
|
||||
.build();
|
||||
|
||||
broadcast( callEvent );
|
||||
broadcast(callEvent);
|
||||
|
||||
mCurrentCallEvent = callEvent;
|
||||
|
||||
broadcast( new Metadata( MetadataType.TO, mTalkgroup, mTalkgroupAlias, true ) );
|
||||
broadcast(new Metadata(MetadataType.TO, mTalkgroup, mTalkgroupAlias, true));
|
||||
|
||||
broadcast( new DecoderStateEvent( this, Event.START, State.CALL ) );
|
||||
broadcast(new DecoderStateEvent(this, Event.START, State.CALL));
|
||||
}
|
||||
|
||||
broadcast( new DecoderStateEvent( this, Event.CONTINUATION, State.CALL ) );
|
||||
broadcast(new DecoderStateEvent(this, Event.CONTINUATION, State.CALL));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void processCallEndMessage( LTRNetMessage message )
|
||||
private void processCallEndMessage(LTRNetMessage message)
|
||||
{
|
||||
if( mCurrentCallEvent != null &&
|
||||
mCurrentCallEvent.getCallEventType() == CallEventType.CALL )
|
||||
if (mCurrentCallEvent != null &&
|
||||
mCurrentCallEvent.getCallEventType() == CallEventType.CALL)
|
||||
{
|
||||
mCurrentCallEvent.setEnd( System.currentTimeMillis() );
|
||||
broadcast( mCurrentCallEvent );
|
||||
mCurrentCallEvent.setEnd(System.currentTimeMillis());
|
||||
broadcast(mCurrentCallEvent);
|
||||
}
|
||||
|
||||
mCurrentCallEvent = null;
|
||||
|
||||
broadcast( new DecoderStateEvent( this, Event.END, State.FADE ) );
|
||||
broadcast(new DecoderStateEvent(this, Event.END, State.FADE));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -711,23 +719,23 @@ public class LTRNetDecoderState extends DecoderState
|
||||
*/
|
||||
private void resetState()
|
||||
{
|
||||
if( mCurrentCallEvent != null && mCurrentCallEvent
|
||||
.getCallEventType() == CallEventType.CALL )
|
||||
if (mCurrentCallEvent != null && mCurrentCallEvent
|
||||
.getCallEventType() == CallEventType.CALL)
|
||||
{
|
||||
mCurrentCallEvent.end();
|
||||
broadcast( mCurrentCallEvent );
|
||||
broadcast(mCurrentCallEvent);
|
||||
}
|
||||
|
||||
mCurrentCallEvent = null;
|
||||
|
||||
mTalkgroup = null;
|
||||
broadcast( ChangedAttribute.TO_TALKGROUP );
|
||||
broadcast(ChangedAttribute.TO_TALKGROUP);
|
||||
|
||||
mTalkgroupAlias = null;
|
||||
broadcast( ChangedAttribute.TO_TALKGROUP_ALIAS );
|
||||
broadcast(ChangedAttribute.TO_TALKGROUP_ALIAS);
|
||||
|
||||
mDescription = null;
|
||||
broadcast( ChangedAttribute.DESCRIPTION );
|
||||
broadcast(ChangedAttribute.DESCRIPTION);
|
||||
}
|
||||
|
||||
public String getToTalkgroup()
|
||||
@@ -762,9 +770,9 @@ public class LTRNetDecoderState extends DecoderState
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveDecoderStateEvent( DecoderStateEvent event )
|
||||
public void receiveDecoderStateEvent(DecoderStateEvent event)
|
||||
{
|
||||
switch( event.getEvent() )
|
||||
switch (event.getEvent())
|
||||
{
|
||||
case RESET:
|
||||
resetState();
|
||||
@@ -778,7 +786,7 @@ public class LTRNetDecoderState extends DecoderState
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start( ScheduledExecutorService executor )
|
||||
public void start(ScheduledExecutorService executor)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ public class P25AudioModule extends Module implements Listener<Message>,
|
||||
IAudioPacketProvider, IMessageListener, IChannelEventListener,
|
||||
IMetadataListener, ISquelchStateListener
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger( P25AudioModule.class );
|
||||
private final static Logger mLog = LoggerFactory.getLogger(P25AudioModule.class);
|
||||
|
||||
private static final String IMBE_CODEC = "IMBE";
|
||||
|
||||
@@ -44,12 +44,12 @@ public class P25AudioModule extends Module implements Listener<Message>,
|
||||
private AudioMetadata mAudioMetadata;
|
||||
private ChannelEventListener mChannelEventListener = new ChannelEventListener();
|
||||
private SquelchStateListener mSquelchStateListener = new SquelchStateListener();
|
||||
private NonClippingGain mGain = new NonClippingGain( 5.0f, 0.95f );
|
||||
private NonClippingGain mGain = new NonClippingGain(5.0f, 0.95f);
|
||||
|
||||
public P25AudioModule( boolean record )
|
||||
public P25AudioModule(boolean record)
|
||||
{
|
||||
mSourceID = ++UNIQUE_ID;
|
||||
mAudioMetadata = new AudioMetadata( mSourceID, record );
|
||||
mAudioMetadata = new AudioMetadata(mSourceID, record);
|
||||
|
||||
loadConverter();
|
||||
}
|
||||
@@ -79,7 +79,7 @@ public class P25AudioModule extends Module implements Listener<Message>,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start( ScheduledExecutorService executor )
|
||||
public void start(ScheduledExecutorService executor)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -96,25 +96,25 @@ public class P25AudioModule extends Module implements Listener<Message>,
|
||||
* audio when the JMBE library is loaded, processed by auto-gain, and
|
||||
* broadcast to the audio packet listener.
|
||||
*/
|
||||
public void receive( Message message )
|
||||
public void receive(Message message)
|
||||
{
|
||||
if( mCanConvertAudio && mAudioPacketListener != null )
|
||||
if (mCanConvertAudio && mAudioPacketListener != null)
|
||||
{
|
||||
if( message instanceof LDUMessage )
|
||||
if (message instanceof LDUMessage)
|
||||
{
|
||||
LDUMessage ldu = (LDUMessage)message;
|
||||
LDUMessage ldu = (LDUMessage) message;
|
||||
|
||||
/* Only process unencrypted audio frames */
|
||||
if( !( ldu.isValid() && ldu.isEncrypted() ) )
|
||||
if (!(ldu.isValid() && ldu.isEncrypted()))
|
||||
{
|
||||
for( byte[] frame: ldu.getIMBEFrames() )
|
||||
for (byte[] frame : ldu.getIMBEFrames())
|
||||
{
|
||||
float[] audio = mAudioConverter.decode( frame );
|
||||
float[] audio = mAudioConverter.decode(frame);
|
||||
|
||||
audio = mGain.apply( audio );
|
||||
audio = mGain.apply(audio);
|
||||
|
||||
mAudioPacketListener.receive(
|
||||
new AudioPacket( audio, mAudioMetadata.copyOf() ) );
|
||||
new AudioPacket(audio, mAudioMetadata.copyOf()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -132,74 +132,79 @@ public class P25AudioModule extends Module implements Listener<Message>,
|
||||
|
||||
try
|
||||
{
|
||||
@SuppressWarnings( "rawtypes" )
|
||||
Class temp = Class.forName( "jmbe.JMBEAudioLibrary" );
|
||||
@SuppressWarnings("rawtypes")
|
||||
Class temp = Class.forName("jmbe.JMBEAudioLibrary");
|
||||
|
||||
library = (AudioConversionLibrary)temp.newInstance();
|
||||
library = (AudioConversionLibrary) temp.newInstance();
|
||||
|
||||
if( ( library.getMajorVersion() == 0 &&
|
||||
if ((library.getMajorVersion() == 0 &&
|
||||
library.getMinorVersion() >= 3 &&
|
||||
library.getBuildVersion() >= 1 ) ||
|
||||
library.getMajorVersion() >= 1 )
|
||||
library.getBuildVersion() >= 3) ||
|
||||
library.getMajorVersion() >= 1)
|
||||
{
|
||||
mAudioConverter = library.getAudioConverter( IMBE_CODEC,
|
||||
AudioFormats.PCM_SIGNED_48KHZ_16BITS_MONO );
|
||||
// mAudioConverter = library.getAudioConverter( IMBE_CODEC,
|
||||
// AudioFormats.PCM_SIGNED_48KHZ_16BITS_MONO );
|
||||
mAudioConverter = library.getAudioConverter(IMBE_CODEC, AudioFormats.PCM_SIGNED_8KHZ_16BITS_MONO);
|
||||
|
||||
if( mAudioConverter != null )
|
||||
if (mAudioConverter != null)
|
||||
{
|
||||
mCanConvertAudio = true;
|
||||
|
||||
if( !mLibraryLoadStatusLogged )
|
||||
if (!mLibraryLoadStatusLogged)
|
||||
{
|
||||
mLog.info( "JMBE audio conversion library successfully loaded"
|
||||
+ " - P25 audio will be available" );
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("JMBE audio conversion library [");
|
||||
sb.append(library.getVersion());
|
||||
sb.append("] successfully loaded - P25 audio will be available");
|
||||
|
||||
mLog.info(sb.toString());
|
||||
|
||||
mLibraryLoadStatusLogged = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !mLibraryLoadStatusLogged )
|
||||
if (!mLibraryLoadStatusLogged)
|
||||
{
|
||||
mLog.info( "JMBE audio conversion library NOT FOUND" );
|
||||
mLog.info("JMBE audio conversion library NOT FOUND");
|
||||
mLibraryLoadStatusLogged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mLog.warn( "JMBE library version 0.3.1 or higher is required - found: " + library.getVersion() );
|
||||
mLog.warn("JMBE library version 0.3.1 or higher is required - found: " + library.getVersion());
|
||||
}
|
||||
}
|
||||
catch ( ClassNotFoundException e1 )
|
||||
catch (ClassNotFoundException e1)
|
||||
{
|
||||
if( !mLibraryLoadStatusLogged )
|
||||
if (!mLibraryLoadStatusLogged)
|
||||
{
|
||||
mLog.error( "Couldn't find/load JMBE audio conversion library" );
|
||||
mLog.error("Couldn't find/load JMBE audio conversion library");
|
||||
mLibraryLoadStatusLogged = true;
|
||||
}
|
||||
}
|
||||
catch ( InstantiationException e1 )
|
||||
catch (InstantiationException e1)
|
||||
{
|
||||
if( !mLibraryLoadStatusLogged )
|
||||
if (!mLibraryLoadStatusLogged)
|
||||
{
|
||||
mLog.error( "Couldn't instantiate JMBE audio conversion library class" );
|
||||
mLog.error("Couldn't instantiate JMBE audio conversion library class");
|
||||
mLibraryLoadStatusLogged = true;
|
||||
}
|
||||
}
|
||||
catch ( IllegalAccessException e1 )
|
||||
catch (IllegalAccessException e1)
|
||||
{
|
||||
if( !mLibraryLoadStatusLogged )
|
||||
if (!mLibraryLoadStatusLogged)
|
||||
{
|
||||
mLog.error( "Couldn't load JMBE audio conversion library due to "
|
||||
+ "security restrictions" );
|
||||
mLog.error("Couldn't load JMBE audio conversion library due to "
|
||||
+ "security restrictions");
|
||||
mLibraryLoadStatusLogged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAudioPacketListener( Listener<AudioPacket> listener )
|
||||
public void setAudioPacketListener(Listener<AudioPacket> listener)
|
||||
{
|
||||
mAudioPacketListener = listener;
|
||||
}
|
||||
@@ -229,15 +234,15 @@ public class P25AudioModule extends Module implements Listener<Message>,
|
||||
public class ChannelEventListener implements Listener<ChannelEvent>
|
||||
{
|
||||
@Override
|
||||
public void receive( ChannelEvent event )
|
||||
public void receive(ChannelEvent event)
|
||||
{
|
||||
switch( event.getEvent() )
|
||||
switch (event.getEvent())
|
||||
{
|
||||
case NOTIFICATION_STATE_RESET:
|
||||
mAudioMetadata.reset();
|
||||
break;
|
||||
case NOTIFICATION_SELECTION_CHANGE:
|
||||
mAudioMetadata.setSelected( event.getChannel().isSelected() );
|
||||
mAudioMetadata.setSelected(event.getChannel().isSelected());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -254,12 +259,12 @@ public class P25AudioModule extends Module implements Listener<Message>,
|
||||
public class SquelchStateListener implements Listener<SquelchState>
|
||||
{
|
||||
@Override
|
||||
public void receive( SquelchState state )
|
||||
public void receive(SquelchState state)
|
||||
{
|
||||
if( state == SquelchState.SQUELCH && mAudioPacketListener != null )
|
||||
if (state == SquelchState.SQUELCH && mAudioPacketListener != null)
|
||||
{
|
||||
mAudioPacketListener.receive( new AudioPacket( AudioPacket.Type.END,
|
||||
mAudioMetadata.copyOf() ) );
|
||||
mAudioPacketListener.receive(new AudioPacket(AudioPacket.Type.END,
|
||||
mAudioMetadata.copyOf()));
|
||||
|
||||
mAudioMetadata.reset();
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class RecorderManager implements Listener<AudioPacket>
|
||||
{
|
||||
private static final Logger mLog = LoggerFactory.getLogger( RecorderManager.class );
|
||||
|
||||
public static final int AUDIO_SAMPLE_RATE = 48000;
|
||||
public static final int AUDIO_SAMPLE_RATE = 8000;
|
||||
|
||||
private Map<String,RealBufferWaveRecorder> mRecorders = new HashMap<>();
|
||||
|
||||
|
||||
@@ -30,10 +30,10 @@ public class RealToRealBufferAssembler implements RealSampleListener
|
||||
|
||||
private Listener<RealBuffer> mListener;
|
||||
|
||||
public RealToRealBufferAssembler( int bufferSize )
|
||||
public RealToRealBufferAssembler(int bufferSize)
|
||||
{
|
||||
mBufferSize = bufferSize;
|
||||
mBuffer = new float[ mBufferSize ];
|
||||
mBuffer = new float[mBufferSize];
|
||||
}
|
||||
|
||||
public void dispose()
|
||||
@@ -44,30 +44,28 @@ public class RealToRealBufferAssembler implements RealSampleListener
|
||||
|
||||
public void reset()
|
||||
{
|
||||
mBuffer = new float[ mBufferSize ];
|
||||
mBuffer = new float[mBufferSize];
|
||||
mBufferPointer = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive( float sample )
|
||||
public void receive(float sample)
|
||||
{
|
||||
if( mBufferPointer >= mBufferSize )
|
||||
mBuffer[mBufferPointer++] = sample;
|
||||
|
||||
if (mBufferPointer >= mBufferSize)
|
||||
{
|
||||
if( mListener != null )
|
||||
if (mListener != null)
|
||||
{
|
||||
mListener.receive( new RealBuffer( mBuffer ) );
|
||||
mListener.receive(new RealBuffer(mBuffer));
|
||||
}
|
||||
|
||||
mBuffer = new float[ mBufferSize ];
|
||||
mBuffer = new float[mBufferSize];
|
||||
mBufferPointer = 0;
|
||||
}
|
||||
|
||||
mBuffer[ mBufferPointer ] = sample;
|
||||
|
||||
mBufferPointer++;
|
||||
}
|
||||
|
||||
public void setListener( Listener<RealBuffer> listener )
|
||||
public void setListener(Listener<RealBuffer> listener)
|
||||
{
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
@@ -1599,7 +1599,7 @@ public abstract class RTL2832TunerController extends TunerController
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
mLog.error( "error duing rtl2832 buffer dispatcher run", e );
|
||||
mLog.error( "error during rtl2832 buffer dispatcher run", e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user