[WIP]Updates mixer manager and mixer source to use 8 kHz audio for

sound card inputs.

Updated DecoderFactory to only include an AM/FM demodulator when we're
using a tuner input.
This commit is contained in:
Denny
2018-06-23 09:49:40 -04:00
parent 7a830077bd
commit 19fa256c60
3 changed files with 341 additions and 355 deletions

View File

@@ -89,6 +89,7 @@ import io.github.dsheirer.module.decode.tait.Tait1200DecoderState;
import io.github.dsheirer.module.demodulate.am.AMDemodulatorModule;
import io.github.dsheirer.module.demodulate.audio.DemodulatedAudioFilterModule;
import io.github.dsheirer.module.demodulate.fm.FMDemodulatorModule;
import io.github.dsheirer.source.SourceType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -147,31 +148,44 @@ public class DecoderFactory
switch(decodeConfig.getDecoderType())
{
case AM:
modules.add(new AMDecoder(decodeConfig));
modules.add(new AlwaysUnsquelchedDecoderState(DecoderType.AM, channel.getName()));
if(channel.getSourceConfiguration().getSourceType() == SourceType.TUNER)
{
modules.add(new AMDemodulatorModule());
//TODO: update AM demodulator to produce demodulated 8 kHz audio and delete the following filter module
modules.add(new DemodulatedAudioFilterModule(4000, 6000));
}
modules.add(new AMDecoder(decodeConfig));
modules.add(new AlwaysUnsquelchedDecoderState(DecoderType.AM, channel.getName()));
modules.add(new AudioModule(metadata));
break;
case NBFM:
modules.add(new NBFMDecoder(decodeConfig));
modules.add(new AlwaysUnsquelchedDecoderState(DecoderType.NBFM, channel.getName()));
modules.add(new FMDemodulatorModule(CHANNEL_BANDWIDTH, DEMODULATED_AUDIO_SAMPLE_RATE));
modules.add(new AudioModule(metadata));
if(channel.getSourceConfiguration().getSourceType() == SourceType.TUNER)
{
modules.add(new FMDemodulatorModule(CHANNEL_BANDWIDTH, DEMODULATED_AUDIO_SAMPLE_RATE));
}
break;
case LTR_STANDARD:
MessageDirection direction = ((DecodeConfigLTRStandard) decodeConfig).getMessageDirection();
modules.add(new LTRStandardDecoder(aliasList, direction));
modules.add(new LTRStandardDecoderState(aliasList));
modules.add(new FMDemodulatorModule(CHANNEL_BANDWIDTH, DEMODULATED_AUDIO_SAMPLE_RATE));
modules.add(new AudioModule(metadata));
if(channel.getSourceConfiguration().getSourceType() == SourceType.TUNER)
{
modules.add(new FMDemodulatorModule(CHANNEL_BANDWIDTH, DEMODULATED_AUDIO_SAMPLE_RATE));
}
break;
case LTR_NET:
modules.add(new LTRNetDecoder((DecodeConfigLTRNet) decodeConfig, aliasList));
modules.add(new LTRNetDecoderState(aliasList));
modules.add(new FMDemodulatorModule(CHANNEL_BANDWIDTH, DEMODULATED_AUDIO_SAMPLE_RATE));
modules.add(new AudioModule(metadata));
if(channel.getSourceConfiguration().getSourceType() == SourceType.TUNER)
{
modules.add(new FMDemodulatorModule(CHANNEL_BANDWIDTH, DEMODULATED_AUDIO_SAMPLE_RATE));
}
break;
case MPT1327:
DecodeConfigMPT1327 mptConfig = (DecodeConfigMPT1327) decodeConfig;
@@ -179,8 +193,11 @@ public class DecoderFactory
Sync sync = mptConfig.getSync();
modules.add(new MPT1327Decoder(aliasList, sync));
modules.add(new MPT1327DecoderState(aliasList, channelMap, channelType, mptConfig.getCallTimeout() * 1000));
modules.add(new FMDemodulatorModule(CHANNEL_BANDWIDTH, DEMODULATED_AUDIO_SAMPLE_RATE));
modules.add(new AudioModule(metadata));
if(channel.getSourceConfiguration().getSourceType() == SourceType.TUNER)
{
modules.add(new FMDemodulatorModule(CHANNEL_BANDWIDTH, DEMODULATED_AUDIO_SAMPLE_RATE));
}
if(channelType == ChannelType.STANDARD)
{
@@ -192,15 +209,17 @@ public class DecoderFactory
case PASSPORT:
modules.add(new PassportDecoder(decodeConfig, aliasList));
modules.add(new PassportDecoderState(aliasList));
modules.add(new FMDemodulatorModule(CHANNEL_BANDWIDTH, DEMODULATED_AUDIO_SAMPLE_RATE));
modules.add(new AudioModule(metadata));
if(channel.getSourceConfiguration().getSourceType() == SourceType.TUNER)
{
modules.add(new FMDemodulatorModule(CHANNEL_BANDWIDTH, DEMODULATED_AUDIO_SAMPLE_RATE));
}
break;
case P25_PHASE1:
DecodeConfigP25Phase1 p25Config = (DecodeConfigP25Phase1) decodeConfig;
Modulation modulation = p25Config.getModulation();
switch(modulation)
{
case C4FM:
@@ -288,8 +307,7 @@ public class DecoderFactory
{
if(module instanceof Decoder)
{
filterSet.addFilters(getMessageFilter(
((Decoder) module).getDecoderType()));
filterSet.addFilters(getMessageFilter(((Decoder)module).getDecoderType()));
}
}

View File

@@ -1,19 +1,17 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014 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.source.mixer;
@@ -42,15 +40,15 @@ import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MixerManager
{
private final static Logger mLog =
LoggerFactory.getLogger( MixerManager.class );
private final static Logger mLog = LoggerFactory.getLogger(MixerManager.class);
private List<InputMixerConfiguration> mInputMixers = new ArrayList<>();
private List<MixerChannelConfiguration> mOutputMixers = new ArrayList<>();
private HashMap<String,MixerTunerDataLine> mMixerTuners = new HashMap<>();
private Map<String,MixerTunerDataLine> mMixerTuners = new HashMap<>();
public MixerManager()
{
@@ -80,57 +78,48 @@ public class MixerManager
if(channel == MixerChannel.MONO)
{
DataLine.Info info =
new DataLine.Info(TargetDataLine.class,
AudioFormats.PCM_SIGNED_48KHZ_16BITS_MONO );
DataLine.Info info = new DataLine.Info(TargetDataLine.class,
AudioFormats.PCM_SIGNED_8KHZ_16BITS_MONO);
TargetDataLine dataLine;
try
{
dataLine = (TargetDataLine)mixer
.getMixer().getLine( info );
dataLine = (TargetDataLine)mixer.getMixer().getLine(info);
if(dataLine != null)
{
return new RealMixerSource( dataLine,
AudioFormats.PCM_SIGNED_48KHZ_16BITS_MONO,
return new RealMixerSource(dataLine, AudioFormats.PCM_SIGNED_8KHZ_16BITS_MONO,
new ShortAdapter());
}
}
catch(LineUnavailableException e)
{
mLog.error( "couldn't get mixer data line " +
"for [" + mixerName + "] for channel [" +
mLog.error("couldn't get mixer data line for [" + mixerName + "] for channel [" +
channel.name() + "]", e);
}
}
else
{
DataLine.Info info =
new DataLine.Info(TargetDataLine.class,
AudioFormats.PCM_SIGNED_48KHZ_16BITS_STEREO );
DataLine.Info info = new DataLine.Info(TargetDataLine.class,
AudioFormats.PCM_SIGNED_8KHZ_16BITS_STEREO);
TargetDataLine dataLine;
try
{
dataLine = (TargetDataLine)mixer
.getMixer().getLine( info );
dataLine = (TargetDataLine)mixer.getMixer().getLine(info);
if(dataLine != null)
{
return new RealMixerSource( dataLine,
AudioFormats.PCM_SIGNED_48KHZ_16BITS_STEREO,
new ChannelShortAdapter(
mixerConfig.getChannel() ) );
return new RealMixerSource(dataLine, AudioFormats.PCM_SIGNED_8KHZ_16BITS_STEREO,
new ChannelShortAdapter(mixerConfig.getChannel()));
}
}
catch(LineUnavailableException e)
{
mLog.error( "couldn't get mixer data line " +
"for [" + mixerName + "] for channel [" +
mLog.error("couldn't get mixer data line for [" + mixerName + "] for channel [" +
channel.name() + "]", e);
}
}
@@ -198,11 +187,9 @@ public class MixerManager
if(inputChannels != null)
{
mInputMixers.add(
new InputMixerConfiguration( mixer, inputChannels ) );
mInputMixers.add(new InputMixerConfiguration(mixer, inputChannels));
sb.append( "\t[LOADED] Input: " + mixerInfo.getName() +
" CHANNELS: " + inputChannels + "\n" );
sb.append("\t[LOADED] Input: " + mixerInfo.getName() + " CHANNELS: " + inputChannels + "\n");
}
EnumSet<MixerChannel> outputChannels = getSupportedSourceChannels(mixer);
@@ -214,21 +201,17 @@ public class MixerManager
mOutputMixers.add(new MixerChannelConfiguration(mixer, channel));
}
sb.append( "\t[LOADED] Output: " + mixerInfo.getName() +
" CHANNELS: " + outputChannels + "\n" );
sb.append("\t[LOADED] Output: " + mixerInfo.getName() + " CHANNELS: " + outputChannels + "\n");
}
}
else
{
sb.append( "\t[NOT LOADED] Mixer:" + mixerInfo.getName() +
" - couldn't get mixer\n" );
sb.append("\t[NOT LOADED] Mixer:" + mixerInfo.getName() + " - couldn't get mixer\n");
}
}
else //Process as a Mixer-based tuner data line
else
{
TargetDataLine tdl =
getTargetDataLine( mixerInfo,
mixerTunerType.getAudioFormat() );
TargetDataLine tdl = getTargetDataLine(mixerInfo, mixerTunerType.getAudioFormat());
if(tdl != null)
{
@@ -252,7 +235,7 @@ public class MixerManager
mLog.info(sb.toString());
}
public HashMap<String,MixerTunerDataLine> getMixerTuners()
public Map<String,MixerTunerDataLine> getMixerTuners()
{
return mMixerTuners;
}
@@ -267,8 +250,7 @@ public class MixerManager
{
try
{
DataLine.Info datalineInfo=
new DataLine.Info(TargetDataLine.class, format );
DataLine.Info datalineInfo = new DataLine.Info(TargetDataLine.class, format);
retVal = (TargetDataLine)mixer.getLine(datalineInfo);
}
@@ -283,29 +265,23 @@ public class MixerManager
private EnumSet<MixerChannel> getSupportedTargetChannels(Mixer mixer)
{
DataLine.Info stereoInfo=
new DataLine.Info(TargetDataLine.class,
AudioFormats.PCM_SIGNED_48KHZ_16BITS_STEREO );
DataLine.Info stereoInfo = new DataLine.Info(TargetDataLine.class,
AudioFormats.PCM_SIGNED_8KHZ_16BITS_STEREO);
boolean stereoSupported = mixer.isLineSupported(stereoInfo);
DataLine.Info monoInfo=
new DataLine.Info(TargetDataLine.class,
AudioFormats.PCM_SIGNED_48KHZ_16BITS_MONO );
DataLine.Info monoInfo = new DataLine.Info(TargetDataLine.class,
AudioFormats.PCM_SIGNED_8KHZ_16BITS_MONO);
boolean monoSupported = mixer.isLineSupported(monoInfo);
if(stereoSupported && monoSupported)
{
return EnumSet.of( MixerChannel.LEFT,
MixerChannel.RIGHT,
MixerChannel.MONO );
return EnumSet.of(MixerChannel.LEFT, MixerChannel.RIGHT, MixerChannel.MONO);
}
else if(stereoSupported)
{
return EnumSet.of( MixerChannel.LEFT,
MixerChannel.RIGHT,
MixerChannel.MONO );
return EnumSet.of(MixerChannel.LEFT, MixerChannel.RIGHT, MixerChannel.MONO);
}
else if(monoSupported)
{
@@ -322,22 +298,18 @@ public class MixerManager
*/
private EnumSet<MixerChannel> getSupportedSourceChannels(Mixer mixer)
{
DataLine.Info stereoInfo=
new DataLine.Info(SourceDataLine.class,
AudioFormats.PCM_SIGNED_48KHZ_16BITS_STEREO );
DataLine.Info stereoInfo = new DataLine.Info(SourceDataLine.class,
AudioFormats.PCM_SIGNED_8KHZ_16BITS_STEREO);
boolean stereoSupported = mixer.isLineSupported(stereoInfo);
DataLine.Info monoInfo=
new DataLine.Info(SourceDataLine.class,
AudioFormats.PCM_SIGNED_48KHZ_16BITS_MONO );
DataLine.Info monoInfo = new DataLine.Info(SourceDataLine.class, AudioFormats.PCM_SIGNED_8KHZ_16BITS_MONO);
boolean monoSupported = mixer.isLineSupported(monoInfo);
if(stereoSupported && monoSupported)
{
return EnumSet.of( MixerChannel.MONO,
MixerChannel.STEREO );
return EnumSet.of(MixerChannel.MONO, MixerChannel.STEREO);
}
else if(stereoSupported)
{

View File

@@ -1,19 +1,17 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014 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.source.mixer;
@@ -63,9 +61,7 @@ public class RealMixerSource extends RealSource
* mixer into float array data. Can optionally invert the channel data if
* the left/right stereo channels are inverted.
*/
public RealMixerSource(TargetDataLine targetDataLine,
AudioFormat format,
ISampleAdapter sampleAdapter)
public RealMixerSource(TargetDataLine targetDataLine, AudioFormat format, ISampleAdapter sampleAdapter)
{
mTargetDataLine = targetDataLine;
mAudioFormat = format;