add external vocoder DLL support;

pull/1/head
Bryan Biedenkapp 11 months ago
parent 47403819e8
commit 08f9d8ef4e

@ -13,7 +13,6 @@
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
#if WIN32
namespace dvmconsole namespace dvmconsole
{ {
/// <summary> /// <summary>
@ -449,4 +448,3 @@ namespace dvmconsole
private static extern uint ambe_voice_enc([Out] IntPtr codeword, [In] short bitSteal, [In] IntPtr samples, [In] short sampleLength, [In] ushort cmode, [In] short n, [In] short unk, [In] IntPtr state); private static extern uint ambe_voice_enc([Out] IntPtr codeword, [In] short bitSteal, [In] IntPtr samples, [In] short sampleLength, [In] ushort cmode, [In] short n, [In] short unk, [In] IntPtr state);
} // public class AmbeVocoder } // public class AmbeVocoder
} }
#endif

@ -121,13 +121,13 @@ namespace dvmconsole
if (cpgChannel.GetKeyId() == 0 || cpgChannel.GetAlgoId() == 0) if (cpgChannel.GetKeyId() == 0 || cpgChannel.GetAlgoId() == 0)
continue; continue;
if (channelBox.crypter == null) if (channelBox.Crypter == null)
{ {
Trace.WriteLine($"Crypter is null for channel {channelBox.ChannelName}"); Trace.WriteLine($"Crypter is null for channel {channelBox.ChannelName}");
continue; continue;
} }
bool hasKey = channelBox.crypter.HasKey(cpgChannel.GetKeyId()); bool hasKey = channelBox.Crypter.HasKey(cpgChannel.GetKeyId());
KeyStatusItems.Add(new KeyStatusItem KeyStatusItems.Add(new KeyStatusItem
{ {

@ -1237,7 +1237,7 @@ namespace dvmconsole
if (true) // TODO: Disable/enable detection if (true) // TODO: Disable/enable detection
{ {
tone = channel.toneDetector.Detect(signal); tone = channel.ToneDetector.Detect(signal);
} }
if (tone > 0) if (tone > 0)
@ -1247,17 +1247,21 @@ namespace dvmconsole
} }
else else
{ {
#if WIN32 // do we have the external vocoder library?
if (channel.extFullRateVocoder == null) if (channel.ExternalVocoderEnabled)
channel.extFullRateVocoder = new AmbeVocoder(true); {
if (channel.ExtFullRateVocoder == null)
channel.ExtFullRateVocoder = new AmbeVocoder(true);
channel.extFullRateVocoder.encode(samples, out imbe); channel.ExtFullRateVocoder.encode(samples, out imbe);
#else }
if (channel.encoder == null) else
channel.encoder = new MBEEncoder(MBE_MODE.IMBE_88BIT); {
if (channel.Encoder == null)
channel.Encoder = new MBEEncoder(MBE_MODE.IMBE_88BIT);
channel.encoder.encode(samples, imbe); channel.Encoder.encode(samples, imbe);
#endif }
} }
// Log.Logger.Debug($"IMBE {FneUtils.HexDump(imbe)}"); // Log.Logger.Debug($"IMBE {FneUtils.HexDump(imbe)}");
@ -1276,17 +1280,17 @@ namespace dvmconsole
} }
} }
channel.crypter.Prepare(cpgChannel.GetAlgoId(), cpgChannel.GetKeyId(), channel.mi); channel.Crypter.Prepare(cpgChannel.GetAlgoId(), cpgChannel.GetKeyId(), channel.mi);
} }
// crypto time // crypto time
channel.crypter.Process(imbe, channel.p25N < 9U ? P25DUID.LDU1 : P25DUID.LDU2); channel.Crypter.Process(imbe, channel.p25N < 9U ? P25DUID.LDU1 : P25DUID.LDU2);
// last block of LDU2, prepare a new MI // last block of LDU2, prepare a new MI
if (channel.p25N == 17U) if (channel.p25N == 17U)
{ {
P25Crypto.CycleP25Lfsr(channel.mi); P25Crypto.CycleP25Lfsr(channel.mi);
channel.crypter.Prepare(cpgChannel.GetAlgoId(), cpgChannel.GetKeyId(), channel.mi); channel.Crypter.Prepare(cpgChannel.GetAlgoId(), cpgChannel.GetKeyId(), channel.mi);
} }
} }
@ -1451,17 +1455,18 @@ namespace dvmconsole
short[] samples = new short[FneSystemBase.MBE_SAMPLES_LENGTH]; short[] samples = new short[FneSystemBase.MBE_SAMPLES_LENGTH];
channel.crypter.Process(imbe, duid); channel.Crypter.Process(imbe, duid);
#if WIN32 // do we have the external vocoder library?
if (channel.extFullRateVocoder == null) if (channel.ExternalVocoderEnabled)
channel.extFullRateVocoder = new AmbeVocoder(true); {
if (channel.ExtFullRateVocoder == null)
channel.p25Errs = channel.extFullRateVocoder.decode(imbe, out samples); channel.ExtFullRateVocoder = new AmbeVocoder(true);
#else
channel.p25Errs = channel.decoder.decode(imbe, samples); channel.p25Errs = channel.ExtFullRateVocoder.decode(imbe, out samples);
#endif }
else
channel.p25Errs = channel.Decoder.decode(imbe, samples);
if (emergency && !channel.Emergency) if (emergency && !channel.Emergency)
{ {
@ -1527,7 +1532,7 @@ namespace dvmconsole
PeerSystem handler = fneSystemManager.GetFneSystem(system.Name); PeerSystem handler = fneSystemManager.GetFneSystem(system.Name);
if (cpgChannel.GetKeyId() != 0 && cpgChannel.GetAlgoId() != 0) if (cpgChannel.GetKeyId() != 0 && cpgChannel.GetAlgoId() != 0)
channel.crypter.AddKey(key.KeyId, e.KmmKey.KeysetItem.AlgId, key.GetKey()); channel.Crypter.AddKey(key.KeyId, e.KmmKey.KeysetItem.AlgId, key.GetKey());
} }
}); });
} }
@ -1581,8 +1586,8 @@ namespace dvmconsole
if (!systemStatuses.ContainsKey(cpgChannel.Name)) if (!systemStatuses.ContainsKey(cpgChannel.Name))
systemStatuses[cpgChannel.Name] = new SlotStatus(); systemStatuses[cpgChannel.Name] = new SlotStatus();
if (channel.decoder == null) if (channel.Decoder == null)
channel.decoder = new MBEDecoder(MBE_MODE.IMBE_88BIT); channel.Decoder = new MBEDecoder(MBE_MODE.IMBE_88BIT);
SlotStatus slot = systemStatuses[cpgChannel.Name]; SlotStatus slot = systemStatuses[cpgChannel.Name];
@ -1598,7 +1603,7 @@ namespace dvmconsole
channel.kId = (ushort)((e.Data[182] << 8) | e.Data[183]); channel.kId = (ushort)((e.Data[182] << 8) | e.Data[183]);
Array.Copy(e.Data, 184, channel.mi, 0, P25Defines.P25_MI_LENGTH); Array.Copy(e.Data, 184, channel.mi, 0, P25Defines.P25_MI_LENGTH);
channel.crypter.Prepare(channel.algId, channel.kId, channel.mi); channel.Crypter.Prepare(channel.algId, channel.kId, channel.mi);
encrypted = true; encrypted = true;
} }
@ -1776,7 +1781,7 @@ namespace dvmconsole
} }
if (channel.mi != null) if (channel.mi != null)
channel.crypter.Prepare(channel.algId, channel.kId, channel.mi); channel.Crypter.Prepare(channel.algId, channel.kId, channel.mi);
slot.RxRFS = e.SrcId; slot.RxRFS = e.SrcId;
slot.RxType = e.FrameType; slot.RxType = e.FrameType;

