Merges from master branch.

This commit is contained in:
Denny
2017-12-27 10:10:51 -05:00
parent 667c50174d
commit 236df8f3f4
262 changed files with 7701 additions and 49122 deletions

View File

@@ -0,0 +1,195 @@
/*******************************************************************************
* 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.test;
import io.github.dsheirer.dsp.mixer.LowPhaseNoiseOscillator;
import io.github.dsheirer.sample.Listener;
import io.github.dsheirer.sample.complex.ComplexBuffer;
import io.github.dsheirer.util.ThreadPool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
public class SampleGenerator
{
private final static Logger mLog = LoggerFactory.getLogger(SampleGenerator.class);
private LowPhaseNoiseOscillator mOscillator;
private int mSweepUpdateInterval;
private Listener<ComplexBuffer> mListener;
private long mInterval;
private int mSamplesPerInterval;
private ScheduledFuture<?> mScheduledFuture;
/**
* Generates complex sample buffers at the specified sample rate with a unity gain tone at the specified
* frequency. This generator runs via a scheduled thread pool and generates samples at the specified time
* interval.
*
* @param sampleRate of the complex samples
* @param frequency of the tone produced by the generator
* @param interval in milliseconds for generating samples
* @param sweepUpdateRate to turn on sweeping of the tone frequency where the frequency is incremented by the
* rate specified at each interval, resetting to 1 Hz after reaching/exceeding the highest frequency.
*/
public SampleGenerator(int sampleRate, long frequency, long interval, int sweepUpdateRate)
{
if(Math.abs(sweepUpdateRate) >= sampleRate)
{
throw new IllegalArgumentException("Sweep update rate cannot be greater than sample rate");
}
mLog.debug("Sample Generator - Sample Rate:" + sampleRate + " Frequency:" + frequency);
mOscillator = new LowPhaseNoiseOscillator(sampleRate, frequency);
mInterval = interval;
mSweepUpdateInterval = sweepUpdateRate;
updateSamplesPerInterval();
}
/**
* Generates complex sample buffers at the specified sample rate with a unity gain tone at the specified
* frequency. This generator runs via a scheduled thread pool and generates samples at the specified time
* interval.
*
* @param sampleRate of the complex samples
* @param frequency of the tone produced by the generator
* @param interval in milliseconds for generating samples
*/
public SampleGenerator(int sampleRate, long frequency, long interval)
{
this(sampleRate, frequency, interval, 0);
}
/**
* Updates the number of complex samples generated per interval
*/
private void updateSamplesPerInterval()
{
mSamplesPerInterval = (int)((double)mOscillator.getSampleRate() * ((double)mInterval / 1000.0));
mLog.debug("Sample Generator - " + mSamplesPerInterval + " samples every " + mInterval + "ms");
}
/**
* Starts the generator producing samples
*/
public void start()
{
if(mScheduledFuture == null)
{
mScheduledFuture = ThreadPool.SCHEDULED.scheduleAtFixedRate(new Generator(), 0, mInterval,
TimeUnit.MILLISECONDS);
}
else
{
throw new IllegalStateException("Sample generator is already started");
}
}
/**
* Stops the generator from producing samples
*/
public void stop()
{
if(mScheduledFuture != null)
{
mScheduledFuture.cancel(true);
mScheduledFuture = null;
}
else
{
throw new IllegalStateException("Sample generator is already stopped");
}
}
/**
* Registers the listener to receive samples once the generator starts. Note: invoke this method with null
* argument to de-register the listener.
*
* @param listener to receive complex sample buffers
*/
public void setListener(Listener<ComplexBuffer> listener)
{
mListener = listener;
}
/**
* Updates the tone frequency for this generator
* @param frequency to generate
*/
public void setFrequency(long frequency)
{
mOscillator.setFrequency(frequency);
}
/**
* Current tone frequency for this generator
*/
public long getFrequency()
{
return mOscillator.getFrequency();
}
/**
* Updates the sample rate for this generator
* @param sampleRate in hertz for complex samples
*/
public void setSampleRate(int sampleRate)
{
mOscillator.setSampleRate(sampleRate);
updateSamplesPerInterval();
}
/**
* Generates a complex sample buffer and distributes the buffer to a registered listener
*/
public class Generator implements Runnable
{
@Override
public void run()
{
if(mListener != null)
{
float[] samples = mOscillator.generate(mSamplesPerInterval);
mListener.receive(new ComplexBuffer(samples));
if(mSweepUpdateInterval != 0)
{
long updatedFrequency = mOscillator.getFrequency() + mSweepUpdateInterval;
if(updatedFrequency > mOscillator.getSampleRate() / 2)
{
mOscillator.setFrequency(mOscillator.getSampleRate() / -2);
}
else if(updatedFrequency < mOscillator.getSampleRate() / -2)
{
mOscillator.setFrequency(mOscillator.getSampleRate() / 2);
}
else
{
mOscillator.setFrequency(updatedFrequency);
}
}
}
}
}
}

View File

