Updates pull request from Roman Tsypuk to convert the build system from

ant to gradle.  Removes linux and windows application launch scripts and
produces an executable jar with all resources included.
This commit is contained in:
Denny
2017-12-17 07:28:03 -05:00
parent a1535c4157
commit 9316599dec
981 changed files with 8368 additions and 9049 deletions

View File

@@ -0,0 +1,129 @@
package io.github.dsheirer.source.tuner.frequency;
/*******************************************************************************
* SDR Trunk
* Copyright (C) 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/>
******************************************************************************/
import io.github.dsheirer.sample.Listener;
import io.github.dsheirer.sample.real.RealBuffer;
import io.github.dsheirer.source.tuner.frequency.FrequencyChangeEvent.Event;
import io.github.dsheirer.module.Module;
import java.util.concurrent.ScheduledExecutorService;
public class DCTrackingFrequencyControl extends Module
implements Listener<RealBuffer>, IFrequencyChangeProvider
{
private static float COARSE_THRESHOLD = 0.1f;
private static float LOOP_GAIN = 0.1f;
private static float COARSE_GAIN = 1000.0f;
private static float FINE_GAIN = 100.0f;
private int mErrorCorrection = 0;
private int mMaximumFrequencyCorrection = 0;
private Listener<FrequencyChangeEvent> mListener;
/**
* DC offset Automatic Frequency Control. Monitors DC bias present in an FM
* demodulated audio stream and issues automatic frequency corrections to
* maintain the DC bias close to zero.
*
* @param maximum - maximum allowable (+/-) frequency correction value.
*/
public DCTrackingFrequencyControl( int maximum )
{
mMaximumFrequencyCorrection = maximum;
}
public void dispose()
{
mListener = null;
}
@Override
public void receive( RealBuffer buffer )
{
double sum = 0.0d;
for( float sample: buffer.getSamples() )
{
sum += sample;
}
float mean = (float)( sum / (double)buffer.getSamples().length );
float adjustment = 0.0f;
if( mean > COARSE_THRESHOLD || mean < - COARSE_THRESHOLD )
{
adjustment = mean * COARSE_GAIN;
}
else
{
adjustment = mean * FINE_GAIN;
}
setErrorCorrection( mErrorCorrection + (int)( (float)adjustment * LOOP_GAIN ) );
}
private void setErrorCorrection( int correction )
{
if( mListener != null )
{
if( correction > mMaximumFrequencyCorrection )
{
correction = mMaximumFrequencyCorrection;
}
else if( correction < -mMaximumFrequencyCorrection )
{
correction = -mMaximumFrequencyCorrection;
}
if( correction != mErrorCorrection )
{
mListener.receive( new FrequencyChangeEvent(
Event.REQUEST_CHANNEL_FREQUENCY_CORRECTION_CHANGE, correction ) );
}
}
}
@Override
public void setFrequencyChangeListener( Listener<FrequencyChangeEvent> listener )
{
mListener = listener;
}
@Override
public void removeFrequencyChangeListener()
{
mListener = null;
}
@Override
public void start( ScheduledExecutorService executor )
{
}
@Override
public void stop()
{
}
@Override
public void reset()
{
setErrorCorrection( 0 );
}
}

View File

@@ -0,0 +1,34 @@
package io.github.dsheirer.source.tuner.frequency;
public class FrequencyChangeEvent
{
public enum Event
{
NOTIFICATION_FREQUENCY_CHANGE,
NOTIFICATION_FREQUENCY_CORRECTION_CHANGE,
NOTIFICATION_CHANNEL_FREQUENCY_CORRECTION_CHANGE,
NOTIFICATION_SAMPLE_RATE_CHANGE,
REQUEST_FREQUENCY_CHANGE,
REQUEST_CHANNEL_FREQUENCY_CORRECTION_CHANGE;
}
private Event mEvent;
private Number mValue;
public FrequencyChangeEvent( Event event, Number value )
{
mEvent = event;
mValue = value;
}
public Event getEvent()
{
return mEvent;
}
public Number getValue()
{
return mValue;
}
}

View File

