mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-09 23:27:24 -05:00
NBFM decoder enhancements. CTCSS and DCS squelch control. Adds deemphasis, high pass filter control, and auto-level control
146 lines
4.7 KiB
Java
146 lines
4.7 KiB
Java
/*
|
|
* *****************************************************************************
|
|
* Copyright (C) 2014-2023 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.audio;
|
|
|
|
import io.github.dsheirer.alias.AliasList;
|
|
import io.github.dsheirer.audio.squelch.ISquelchStateListener;
|
|
import io.github.dsheirer.audio.squelch.SquelchState;
|
|
import io.github.dsheirer.audio.squelch.SquelchStateEvent;
|
|
import io.github.dsheirer.dsp.filter.FilterFactory;
|
|
import io.github.dsheirer.dsp.filter.design.FilterDesignException;
|
|
import io.github.dsheirer.dsp.filter.fir.FIRFilterSpecification;
|
|
import io.github.dsheirer.dsp.filter.fir.real.IRealFilter;
|
|
import io.github.dsheirer.dsp.filter.fir.remez.RemezFIRFilterDesigner;
|
|
import io.github.dsheirer.sample.Listener;
|
|
import io.github.dsheirer.sample.real.IRealBufferListener;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import java.util.List;
|
|
|
|
/**
|
|
* Provides packaging of demodulated audio sample buffers into audio segments for broadcast to registered listeners.
|
|
* Includes audio packet metadata in constructed audio segments.
|
|
*
|
|
* Incorporates audio squelch state listener to control if audio packets are broadcast or ignored.
|
|
*/
|
|
public class AudioModule extends AbstractAudioModule implements ISquelchStateListener, IRealBufferListener,
|
|
Listener<float[]>
|
|
{
|
|
private static final Logger mLog = LoggerFactory.getLogger(AudioModule.class);
|
|
private List<AbstractAudioFilter>mAudioFilters;
|
|
private final SquelchStateListener mSquelchStateListener = new SquelchStateListener();
|
|
private SquelchState mSquelchState = SquelchState.SQUELCH;
|
|
|
|
/**
|
|
* Creates an Audio Module.
|
|
*
|
|
* @param aliasList for aliasing identifiers
|
|
* @param timeslot for this audio module
|
|
* @param maxAudioSegmentLength in milliseconds
|
|
* @param audioFilters a list of audio filters to apply to the incoming audio samples
|
|
*/
|
|
public AudioModule(AliasList aliasList, int timeslot, long maxAudioSegmentLength, List<AbstractAudioFilter> audioFilters)
|
|
{
|
|
super(aliasList, timeslot, maxAudioSegmentLength);
|
|
mAudioFilters = audioFilters;
|
|
}
|
|
|
|
/**
|
|
* Creates an Audio Module.
|
|
* @param aliasList for aliasing identifiers
|
|
* @param audioFilters a list of audio filters to apply to the incoming audio samples
|
|
*/
|
|
public AudioModule(AliasList aliasList, List<AbstractAudioFilter> audioFilters)
|
|
{
|
|
super(aliasList);
|
|
mAudioFilters = audioFilters;
|
|
}
|
|
|
|
@Override
|
|
protected int getTimeslot()
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
@Override
|
|
public void reset()
|
|
{
|
|
getIdentifierCollection().clear();
|
|
}
|
|
|
|
@Override
|
|
public void start()
|
|
{
|
|
}
|
|
|
|
@Override
|
|
public Listener<SquelchStateEvent> getSquelchStateListener()
|
|
{
|
|
return mSquelchStateListener;
|
|
}
|
|
|
|
@Override
|
|
public void receive(float[] audioBuffer)
|
|
{
|
|
if(mSquelchState == SquelchState.UNSQUELCH)
|
|
{
|
|
// apply audio filters if any (i.e. deemphasis, high pass, etc.)
|
|
if(!mAudioFilters.isEmpty())
|
|
{
|
|
for(AbstractAudioFilter filter : mAudioFilters)
|
|
{
|
|
audioBuffer = filter.filter(audioBuffer);
|
|
}
|
|
}
|
|
|
|
addAudio(audioBuffer);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public Listener<float[]> getBufferListener()
|
|
{
|
|
//Redirect received reusable buffers to the receive(buffer) method
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* Wrapper for squelch state listener
|
|
*/
|
|
public class SquelchStateListener implements Listener<SquelchStateEvent>
|
|
{
|
|
@Override
|
|
public void receive(SquelchStateEvent event)
|
|
{
|
|
SquelchState squelchState = event.getSquelchState();
|
|
|
|
if(mSquelchState != squelchState)
|
|
{
|
|
mSquelchState = squelchState;
|
|
|
|
if(mSquelchState == SquelchState.SQUELCH)
|
|
{
|
|
closeAudioSegment();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|