mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 08:37:25 -05:00
[WIP] Updating dsp modules to accept variable sample rate I/Q streams
and creating a new audio resampler.
This commit is contained in:
@@ -101,6 +101,9 @@ public class DecoderFactory
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger(DecoderFactory.class);
|
||||
|
||||
private static final int NBFM_PASS_FREQUENCY = 6000;
|
||||
private static final int NBFM_STOP_FREQUENCY = 6500;
|
||||
|
||||
//Low-pass filter with ~60 dB attenuation and 89 taps
|
||||
private static final FIRFilterSpecification MPT1327_FILTER_SPECIFICATION = FIRFilterSpecification.lowPassBuilder()
|
||||
.sampleRate( 48000 ).gridDensity( 16 ).passBandCutoff( 3200 ).passBandAmplitude( 1.0 ).passBandRipple( 0.02 )
|
||||
@@ -174,9 +177,6 @@ public class DecoderFactory
|
||||
/* Baseband low-pass filter pass and stop frequencies */
|
||||
DecodeConfiguration decodeConfig = channel.getDecodeConfiguration();
|
||||
|
||||
int iqPass = decodeConfig.getDecoderType().getChannelBandwidth() / 2;
|
||||
int iqStop = iqPass + 1250;
|
||||
|
||||
switch(decodeConfig.getDecoderType())
|
||||
{
|
||||
case AM:
|
||||
@@ -189,7 +189,7 @@ public class DecoderFactory
|
||||
case NBFM:
|
||||
modules.add(new NBFMDecoder(decodeConfig));
|
||||
modules.add(new AlwaysUnsquelchedDecoderState(DecoderType.NBFM, channel.getName()));
|
||||
modules.add(new FMDemodulatorModule(iqPass, iqStop));
|
||||
modules.add(new FMDemodulatorModule(NBFM_PASS_FREQUENCY, NBFM_STOP_FREQUENCY));
|
||||
modules.add(new DemodulatedAudioFilterModule(4000, 6000));
|
||||
modules.add(new AudioModule(metadata));
|
||||
break;
|
||||
@@ -197,14 +197,14 @@ public class DecoderFactory
|
||||
MessageDirection direction = ((DecodeConfigLTRStandard) decodeConfig).getMessageDirection();
|
||||
modules.add(new LTRStandardDecoder(aliasList, direction));
|
||||
modules.add(new LTRStandardDecoderState(aliasList));
|
||||
modules.add(new FMDemodulatorModule(iqPass, iqStop));
|
||||
modules.add(new FMDemodulatorModule(NBFM_PASS_FREQUENCY, NBFM_STOP_FREQUENCY));
|
||||
modules.add(new DemodulatedAudioFilterModule(4000, 6000));
|
||||
modules.add(new AudioModule(metadata));
|
||||
break;
|
||||
case LTR_NET:
|
||||
modules.add(new LTRNetDecoder((DecodeConfigLTRNet) decodeConfig, aliasList));
|
||||
modules.add(new LTRNetDecoderState(aliasList));
|
||||
modules.add(new FMDemodulatorModule(iqPass, iqStop));
|
||||
modules.add(new FMDemodulatorModule(NBFM_PASS_FREQUENCY, NBFM_STOP_FREQUENCY));
|
||||
modules.add(new DemodulatedAudioFilterModule(4000, 6000));
|
||||
modules.add(new AudioModule(metadata));
|
||||
break;
|
||||
@@ -227,14 +227,14 @@ public class DecoderFactory
|
||||
(aliasList != null ? aliasList.getName() : null), mptConfig.getTrafficChannelPoolSize()));
|
||||
}
|
||||
|
||||
modules.add(new FMDemodulatorModule(iqPass, iqStop));
|
||||
modules.add(new FMDemodulatorModule(NBFM_PASS_FREQUENCY, NBFM_STOP_FREQUENCY));
|
||||
modules.add(new DemodulatedAudioFilterModule(P25_C4FM_DEMOD_FILTER, 1.0f));
|
||||
modules.add(new AudioModule(metadata));
|
||||
break;
|
||||
case PASSPORT:
|
||||
modules.add(new PassportDecoder(decodeConfig, aliasList));
|
||||
modules.add(new PassportDecoderState(aliasList));
|
||||
modules.add(new FMDemodulatorModule(iqPass, iqStop));
|
||||
modules.add(new FMDemodulatorModule(NBFM_PASS_FREQUENCY, NBFM_STOP_FREQUENCY));
|
||||
modules.add(new DemodulatedAudioFilterModule(4000, 6000));
|
||||
modules.add(new AudioModule(metadata));
|
||||
break;
|
||||
@@ -247,7 +247,7 @@ public class DecoderFactory
|
||||
switch(modulation)
|
||||
{
|
||||
case C4FM:
|
||||
modules.add(new FMDemodulatorModule(P25_C4FM_IQ_FILTER));
|
||||
// modules.add(new FMDemodulatorModule(P25_C4FM_IQ_FILTER));
|
||||
modules.add(new DemodulatedAudioFilterModule(P25_C4FM_DEMOD_FILTER, 1.0f));
|
||||
modules.add(new P25_C4FMDecoder(aliasList, decodeConfig.getAFCMaximumCorrection()));
|
||||
modules.add(new P25DecoderState(aliasList, channelType, Modulation.C4FM,
|
||||
|
||||
@@ -235,7 +235,7 @@ public class P25_LSMDecoder extends P25Decoder implements IReusableComplexBuffer
|
||||
@Override
|
||||
public void receive(ReusableComplexBuffer reusableComplexBuffer)
|
||||
{
|
||||
float[] samples = reusableComplexBuffer.getCopyOfSamples();
|
||||
float[] samples = reusableComplexBuffer.getSamplesCopy();
|
||||
|
||||
//TODO: redesign the filter chain so that we can simply pass a float array ...
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ public class AMDemodulatorModule extends Module implements IReusableComplexBuffe
|
||||
@Override
|
||||
public void receive(ReusableComplexBuffer reusableComplexBuffer)
|
||||
{
|
||||
float[] samples = reusableComplexBuffer.getCopyOfSamples();
|
||||
float[] samples = reusableComplexBuffer.getSamplesCopy();
|
||||
|
||||
//TODO: redesign the filter chain so that we can simply pass a float array ...
|
||||
|
||||
|
||||
@@ -1,85 +1,84 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014-2016 Dennis Sheirer
|
||||
* sdr-trunk
|
||||
* Copyright (C) 2014-2018 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 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.
|
||||
* 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/>
|
||||
*
|
||||
* 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.module.demodulate.fm;
|
||||
|
||||
import io.github.dsheirer.dsp.filter.FilterFactory;
|
||||
import io.github.dsheirer.dsp.filter.Window;
|
||||
import io.github.dsheirer.dsp.filter.design.FilterDesignException;
|
||||
import io.github.dsheirer.dsp.filter.fir.FIRFilterSpecification;
|
||||
import io.github.dsheirer.dsp.filter.fir.complex.ComplexFIRFilter_CB_CB;
|
||||
import io.github.dsheirer.dsp.fm.FMDemodulator_CB;
|
||||
import io.github.dsheirer.module.Module;
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
import io.github.dsheirer.sample.complex.ComplexBuffer;
|
||||
import io.github.dsheirer.sample.complex.reusable.IReusableComplexBufferListener;
|
||||
import io.github.dsheirer.sample.complex.reusable.ReusableComplexBuffer;
|
||||
import io.github.dsheirer.sample.real.IUnFilteredRealBufferProvider;
|
||||
import io.github.dsheirer.sample.real.RealBuffer;
|
||||
import io.github.dsheirer.source.ISourceEventListener;
|
||||
import io.github.dsheirer.source.SourceEvent;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class FMDemodulatorModule extends Module implements IReusableComplexBufferListener, IUnFilteredRealBufferProvider
|
||||
public class FMDemodulatorModule extends Module implements ISourceEventListener, IReusableComplexBufferListener,
|
||||
IUnFilteredRealBufferProvider
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger(FMDemodulatorModule.class);
|
||||
|
||||
private static final int SAMPLE_RATE = 48000;
|
||||
|
||||
private ComplexFIRFilter_CB_CB mIQFilter;
|
||||
private FMDemodulator_CB mDemodulator;
|
||||
private ReusableBufferListener mReusableBufferListener = new ReusableBufferListener();
|
||||
private ReusableBufferProcessor mReusableBufferProcessor = new ReusableBufferProcessor();
|
||||
private SourceEventProcessor mSourceEventProcessor = new SourceEventProcessor();
|
||||
private int mPassFrequency;
|
||||
private int mStopFrequency;
|
||||
|
||||
/**
|
||||
* FM Demodulator with I/Q filter. Demodulated output is unfiltered and
|
||||
* may contain a DC component.
|
||||
* FM Demodulator with I/Q filter. Demodulated output is unfiltered and may contain a DC component.
|
||||
*
|
||||
* @param pass - pass frequency for IQ filtering prior to demodulation. This
|
||||
* frequency should be half of the signal bandwidth since the filter will
|
||||
* frequency should be less than or equal to half of the signal bandwidth since the filter will
|
||||
* be applied against each of the inphase and quadrature signals and the
|
||||
* combined pass bandwidth will be twice this value.
|
||||
* @param stop - stop frequency for IQ filtering prior to demodulation.
|
||||
*/
|
||||
public FMDemodulatorModule(int pass, int stop)
|
||||
{
|
||||
assert (stop > pass);
|
||||
|
||||
mIQFilter = new ComplexFIRFilter_CB_CB(FilterFactory.getLowPass(
|
||||
SAMPLE_RATE, pass, stop, 60, Window.WindowType.HAMMING, true), 1.0f);
|
||||
|
||||
mDemodulator = new FMDemodulator_CB(1.0f);
|
||||
mIQFilter.setListener(mDemodulator);
|
||||
}
|
||||
|
||||
public FMDemodulatorModule(float[] filter)
|
||||
{
|
||||
mIQFilter = new ComplexFIRFilter_CB_CB(filter, 1.0f);
|
||||
mDemodulator = new FMDemodulator_CB(1.0f);
|
||||
mIQFilter.setListener(mDemodulator);
|
||||
mPassFrequency = pass;
|
||||
mStopFrequency = stop;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Listener<ReusableComplexBuffer> getReusableComplexBufferListener()
|
||||
{
|
||||
return mReusableBufferListener;
|
||||
return mReusableBufferProcessor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Listener<SourceEvent> getSourceEventListener()
|
||||
{
|
||||
return mSourceEventProcessor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose()
|
||||
{
|
||||
mIQFilter.dispose();
|
||||
mIQFilter = null;
|
||||
if(mIQFilter != null)
|
||||
{
|
||||
mIQFilter.dispose();
|
||||
mIQFilter = null;
|
||||
}
|
||||
|
||||
mDemodulator.dispose();
|
||||
mDemodulator = null;
|
||||
@@ -113,17 +112,76 @@ public class FMDemodulatorModule extends Module implements IReusableComplexBuffe
|
||||
{
|
||||
}
|
||||
|
||||
public class ReusableBufferListener implements Listener<ReusableComplexBuffer>
|
||||
/**
|
||||
* Receives complex buffers and sends them through the filtering and demodulation process. Manages accounting for
|
||||
* the reusable buffers.
|
||||
*/
|
||||
public class ReusableBufferProcessor implements Listener<ReusableComplexBuffer>
|
||||
{
|
||||
@Override
|
||||
public void receive(ReusableComplexBuffer reusableComplexBuffer)
|
||||
{
|
||||
float[] samples = reusableComplexBuffer.getCopyOfSamples();
|
||||
if(mIQFilter == null)
|
||||
{
|
||||
reusableComplexBuffer.decrementUserCount();
|
||||
throw new IllegalStateException("FM demodulator module must receive a sample rate change source " +
|
||||
"event before it can process complex sample buffers");
|
||||
}
|
||||
|
||||
//TODO: redesign the filter chain so that we can simply pass a float array ...
|
||||
float[] samples = reusableComplexBuffer.getSamplesCopy();
|
||||
|
||||
mIQFilter.receive(samples);
|
||||
|
||||
mIQFilter.receive(new ComplexBuffer(samples));
|
||||
reusableComplexBuffer.decrementUserCount();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Monitors sample rate change source event(s) to setup the initial I/Q filter
|
||||
*/
|
||||
public class SourceEventProcessor implements Listener<SourceEvent>
|
||||
{
|
||||
@Override
|
||||
public void receive(SourceEvent sourceEvent)
|
||||
{
|
||||
if(sourceEvent.getEvent() == SourceEvent.Event.NOTIFICATION_SAMPLE_RATE_CHANGE)
|
||||
{
|
||||
double sampleRate = sourceEvent.getValue().doubleValue();
|
||||
|
||||
float[] filterTaps = null;
|
||||
|
||||
FIRFilterSpecification specification = FIRFilterSpecification.lowPassBuilder()
|
||||
.sampleRate(sampleRate)
|
||||
.gridDensity(16)
|
||||
.oddLength(true)
|
||||
.passBandCutoff(mPassFrequency)
|
||||
.passBandAmplitude(1.0)
|
||||
.passBandRipple(0.01)
|
||||
.stopBandStart(mStopFrequency)
|
||||
.stopBandAmplitude(0.0)
|
||||
.stopBandRipple(0.028) //Approximately 60 dB attenuation
|
||||
.build();
|
||||
|
||||
try
|
||||
{
|
||||
filterTaps = FilterFactory.getTaps(specification);
|
||||
}
|
||||
catch(FilterDesignException fde)
|
||||
{
|
||||
mLog.error("Couldn't design FM demodulator remez filter for sample rate [" + sampleRate +
|
||||
"] pass frequency [" + mPassFrequency + "] and stop frequency [" + mStopFrequency +
|
||||
"] - using sinc filter");
|
||||
}
|
||||
|
||||
if(filterTaps == null)
|
||||
{
|
||||
filterTaps = FilterFactory.getLowPass(sampleRate, mPassFrequency, mStopFrequency, 60,
|
||||
Window.WindowType.HAMMING, true);
|
||||
}
|
||||
|
||||
mIQFilter = new ComplexFIRFilter_CB_CB(filterTaps, 1.0f);
|
||||
mIQFilter.setListener(mDemodulator);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user