@@ -0,0 +1,76 @@
/*******************************************************************************
* 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.test;
import io.github.dsheirer.source.tuner.Tuner;
import io.github.dsheirer.source.tuner.TunerClass;
import io.github.dsheirer.source.tuner.TunerType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Testing tuner that implements an internal oscillator to output a unity gain tone at a specified frequency offset
* from a configurable center tune frequency and sample rate
*/
public class TestTuner extends Tuner
{
private final static Logger mLog = LoggerFactory.getLogger(TestTuner.class);
private static int mInstanceCounter = 1;
private final int mInstanceID = mInstanceCounter++;
public TestTuner()
{
super("Test Tuner", new TestTunerController());
}
/**
* Returns the tuner controller cast as a test tuner controller.
*
* Note: this is a temporary method until the tuner controller interface can be updated with the start(listener)
* and stop() methods.
*/
public TestTunerController getTunerController()
{
return (TestTunerController)getTunerController();
}
@Override
public String getUniqueID()
{
return getName() + "-" + mInstanceID;
}
@Override
public TunerClass getTunerClass()
{
return TunerClass.TEST_TUNER;
}
@Override
public TunerType getTunerType()
{
return TunerClass.TEST_TUNER.getTunerType();
}
@Override
public double getSampleSize()
{
return 16.0;
}
}

View File

@@ -0,0 +1,159 @@
/*******************************************************************************
* 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.test;
import io.github.dsheirer.sample.Listener;
import io.github.dsheirer.sample.complex.ComplexBuffer;
import io.github.dsheirer.source.SourceException;
import io.github.dsheirer.source.tuner.TunerController;
import io.github.dsheirer.source.tuner.configuration.TunerConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestTunerController extends TunerController
{
private final static Logger mLog = LoggerFactory.getLogger(TestTunerController.class);
public static final long MINIMUM_FREQUENCY = 1000000l; //1 MHz
public static final long MAXIMUM_FREQUENCY = 10000000000l; //10 GHz
public static final long DEFAULT_CENTER_FREQUENCY = 100000000; //100 MHz
public static final int DEFAULT_SAMPLE_RATE = 50000; //25 kHz
public static final int DC_NOISE_BANDWIDTH = 5000; // +/-5 kHz
public static final double USABLE_BANDWIDTH = 0.90; //90% usable bandwidth - 5% unusable on either end
public static final int SPECTRAL_FRAME_RATE = 20;
public static final long SAMPLE_GENERATION_INTERVAL = 1000 / SPECTRAL_FRAME_RATE;
private SampleGenerator mSampleGenerator;
private long mReferenceFrequency = DEFAULT_CENTER_FREQUENCY;
/**
* Tuner controller testing implementation.
*/
public TestTunerController()
{
super(MINIMUM_FREQUENCY, MAXIMUM_FREQUENCY, DC_NOISE_BANDWIDTH, USABLE_BANDWIDTH);
int sweepRate = 0; //Hz per interval
mSampleGenerator = new SampleGenerator(DEFAULT_SAMPLE_RATE, 12500, SAMPLE_GENERATION_INTERVAL, sweepRate);
try
{
mLog.debug("Setting frequency ...");
mFrequencyController.setFrequency(DEFAULT_CENTER_FREQUENCY);
mLog.debug("Setting sample rate of freq controller to: " + DEFAULT_SAMPLE_RATE);
mFrequencyController.setSampleRate(DEFAULT_SAMPLE_RATE);
}
catch(Exception e)
{
mLog.error("Error!", e);
}
}
/**
* Starts the tuner controller producing samples that will be delivered to the specified listener
*/
public void start(Listener<ComplexBuffer> listener)
{
}
@Override
public void addComplexBufferListener(Listener<ComplexBuffer> listener)
{
mSampleGenerator.setListener(listener);
mSampleGenerator.start();
}
@Override
public void removeComplexBufferListener(Listener<ComplexBuffer> listener)
{
mSampleGenerator.stop();
mSampleGenerator.setListener(null);
}
/**
* Stops the tuner controller sample generator and deregisters the listener
*/
public void stop()
{
}
@Override
public void apply(TunerConfiguration config) throws SourceException
{
mLog.error("Request to apply tuner configuration was ignored");
}
/**
* Current center frequency for this tuner
* @throws SourceException
*/
@Override
public long getTunedFrequency() throws SourceException
{
return mReferenceFrequency;
}
/**
* Sets the center frequency for this tuner
* @param frequency in hertz
* @throws SourceException
*/
@Override
public void setTunedFrequency(long frequency) throws SourceException
{
mReferenceFrequency = frequency;
}
/**
* Sets the tone frequency for the sample generator. The tone frequency is offset from the center tuned frequency.
* @param toneFrequency
*/
public void setToneFrequency(long toneFrequency)
{
long frequency = toneFrequency - mReferenceFrequency;
mSampleGenerator.setFrequency(frequency);
}
/**
* Current tone frequency for this test controller.
* @return
*/
public long getToneFrequency()
{
return mReferenceFrequency + mSampleGenerator.getFrequency();
}
/**
* Current sample rate for this tuner controller
*/
@Override
public double getCurrentSampleRate()
{
return mFrequencyController.getSampleRate();
}
/**
* Sets the sample rate for this tuner controller
*/
public void setSampleRate(int sampleRate) throws SourceException
{
mFrequencyController.setSampleRate(sampleRate);
}
}