mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-21 13:05:43 -05:00
- JmbeAudioModule synthesizes from host corrected frames (jmbe-api CorrectedIMBEFrame/CorrectedAMBEFrame) when the codec is IAudioCodecV3, and falls back to the raw frame bytes for JMBE version 1 and 2 libraries - LDUMessage, P25P2 AbstractVoiceTimeslot, DMR VoiceMessage and NXDN Audio cache their corrected voice frames - P25P1, P25P2, DMR, NXDN audio modules and MBECallSequenceConverter only correct frames when the codec supports it - DMR queued voice frames carry the optional corrected frame - Error correct MBE voice frames in sdrtrunk and synthesize with JMBE V3 codecs Co-authored-by: denny <dennis.sheirer@gmail.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2024 Dennis Sheirer
|
||||
* Copyright (C) 2014-2026 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
|
||||
@@ -37,10 +37,14 @@ import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import jmbe.frame.ICorrectedFrame;
|
||||
import jmbe.iface.IAudioCodec;
|
||||
import jmbe.iface.IAudioCodecLibrary;
|
||||
import jmbe.iface.IAudioCodecLibraryV2;
|
||||
import jmbe.iface.IAudioCodecLibraryV3;
|
||||
import jmbe.iface.IAudioCodecV2;
|
||||
import jmbe.iface.IAudioCodecV3;
|
||||
import jmbe.iface.IAudioWithMetadata;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -52,6 +56,13 @@ public abstract class JmbeAudioModule extends AbstractAudioModule implements Lis
|
||||
{
|
||||
private static final Logger LOG = LoggerFactory.getLogger(JmbeAudioModule.class);
|
||||
private static final String JMBE_AUDIO_LIBRARY = "JMBE";
|
||||
|
||||
/**
|
||||
* JMBE library entry point class names, newest first. The loader uses the newest version that the library
|
||||
* provides, falling back to older versions for libraries created by older JMBE releases.
|
||||
*/
|
||||
private static final List<String> JMBE_LIBRARY_CLASS_NAMES = List.of("jmbe.JMBEAudioLibraryV3",
|
||||
"jmbe.JMBEAudioLibraryV2", "jmbe.JMBEAudioLibrary");
|
||||
private static final List<String> mLibraryLoadStatusLogged = new ArrayList<>();
|
||||
private IAudioCodec mAudioCodec;
|
||||
private final UserPreferences mUserPreferences;
|
||||
@@ -128,6 +139,56 @@ public abstract class JmbeAudioModule extends AbstractAudioModule implements Lis
|
||||
return getAudioCodec() != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the loaded audio codec can synthesize audio from a voice frame that sdrtrunk has already error
|
||||
* corrected. Only JMBE version 3 libraries support this. Version 1 and 2 libraries only accept the raw voice
|
||||
* frame bytes and perform the error detection and correction themselves.
|
||||
*
|
||||
* Callers can use this to skip creating corrected frames when the codec can't use them.
|
||||
*/
|
||||
protected boolean isCorrectedFrameSupported()
|
||||
{
|
||||
return mAudioCodec instanceof IAudioCodecV3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Synthesizes audio for the voice frame. When the codec supports it (JMBE version 3), the audio is synthesized
|
||||
* from the corrected frame so the codec doesn't repeat the error detection and correction. Otherwise, the raw
|
||||
* frame bytes are passed to the codec (JMBE version 1 and 2).
|
||||
*
|
||||
* @param frame bytes for the voice frame as transmitted
|
||||
* @param correctedFrame for the same voice frame, or null to let the codec perform the error correction
|
||||
* @return audio samples
|
||||
*/
|
||||
protected float[] getAudio(byte[] frame, ICorrectedFrame correctedFrame)
|
||||
{
|
||||
if(correctedFrame != null && mAudioCodec instanceof IAudioCodecV3 v3)
|
||||
{
|
||||
return v3.getAudio(correctedFrame);
|
||||
}
|
||||
|
||||
return mAudioCodec.getAudio(frame);
|
||||
}
|
||||
|
||||
/**
|
||||
* Synthesizes audio with optional metadata (tones, DTMF, etc.) for the voice frame. When the codec supports it
|
||||
* (JMBE version 3), the audio is synthesized from the corrected frame so the codec doesn't repeat the error
|
||||
* detection and correction. Otherwise, the raw frame bytes are passed to the codec (JMBE version 1 and 2).
|
||||
*
|
||||
* @param frame bytes for the voice frame as transmitted
|
||||
* @param correctedFrame for the same voice frame, or null to let the codec perform the error correction
|
||||
* @return audio samples with optional metadata
|
||||
*/
|
||||
protected IAudioWithMetadata getAudioWithMetadata(byte[] frame, ICorrectedFrame correctedFrame)
|
||||
{
|
||||
if(correctedFrame != null && mAudioCodec instanceof IAudioCodecV3 v3)
|
||||
{
|
||||
return v3.getAudioWithMetadata(correctedFrame);
|
||||
}
|
||||
|
||||
return mAudioCodec.getAudioWithMetadata(frame);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Listener<IMessage> getMessageListener()
|
||||
{
|
||||
@@ -177,26 +238,25 @@ public abstract class JmbeAudioModule extends AbstractAudioModule implements Lis
|
||||
URLClassLoader childClassLoader = new URLClassLoader(new URL[]{path.toUri().toURL()},
|
||||
this.getClass().getClassLoader());
|
||||
|
||||
try
|
||||
{
|
||||
sLoadedJmbeAudioConverterClass = Class.forName("jmbe.JMBEAudioLibraryV2", true, childClassLoader);
|
||||
}
|
||||
catch(ClassNotFoundException legacyLibrary)
|
||||
for(String className: JMBE_LIBRARY_CLASS_NAMES)
|
||||
{
|
||||
try
|
||||
{
|
||||
sLoadedJmbeAudioConverterClass = Class.forName("jmbe.JMBEAudioLibrary", true, childClassLoader);
|
||||
sLoadedJmbeAudioConverterClass = Class.forName(className, true, childClassLoader);
|
||||
break;
|
||||
}
|
||||
catch(ClassNotFoundException missingLibrary)
|
||||
catch(ClassNotFoundException notFound)
|
||||
{
|
||||
if(!mLibraryLoadStatusLogged.contains(JMBE_AUDIO_LIBRARY))
|
||||
{
|
||||
LOG.error("Couldn't load JMBE audio conversion library from [" + path +
|
||||
"] - neither V2 nor V1 library class was found");
|
||||
mLibraryLoadStatusLogged.add(JMBE_AUDIO_LIBRARY);
|
||||
}
|
||||
//Library doesn't contain this version of the library class - try the next older version
|
||||
}
|
||||
}
|
||||
|
||||
if(sLoadedJmbeAudioConverterClass == null && !mLibraryLoadStatusLogged.contains(JMBE_AUDIO_LIBRARY))
|
||||
{
|
||||
LOG.error("Couldn't load JMBE audio conversion library from [" + path +
|
||||
"] - none of the library classes " + JMBE_LIBRARY_CLASS_NAMES + " were found");
|
||||
mLibraryLoadStatusLogged.add(JMBE_AUDIO_LIBRARY);
|
||||
}
|
||||
}
|
||||
catch(IllegalArgumentException iae)
|
||||
{
|
||||
@@ -229,9 +289,18 @@ public abstract class JmbeAudioModule extends AbstractAudioModule implements Lis
|
||||
if((library.getMajorVersion() == 1 && library.getMinorVersion() >= 0 &&
|
||||
library.getBuildVersion() >= 0) || library.getMajorVersion() >= 1)
|
||||
{
|
||||
audioConverter = library instanceof IAudioCodecLibraryV2 libraryV2 ?
|
||||
libraryV2.getAudioConverterV2(getCodecName()) :
|
||||
library.getAudioConverter(getCodecName());
|
||||
if(library instanceof IAudioCodecLibraryV3 libraryV3)
|
||||
{
|
||||
audioConverter = libraryV3.getAudioConverterV3(getCodecName());
|
||||
}
|
||||
else if(library instanceof IAudioCodecLibraryV2 libraryV2)
|
||||
{
|
||||
audioConverter = libraryV2.getAudioConverterV2(getCodecName());
|
||||
}
|
||||
else
|
||||
{
|
||||
audioConverter = library.getAudioConverter(getCodecName());
|
||||
}
|
||||
|
||||
String codecStatusKey = JMBE_AUDIO_LIBRARY + ":codec:" + getCodecName();
|
||||
if(!mLibraryLoadStatusLogged.contains(codecStatusKey))
|
||||
|
||||
@@ -36,7 +36,7 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collection;
|
||||
import jmbe.iface.IAudioCodec;
|
||||
import jmbe.frame.CorrectedIMBEFrame;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.filefilter.DirectoryFileFilter;
|
||||
import org.apache.commons.io.filefilter.SuffixFileFilter;
|
||||
@@ -111,12 +111,15 @@ public class MBECallSequenceConverter
|
||||
}
|
||||
}
|
||||
|
||||
IAudioCodec codec = audioModule.getAudioCodec();
|
||||
boolean correctFrames = audioModule.isCorrectedFrameSupported();
|
||||
|
||||
for(VoiceFrame voiceFrame: callSequence.getVoiceFrames())
|
||||
{
|
||||
byte[] frameBytes = voiceFrame.getFrameBytes();
|
||||
float[] audio = codec.getAudio(frameBytes);
|
||||
|
||||
//Only error correct the frame in sdrtrunk when the JMBE library (version 3+) can synthesize from it
|
||||
float[] audio = audioModule.getAudio(frameBytes,
|
||||
correctFrames ? CorrectedIMBEFrame.correct(frameBytes) : null);
|
||||
audioModule.addAudio(audio);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2022 Dennis Sheirer
|
||||
* Copyright (C) 2014-2026 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
|
||||
@@ -171,12 +171,17 @@ public class JmbeLibraryPreferenceEditor extends VBox
|
||||
try
|
||||
{
|
||||
Version current = mUserPreferences.getJmbeLibraryPreference().getCurrentVersion();
|
||||
final Release release = GitHub.getLatestRelease(JmbeCreator.GITHUB_JMBE_RELEASES_URL);
|
||||
final Release release = GitHub.getLatestRelease(JmbeCreator.GITHUB_JMBE_RELEASES_URL,
|
||||
JmbeCreator.JMBE_API_MAJOR_VERSION);
|
||||
|
||||
mLog.info("Checking for JMBE Library Updates ...");
|
||||
mLog.info("Checking for JMBE Library Updates for API major version " +
|
||||
JmbeCreator.JMBE_API_MAJOR_VERSION + " ...");
|
||||
mLog.info("Current: " + (current != null ? current.toString() : "empty"));
|
||||
|
||||
//Offer the latest matching release when there is no current library, when the current library is a
|
||||
//different (incompatible) major version, or when the matching release is newer than the current one.
|
||||
final boolean canUpdate = (release != null) && ((current == null) ||
|
||||
!current.hasMajor() || current.getMajor() != JmbeCreator.JMBE_API_MAJOR_VERSION ||
|
||||
(release.getVersion().compareTo(current) > 0));
|
||||
|
||||
if(release != null)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2025 Dennis Sheirer
|
||||
* Copyright (C) 2014-2026 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
|
||||
@@ -51,6 +51,14 @@ public class JmbeCreator
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger(JmbeCreator.class);
|
||||
public static final String GITHUB_JMBE_RELEASES_URL = "https://api.github.com/repos/dsheirer/jmbe/releases";
|
||||
|
||||
/**
|
||||
* Major version of the JMBE API (com.github.DSheirer.jmbe:api) that this application is compiled against. Only
|
||||
* JMBE creator releases with this same major version are downloaded, so that a newer, incompatible major version
|
||||
* release can't replace the user's library. Update this value whenever the JMBE API dependency major version
|
||||
* changes. JmbeCreatorTest verifies that this value matches the API jar on the classpath.
|
||||
*/
|
||||
public static final int JMBE_API_MAJOR_VERSION = 3;
|
||||
public static final String CREATOR_SCRIPT_LINUX = "creator";
|
||||
public static final String CREATOR_SCRIPT_WINDOWS = "creator.bat";
|
||||
|
||||
@@ -331,7 +339,7 @@ public class JmbeCreator
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
Release release = GitHub.getLatestRelease(GITHUB_JMBE_RELEASES_URL);
|
||||
Release release = GitHub.getLatestRelease(GITHUB_JMBE_RELEASES_URL, JMBE_API_MAJOR_VERSION);
|
||||
Path library = Paths.get("/home/denny/temp/jmbe.jar");
|
||||
JmbeCreator jmbeCreator = new JmbeCreator(release, library);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* ******************************************************************************
|
||||
* Copyright (C) 2015-2020 Dennis Sheirer
|
||||
* Copyright (C) 2015-2026 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
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
package io.github.dsheirer.jmbe.github;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
@@ -33,6 +32,8 @@ import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Utilities for accessing GitHub repositories and releases
|
||||
@@ -41,6 +42,12 @@ public class GitHub
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger(GitHub.class);
|
||||
|
||||
/**
|
||||
* Query suffix to request the maximum page size. GitHub returns 30 releases per page by default, which could
|
||||
* eventually push older major version releases off of the first page.
|
||||
*/
|
||||
private static final String RELEASES_PAGE_SIZE = "?per_page=100";
|
||||
|
||||
private GitHub()
|
||||
{
|
||||
//There's nothing to construct in this class
|
||||
@@ -82,14 +89,17 @@ public class GitHub
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain the latest release object from the repository.
|
||||
* Obtains the latest release from the repository whose major version matches the specified major version. Newer
|
||||
* releases with a different major version are ignored so that the downloaded JMBE creator produces a library that
|
||||
* is compatible with the JMBE API that this application was compiled against.
|
||||
* @param repositoryURL for the GitHub api
|
||||
* @return the latest release or null
|
||||
* @param majorVersion that the release must match.
|
||||
* @return the latest matching release or null
|
||||
*/
|
||||
public static Release getLatestRelease(String repositoryURL)
|
||||
public static Release getLatestRelease(String repositoryURL, int majorVersion)
|
||||
{
|
||||
HttpClient httpClient = HttpClient.newHttpClient();
|
||||
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(repositoryURL)).build();
|
||||
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(repositoryURL + RELEASES_PAGE_SIZE)).build();
|
||||
|
||||
try
|
||||
{
|
||||
@@ -97,7 +107,7 @@ public class GitHub
|
||||
|
||||
if(response.statusCode() == 200)
|
||||
{
|
||||
return parseResponse(response.body());
|
||||
return getLatestRelease(parseReleases(response.body()), majorVersion);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -113,13 +123,38 @@ public class GitHub
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a json string containing an array or GitHub release objects and returns the latest release.
|
||||
* @param json string returned from URL call
|
||||
* @return latest release version
|
||||
* Finds the latest release in the list whose major version matches the specified major version.
|
||||
* @param releases to search
|
||||
* @param majorVersion that the release must match
|
||||
* @return latest matching release or null
|
||||
*/
|
||||
private static Release parseResponse(String json)
|
||||
public static Release getLatestRelease(List<Release> releases, int majorVersion)
|
||||
{
|
||||
Release release = null;
|
||||
Release latest = null;
|
||||
|
||||
for(Release release: releases)
|
||||
{
|
||||
Version version = release.getVersion();
|
||||
|
||||
if(version.hasMajor() && version.getMajor() == majorVersion &&
|
||||
(latest == null || latest.getVersion().compareTo(version) < 0))
|
||||
{
|
||||
latest = release;
|
||||
}
|
||||
}
|
||||
|
||||
return latest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a json string containing an array of GitHub release objects. Release objects that don't have a
|
||||
* parsable version tag are ignored.
|
||||
* @param json string returned from URL call
|
||||
* @return list of releases, possibly empty
|
||||
*/
|
||||
public static List<Release> parseReleases(String json)
|
||||
{
|
||||
List<Release> releases = new ArrayList<>();
|
||||
|
||||
if(json != null)
|
||||
{
|
||||
@@ -127,9 +162,7 @@ public class GitHub
|
||||
|
||||
if(element.isJsonArray())
|
||||
{
|
||||
JsonArray array = element.getAsJsonArray();
|
||||
|
||||
for(JsonElement child: array)
|
||||
for(JsonElement child: element.getAsJsonArray())
|
||||
{
|
||||
if(child.isJsonObject())
|
||||
{
|
||||
@@ -138,17 +171,14 @@ public class GitHub
|
||||
|
||||
if(version != null)
|
||||
{
|
||||
if(release == null || release.getVersion().compareTo(version) < 0)
|
||||
{
|
||||
release = new Release(version, releaseObject);
|
||||
}
|
||||
releases.add(new Release(version, releaseObject));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return release;
|
||||
return releases;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2020 Dennis Sheirer
|
||||
* Copyright (C) 2014-2026 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
|
||||
@@ -167,7 +167,7 @@ public class Version implements Comparable<Version>
|
||||
{
|
||||
if(hasMajor() && other.hasMajor())
|
||||
{
|
||||
if(getMajor() != other.getMajor())
|
||||
if(!getMajor().equals(other.getMajor()))
|
||||
{
|
||||
return Integer.compare(getMajor(), other.getMajor());
|
||||
}
|
||||
@@ -175,7 +175,7 @@ public class Version implements Comparable<Version>
|
||||
{
|
||||
if(hasMinor() && other.hasMinor())
|
||||
{
|
||||
if(getMinor() != other.getMinor())
|
||||
if(!getMinor().equals(other.getMinor()))
|
||||
{
|
||||
return Integer.compare(getMinor(), other.getMinor());
|
||||
}
|
||||
@@ -183,7 +183,7 @@ public class Version implements Comparable<Version>
|
||||
{
|
||||
if(hasRelease() && other.hasRelease())
|
||||
{
|
||||
if(getRelease() != other.getRelease())
|
||||
if(!getRelease().equals(other.getRelease()))
|
||||
{
|
||||
return Integer.compare(getRelease(), other.getRelease());
|
||||
}
|
||||
@@ -200,6 +200,10 @@ public class Version implements Comparable<Version>
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if(hasPatch() == other.hasPatch())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return hasPatch() ? 1 : -1;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2024 Dennis Sheirer
|
||||
* Copyright (C) 2014-2026 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
|
||||
@@ -47,6 +47,7 @@ import io.github.dsheirer.sample.Listener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import jmbe.frame.CorrectedAMBEFrame;
|
||||
import jmbe.iface.IAudioWithMetadata;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -60,7 +61,7 @@ public class DMRAudioModule extends AmbeAudioModule implements IdentifierUpdateP
|
||||
private SquelchStateListener mSquelchStateListener = new SquelchStateListener();
|
||||
private ToneMetadataProcessor mToneMetadataProcessor = new ToneMetadataProcessor();
|
||||
private Listener<IdentifierUpdateNotification> mIdentifierUpdateNotificationListener;
|
||||
private List<byte[]> mQueuedAmbeFrames = new ArrayList<>();
|
||||
private List<AmbeFrame> mQueuedAmbeFrames = new ArrayList<>();
|
||||
private boolean mEncryptedCallStateEstablished = false;
|
||||
private boolean mEncryptedCall = false;
|
||||
private Listener<IMessage> mMessageListener;
|
||||
@@ -175,9 +176,16 @@ public class DMRAudioModule extends AmbeAudioModule implements IdentifierUpdateP
|
||||
else
|
||||
{
|
||||
List<byte[]> frames = voiceMessage.getAMBEFrames();
|
||||
for(byte[] frame: frames)
|
||||
|
||||
//Only error correct the frames in sdrtrunk when the JMBE library (version 3+) can synthesize
|
||||
//from them
|
||||
List<CorrectedAMBEFrame> correctedFrames = isCorrectedFrameSupported() ?
|
||||
voiceMessage.getCorrectedAMBEFrames() : null;
|
||||
|
||||
for(int x = 0; x < frames.size(); x++)
|
||||
{
|
||||
processAudio(frame, message.getTimestamp());
|
||||
processAudio(new AmbeFrame(frames.get(x), correctedFrames != null ? correctedFrames.get(x) : null),
|
||||
message.getTimestamp());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -197,7 +205,7 @@ public class DMRAudioModule extends AmbeAudioModule implements IdentifierUpdateP
|
||||
* Processes the audio frame. Queues the frame until encryption state is determined. Once determined, the audio
|
||||
* frames are dequeued and audio is generated.
|
||||
*/
|
||||
private void processAudio(byte[] frame, long timestamp)
|
||||
private void processAudio(AmbeFrame frame, long timestamp)
|
||||
{
|
||||
if(mEncryptedCallStateEstablished)
|
||||
{
|
||||
@@ -212,7 +220,7 @@ public class DMRAudioModule extends AmbeAudioModule implements IdentifierUpdateP
|
||||
{
|
||||
if(!mEncryptedCall)
|
||||
{
|
||||
for(byte[] queuedFrame: mQueuedAmbeFrames)
|
||||
for(AmbeFrame queuedFrame: mQueuedAmbeFrames)
|
||||
{
|
||||
produceAudio(queuedFrame, timestamp);
|
||||
}
|
||||
@@ -232,11 +240,11 @@ public class DMRAudioModule extends AmbeAudioModule implements IdentifierUpdateP
|
||||
}
|
||||
}
|
||||
|
||||
private void produceAudio(byte[] frame, long timestamp)
|
||||
private void produceAudio(AmbeFrame frame, long timestamp)
|
||||
{
|
||||
try
|
||||
{
|
||||
IAudioWithMetadata audioWithMetadata = getAudioCodec().getAudioWithMetadata(frame);
|
||||
IAudioWithMetadata audioWithMetadata = getAudioWithMetadata(frame.frame(), frame.correctedFrame());
|
||||
addAudio(audioWithMetadata.getAudio());
|
||||
processMetadata(audioWithMetadata, timestamp);
|
||||
}
|
||||
@@ -407,4 +415,11 @@ public class DMRAudioModule extends AmbeAudioModule implements IdentifierUpdateP
|
||||
mCurrentTone = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* AMBE voice frame as transmitted, with the optional error corrected version of the frame.
|
||||
* @param frame bytes as transmitted
|
||||
* @param correctedFrame for the frame, or null when the JMBE library can't synthesize from corrected frames
|
||||
*/
|
||||
private record AmbeFrame(byte[] frame, CorrectedAMBEFrame correctedFrame) {}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2023 Dennis Sheirer
|
||||
* Copyright (C) 2014-2026 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
|
||||
@@ -27,6 +27,7 @@ import io.github.dsheirer.module.decode.dmr.message.DMRBurst;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import jmbe.frame.CorrectedAMBEFrame;
|
||||
|
||||
/**
|
||||
* Base DMR Voice Message
|
||||
@@ -41,6 +42,7 @@ public abstract class VoiceMessage extends DMRBurst
|
||||
public static int[] FRAME_2_IV_FRAGMENT = new int[]{215, 211, 207, 203};
|
||||
public static int[] FRAME_3_IV_FRAGMENT = new int[]{287, 283, 279, 275};
|
||||
private Boolean mValid;
|
||||
private List<CorrectedAMBEFrame> mCorrectedAMBEFrames;
|
||||
|
||||
/**
|
||||
* DMR message frame. This message comprises a 24-bit prefix and a 264-bit message frame. Outbound base
|
||||
@@ -92,6 +94,27 @@ public abstract class VoiceMessage extends DMRBurst
|
||||
return frames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Error corrected versions of the three AMBE voice frames from getAMBEFrames(), in the same order. The frames are
|
||||
* error corrected once and cached.
|
||||
*/
|
||||
public synchronized List<CorrectedAMBEFrame> getCorrectedAMBEFrames()
|
||||
{
|
||||
if(mCorrectedAMBEFrames == null)
|
||||
{
|
||||
List<CorrectedAMBEFrame> corrected = new ArrayList<>();
|
||||
|
||||
for(byte[] frame: getAMBEFrames())
|
||||
{
|
||||
corrected.add(CorrectedAMBEFrame.correct(frame));
|
||||
}
|
||||
|
||||
mCorrectedAMBEFrames = corrected;
|
||||
}
|
||||
|
||||
return mCorrectedAMBEFrames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the four low-order bits from the deinterleaved C3 vector of each of the three AMBE frames that carry
|
||||
* fragments of the initialization vector (IV) for encrypted calls. Since we don't have access to the deinterleaved
|
||||
|
||||
@@ -35,6 +35,7 @@ import io.github.dsheirer.preference.UserPreferences;
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import jmbe.frame.CorrectedAMBEFrame;
|
||||
|
||||
/**
|
||||
* NXDN AMBE audio module
|
||||
@@ -147,9 +148,14 @@ public class NXDNAudioModule extends AmbeAudioModule
|
||||
{
|
||||
if(!mEncryptedCall && mAudioCodec != null && mAudioCodec.equals(AudioCodec.HALF_RATE)) //Full rate not yet supported
|
||||
{
|
||||
for(byte[] frame : audio.getAudioFrames())
|
||||
List<byte[]> frames = audio.getAudioFrames();
|
||||
|
||||
//Only error correct the frames in sdrtrunk when the JMBE library (version 3+) can synthesize from them
|
||||
List<CorrectedAMBEFrame> correctedFrames = isCorrectedFrameSupported() ? audio.getCorrectedAudioFrames() : null;
|
||||
|
||||
for(int x = 0; x < frames.size(); x++)
|
||||
{
|
||||
addAudio(getAudioCodec().getAudio(frame));
|
||||
addAudio(getAudio(frames.get(x), correctedFrames != null ? correctedFrames.get(x) : null));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -30,8 +30,10 @@ import io.github.dsheirer.module.decode.nxdn.layer2.SACCHFragment;
|
||||
import io.github.dsheirer.module.decode.nxdn.layer3.type.AudioCodec;
|
||||
import io.github.dsheirer.util.ByteUtil;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import jmbe.frame.CorrectedAMBEFrame;
|
||||
|
||||
/**
|
||||
* NXDN audio frame data
|
||||
@@ -46,6 +48,7 @@ public class Audio extends NXDNMessage
|
||||
|
||||
private final AudioCodec mAudioCodec;
|
||||
private final List<byte[]> mAudioFrames;
|
||||
private List<CorrectedAMBEFrame> mCorrectedAudioFrames;
|
||||
private SACCHFragment mSACCHFragment;
|
||||
|
||||
/**
|
||||
@@ -119,6 +122,27 @@ public class Audio extends NXDNMessage
|
||||
return mAudioFrames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Error corrected versions of the audio frames from getAudioFrames(), in the same order. The frames are error
|
||||
* corrected once and cached.
|
||||
*/
|
||||
public synchronized List<CorrectedAMBEFrame> getCorrectedAudioFrames()
|
||||
{
|
||||
if(mCorrectedAudioFrames == null)
|
||||
{
|
||||
List<CorrectedAMBEFrame> corrected = new ArrayList<>();
|
||||
|
||||
for(byte[] frame: mAudioFrames)
|
||||
{
|
||||
corrected.add(CorrectedAMBEFrame.correct(frame));
|
||||
}
|
||||
|
||||
mCorrectedAudioFrames = corrected;
|
||||
}
|
||||
|
||||
return mCorrectedAudioFrames;
|
||||
}
|
||||
|
||||
/**
|
||||
* AMBE+ audio codec format
|
||||
* @return full or half rate
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2024 Dennis Sheirer
|
||||
* Copyright (C) 2014-2026 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
|
||||
@@ -31,6 +31,7 @@ import io.github.dsheirer.preference.UserPreferences;
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import jmbe.frame.CorrectedIMBEFrame;
|
||||
|
||||
public class P25P1AudioModule extends ImbeAudioModule
|
||||
{
|
||||
@@ -133,9 +134,14 @@ public class P25P1AudioModule extends ImbeAudioModule
|
||||
{
|
||||
if(!mEncryptedCall)
|
||||
{
|
||||
for(byte[] frame : ldu.getIMBEFrames())
|
||||
List<byte[]> frames = ldu.getIMBEFrames();
|
||||
|
||||
//Only error correct the frames in sdrtrunk when the JMBE library (version 3+) can synthesize from them
|
||||
List<CorrectedIMBEFrame> correctedFrames = isCorrectedFrameSupported() ? ldu.getCorrectedIMBEFrames() : null;
|
||||
|
||||
for(int x = 0; x < frames.size(); x++)
|
||||
{
|
||||
addAudio(getAudioCodec().getAudio(frame));
|
||||
addAudio(getAudio(frames.get(x), correctedFrames != null ? correctedFrames.get(x) : null));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2024 Dennis Sheirer
|
||||
* Copyright (C) 2014-2026 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
|
||||
@@ -48,6 +48,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import jmbe.frame.CorrectedAMBEFrame;
|
||||
import jmbe.iface.IAudioWithMetadata;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -119,7 +120,7 @@ public class P25P2AudioModule extends AmbeAudioModule implements IdentifierUpdat
|
||||
{
|
||||
if(!mEncryptedCall)
|
||||
{
|
||||
processAudio(abstractVoiceTimeslot.getVoiceFrames(), message.getTimestamp());
|
||||
processAudio(abstractVoiceTimeslot, message.getTimestamp());
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -174,20 +175,27 @@ public class P25P2AudioModule extends AmbeAudioModule implements IdentifierUpdat
|
||||
|
||||
/**
|
||||
* Process the audio voice frames
|
||||
* @param voiceFrames to process
|
||||
* @param timeslot containing the voice frames to process
|
||||
* @param timestamp of the carrier message
|
||||
*/
|
||||
private void processAudio(List<BinaryMessage> voiceFrames, long timestamp)
|
||||
private void processAudio(AbstractVoiceTimeslot timeslot, long timestamp)
|
||||
{
|
||||
if(hasAudioCodec())
|
||||
{
|
||||
for(BinaryMessage voiceFrame: voiceFrames)
|
||||
List<BinaryMessage> voiceFrames = timeslot.getVoiceFrames();
|
||||
|
||||
//Only error correct the frames in sdrtrunk when the JMBE library (version 3+) can synthesize from them
|
||||
List<CorrectedAMBEFrame> correctedFrames = isCorrectedFrameSupported() ?
|
||||
timeslot.getCorrectedVoiceFrames() : null;
|
||||
|
||||
for(int x = 0; x < voiceFrames.size(); x++)
|
||||
{
|
||||
byte[] voiceFrameBytes = voiceFrame.getBytes();
|
||||
byte[] voiceFrameBytes = voiceFrames.get(x).getBytes();
|
||||
|
||||
try
|
||||
{
|
||||
IAudioWithMetadata audioWithMetadata = getAudioCodec().getAudioWithMetadata(voiceFrameBytes);
|
||||
IAudioWithMetadata audioWithMetadata = getAudioWithMetadata(voiceFrameBytes,
|
||||
correctedFrames != null ? correctedFrames.get(x) : null);
|
||||
addAudio(audioWithMetadata.getAudio());
|
||||
processMetadata(audioWithMetadata, timestamp);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2024 Dennis Sheirer
|
||||
* Copyright (C) 2014-2026 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
|
||||
@@ -23,6 +23,7 @@ import io.github.dsheirer.bits.CorrectedBinaryMessage;
|
||||
import io.github.dsheirer.module.decode.p25.phase1.message.P25P1Message;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import jmbe.frame.CorrectedIMBEFrame;
|
||||
|
||||
/**
|
||||
* LDU voice frame
|
||||
@@ -41,6 +42,7 @@ public abstract class LDUMessage extends P25P1Message
|
||||
public static final int[] LOW_SPEED_DATA = {1392, 1393, 1394, 1395, 1396, 1397, 1398, 1399, 1408, 1409, 1410, 1411,
|
||||
1412, 1413, 1414, 1415};
|
||||
private List<byte[]> mIMBIFrames;
|
||||
private List<CorrectedIMBEFrame> mCorrectedIMBEFrames;
|
||||
|
||||
/**
|
||||
* Constructs an instance
|
||||
@@ -98,4 +100,23 @@ public abstract class LDUMessage extends P25P1Message
|
||||
|
||||
return mIMBIFrames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Error corrected versions of the 9 IMBE voice frames from getIMBEFrames(), in the same order. The frames are
|
||||
* deinterleaved, derandomized, and error corrected once and cached.
|
||||
*/
|
||||
public synchronized List<CorrectedIMBEFrame> getCorrectedIMBEFrames()
|
||||
{
|
||||
if(mCorrectedIMBEFrames == null)
|
||||
{
|
||||
mCorrectedIMBEFrames = new ArrayList<>();
|
||||
|
||||
for(byte[] frame: getIMBEFrames())
|
||||
{
|
||||
mCorrectedIMBEFrames.add(CorrectedIMBEFrame.correct(frame));
|
||||
}
|
||||
}
|
||||
|
||||
return mCorrectedIMBEFrames;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
*
|
||||
* * ******************************************************************************
|
||||
* * Copyright (C) 2014-2019 Dennis Sheirer
|
||||
* * Copyright (C) 2014-2026 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
|
||||
@@ -27,8 +27,10 @@ import io.github.dsheirer.bits.CorrectedBinaryMessage;
|
||||
import io.github.dsheirer.identifier.Identifier;
|
||||
import io.github.dsheirer.module.decode.p25.phase2.enumeration.DataUnitID;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import jmbe.frame.CorrectedAMBEFrame;
|
||||
|
||||
public abstract class AbstractVoiceTimeslot extends Timeslot
|
||||
{
|
||||
@@ -38,8 +40,31 @@ public abstract class AbstractVoiceTimeslot extends Timeslot
|
||||
super(message, dataUnitID, scramblingSequence, timeslot, timestamp);
|
||||
}
|
||||
|
||||
private List<CorrectedAMBEFrame> mCorrectedVoiceFrames;
|
||||
|
||||
public abstract List<BinaryMessage> getVoiceFrames();
|
||||
|
||||
/**
|
||||
* Error corrected versions of the AMBE voice frames from getVoiceFrames(), in the same order. The frames are
|
||||
* error corrected once and cached.
|
||||
*/
|
||||
public synchronized List<CorrectedAMBEFrame> getCorrectedVoiceFrames()
|
||||
{
|
||||
if(mCorrectedVoiceFrames == null)
|
||||
{
|
||||
List<CorrectedAMBEFrame> corrected = new ArrayList<>();
|
||||
|
||||
for(BinaryMessage frame: getVoiceFrames())
|
||||
{
|
||||
corrected.add(CorrectedAMBEFrame.correct(frame.getBytes()));
|
||||
}
|
||||
|
||||
mCorrectedVoiceFrames = corrected;
|
||||
}
|
||||
|
||||
return mCorrectedVoiceFrames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Identifier> getIdentifiers()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user