@ -13,6 +13,9 @@
*/ */
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
@ -65,16 +68,15 @@ namespace dvmconsole.Controls
public List<byte[]> chunkedPcm = new List<byte[]>(); public List<byte[]> chunkedPcm = new List<byte[]>();
#if WIN32 public bool ExternalVocoderEnabled = false;
public AmbeVocoder extFullRateVocoder; public AmbeVocoder ExtFullRateVocoder = null;
public AmbeVocoder extHalfRateVocoder; public AmbeVocoder ExtHalfRateVocoder = null;
#endif public MBEEncoder Encoder = null;
public MBEEncoder encoder; public MBEDecoder Decoder = null;
public MBEDecoder decoder;
public MBEToneDetector toneDetector = new MBEToneDetector(); public MBEToneDetector ToneDetector = new MBEToneDetector();
public P25Crypto crypter = new P25Crypto(); public P25Crypto Crypter = new P25Crypto();
/* /*
** Properties ** Properties
@ -267,15 +269,21 @@ namespace dvmconsole.Controls
public ChannelBox(SelectedChannelsManager selectedChannelsManager, AudioManager audioManager, string channelName, string systemName, string dstId) public ChannelBox(SelectedChannelsManager selectedChannelsManager, AudioManager audioManager, string channelName, string systemName, string dstId)
{ {
InitializeComponent(); InitializeComponent();
DataContext = this; DataContext = this;
this.selectedChannelsManager = selectedChannelsManager; this.selectedChannelsManager = selectedChannelsManager;
this.audioManager = audioManager; this.audioManager = audioManager;
flashingBackgroundManager = new FlashingBackgroundManager(this); flashingBackgroundManager = new FlashingBackgroundManager(this);
ChannelName = channelName; ChannelName = channelName;
DstId = dstId; DstId = dstId;
SystemName = $"System: {systemName}"; SystemName = $"System: {systemName}";
LastSrcId = $"Last ID: {LastSrcId}"; LastSrcId = $"Last ID: {LastSrcId}";
UpdateBackground(); UpdateBackground();
MouseLeftButtonDown += ChannelBox_MouseLeftButtonDown; MouseLeftButtonDown += ChannelBox_MouseLeftButtonDown;
grayGradient = new LinearGradientBrush grayGradient = new LinearGradientBrush
@ -315,6 +323,20 @@ namespace dvmconsole.Controls
PageSelectButton.IsEnabled = false; PageSelectButton.IsEnabled = false;
ChannelMarkerBtn.IsEnabled = false; ChannelMarkerBtn.IsEnabled = false;
} }
// initialize external AMBE vocoder
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
// if the assembly executing directory contains the external DVSI USB-3000 interface DLL
// setup the external vocoder code
if (File.Exists(Path.Combine(new string[] { Path.GetDirectoryName(path), "AMBE.DLL" })))
{
ExternalVocoderEnabled = true;
ExtFullRateVocoder = new AmbeVocoder();
ExtHalfRateVocoder = new AmbeVocoder(false);
}
} }
/// <summary> /// <summary>

Loading…
Cancel
Save

Powered by TurnKey Linux.