@@ -0,0 +1,44 @@
package io.github.dsheirer.source.tuner.frequency;
import io.github.dsheirer.sample.Listener;
import io.github.dsheirer.source.SourceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class FrequencyChangeProcessorWrapper
implements IFrequencyChangeListener, Listener<FrequencyChangeEvent>
{
private final static Logger mLog = LoggerFactory.getLogger( FrequencyChangeProcessorWrapper.class );
private IFrequencyChangeProcessor mProcessor;
/**
* Provides IFrequencyChangeListener wrapper for an IFrequencyChangeProcessor
*/
public FrequencyChangeProcessorWrapper( IFrequencyChangeProcessor handler )
{
mProcessor = handler;
}
@Override
public Listener<FrequencyChangeEvent> getFrequencyChangeListener()
{
return this;
}
@Override
public void receive( FrequencyChangeEvent event )
{
if( mProcessor != null )
{
try
{
mProcessor.frequencyChanged( event );
}
catch( SourceException se )
{
mLog.error("Error sending frequency change event to embedded processor", se);
}
}
}
}

View File

@@ -0,0 +1,255 @@
/*******************************************************************************
* 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 io.github.dsheirer.source.tuner.frequency;
import io.github.dsheirer.source.InvalidFrequencyException;
import io.github.dsheirer.source.SourceException;
import io.github.dsheirer.source.tuner.frequency.FrequencyChangeEvent.Event;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
public class FrequencyController
{
private final static Logger mLog = LoggerFactory.getLogger( FrequencyController.class );
private Tunable mTunable;
private long mFrequency = 101100000;
private long mTunedFrequency = 101100000;
private long mMinimumFrequency;
private long mMaximumFrequency;
private double mFrequencyCorrection = 0d;
private int mSampleRate = 0;
private ArrayList<IFrequencyChangeProcessor> mProcessors = new ArrayList<>();
public FrequencyController( Tunable tunable,
long minFrequency,
long maxFrequency,
double frequencyCorrection )
{
mTunable = tunable;
mMinimumFrequency = minFrequency;
mMaximumFrequency = maxFrequency;
mFrequencyCorrection = frequencyCorrection;
}
/**
* Get bandwidth/sample rate in hertz
*/
public int getBandwidth()
{
return mSampleRate;
}
/**
* Set sample rate in hertz
*/
public void setSampleRate( int sampleRate ) throws SourceException
{
mSampleRate = sampleRate;
broadcastSampleRateChange();
}
/**
* Get frequency in hertz
*/
public long getFrequency()
{
return mFrequency;
}
/**
* Set frequency
* @param frequency in hertz
* @throws SourceException if tunable doesn't support tuning a corrected
* version of the requested frequency
*/
public void setFrequency( long frequency ) throws SourceException
{
setFrequency( frequency, true );
}
/**
* Set frequency with optional broadcast of frequency change event. This
* method supports changing the frequency correction value without
* broadcasting a frequency change event.
*/
private void setFrequency( long frequency, boolean broadcastChange ) throws SourceException
{
long tunedFrequency = getTunedFrequency( frequency );
if( tunedFrequency < mMinimumFrequency )
{
throw new InvalidFrequencyException( "Requested frequency not valid", frequency, mMinimumFrequency );
}
if( tunedFrequency > mMaximumFrequency )
{
throw new InvalidFrequencyException( "Requested frequency not valid", frequency, mMaximumFrequency );
}
mFrequency = frequency;
mTunedFrequency = tunedFrequency;
if( mTunable != null )
{
mTunable.setTunedFrequency( mTunedFrequency );
}
/* Broadcast to all listeners that the frequency has changed */
if( broadcastChange )
{
broadcastFrequencyChange();
}
}
public long getTunedFrequency()
{
return mTunedFrequency;
}
public long getMinimumFrequency()
{
return mMinimumFrequency;
}
public long getMaximumFrequency()
{
return mMaximumFrequency;
}
/**
* Calculate the tuned frequency by adding frequency correction to the
* corrected frequency.
* @param correctedFrequency
*/
private long getTunedFrequency( long correctedFrequency )
{
return (long)( (double)correctedFrequency /
( 1.0 + ( mFrequencyCorrection / 1000000.0 ) ) );
}
/**
* Calculate the corrected frequency by subtracting frequency correction
* from the tuned frequency.
* @param tunedFrequency
*/
@SuppressWarnings("unused")
private long getCorrectedFrequency( long tunedFrequency )
{
return (long)( (double)tunedFrequency /
( 1.0 - ( mFrequencyCorrection / 1000000.0 ) ) );
}
public double getFrequencyCorrection()
{
return mFrequencyCorrection;
}
public void setFrequencyCorrection( double correction ) throws SourceException
{
mFrequencyCorrection = correction;
if( mFrequency > 0 )
{
setFrequency( mFrequency, true );
}
broadcastFrequencyErrorChange();
}
/**
* Adds listener to receive frequency change events
*/
//TODO: rename this to addFrequencyChangeProcessor()
public void addListener( IFrequencyChangeProcessor processor )
{
if( !mProcessors.contains( processor ) )
{
mProcessors.add( processor );
}
}
/**
* Removes listener from receiving frequency change events
*/
public void removeFrequencyChangeProcessor( IFrequencyChangeProcessor processor )
{
mProcessors.remove( processor );
}
/**
* Broadcasts a change/update to the current (uncorrected) frequency or the
* bandwidth/sample rate value.
*/
protected void broadcastFrequencyChange() throws SourceException
{
broadcastFrequencyChangeEvent(
new FrequencyChangeEvent( Event.NOTIFICATION_FREQUENCY_CHANGE, mFrequency ) );
}
/**
* Broadcast a frequency error/correction value change
*/
protected void broadcastFrequencyErrorChange() throws SourceException
{
broadcastFrequencyChangeEvent(
new FrequencyChangeEvent( Event.NOTIFICATION_FREQUENCY_CORRECTION_CHANGE, mFrequencyCorrection ) );
}
/**
* Broadcasts a sample rate change
*/
protected void broadcastSampleRateChange() throws SourceException
{
broadcastFrequencyChangeEvent(
new FrequencyChangeEvent( Event.NOTIFICATION_SAMPLE_RATE_CHANGE, mSampleRate ) );
}
public void broadcastFrequencyChangeEvent( FrequencyChangeEvent event ) throws SourceException
{
for( IFrequencyChangeProcessor processor: mProcessors )
{
processor.frequencyChanged( event );
}
}
public interface Tunable
{
/**
* Gets the tuned frequency of the device
*/
public long getTunedFrequency() throws SourceException;
/**
* Sets the tuned frequency of the device
*/
public void setTunedFrequency( long frequency ) throws SourceException;
/**
* Gets the current bandwidth setting of the device
*/
public int getCurrentSampleRate() throws SourceException;
}
}

View File

@@ -0,0 +1,36 @@
package io.github.dsheirer.source.tuner.frequency;
public class FrequencyLimitException extends Exception
{
private static final long serialVersionUID = 1L;
private long mFrequencyLimit;
private long mRequestedFrequency;
/**
* Indicates that the requested frequency is outside of the tunable bounds
* of the tuner.
* @param message
* @param frequency
*/
public FrequencyLimitException( long requestedFrequency,
long frequencyLimit )
{
super( "Requested frequency [" + requestedFrequency +
"] exceeds the limit [" + frequencyLimit + "]. Tuned "
+ "frequency was set to the limit value" );
mRequestedFrequency = requestedFrequency;
mFrequencyLimit = frequencyLimit;
}
public long getRequestedFrequency()
{
return mRequestedFrequency;
}
public long getFrequencyLimit()
{
return mFrequencyLimit;
}
}

View File

@@ -0,0 +1,34 @@
/*******************************************************************************
* 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 io.github.dsheirer.source.tuner.frequency;
import io.github.dsheirer.sample.Listener;
/**
* Interface for broadcasting changes to frequency, bandwidth, sample rate,
* and actual sample rate values to all registered listeners.
*
* Note: broadcasted frequency should be the uncorrected, or displayable
* frequency value. All frequency correction aspects should be handled within
* the device that implements the tuning of the frequency.
*/
public interface IFrequencyChangeListener
{
public Listener<FrequencyChangeEvent> getFrequencyChangeListener();
}

View File

@@ -0,0 +1,8 @@
package io.github.dsheirer.source.tuner.frequency;
import io.github.dsheirer.source.SourceException;
public interface IFrequencyChangeProcessor
{
public void frequencyChanged( FrequencyChangeEvent event ) throws SourceException;
}

View File

@@ -0,0 +1,30 @@
/*******************************************************************************
* sdrtrunk
* Copyright (C) 2014-2017 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 io.github.dsheirer.source.tuner.frequency;
import io.github.dsheirer.sample.Listener;
/**
* Provider of Frequency Change Events
*/
public interface IFrequencyChangeProvider
{
void setFrequencyChangeListener( Listener<FrequencyChangeEvent> listener );
void removeFrequencyChangeListener();
}