#2740 JMBE version 3.0.0 library with support for EDACS PROVOICE IMBE codec. (#2741)

- 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:
Denny Sheirer
2026-11-21 05:31:04 -05:00
committed by GitHub
parent 18f5df142e
commit 164e193ef0
17 changed files with 415 additions and 73 deletions

View File

@@ -138,7 +138,6 @@ dependencies {
//Jitpack imports //Jitpack imports
implementation 'com.github.dnault:libresample4j:master' implementation 'com.github.dnault:libresample4j:master'
implementation 'com.github.DSheirer.jmbe:api:v2.1.1'
implementation 'com.github.nwaldispuehl:java-lame:v3.98.4' implementation 'com.github.nwaldispuehl:java-lame:v3.98.4'
//mavenCentral/jcenter imports //mavenCentral/jcenter imports
@@ -158,6 +157,7 @@ dependencies {
implementation 'io.github.dsheirer:jairspyhf:1.8.1.1' //Airspy HF+ tuners - GitHub release, see settings.gradle implementation 'io.github.dsheirer:jairspyhf:1.8.1.1' //Airspy HF+ tuners - GitHub release, see settings.gradle
implementation 'io.github.dsheirer:jbladerf:2.6.0.1' //bladeRF tuners - GitHub release, see settings.gradle implementation 'io.github.dsheirer:jbladerf:2.6.0.1' //bladeRF tuners - GitHub release, see settings.gradle
implementation 'io.github.dsheirer:jhackrf:2026.01.3.1' //HackRF tuners - GitHub release, see settings.gradle implementation 'io.github.dsheirer:jhackrf:2026.01.3.1' //HackRF tuners - GitHub release, see settings.gradle
implementation 'io.github.dsheirer:jmbe-api:3.0.0' //JMBE audio codec interfaces - GitHub release, see settings.gradle
implementation 'io.github.dsheirer:jlibusb:1.0.30.1' //libusb and USB hotplug for the tuner libraries - GitHub release; not pulled in transitively implementation 'io.github.dsheirer:jlibusb:1.0.30.1' //libusb and USB hotplug for the tuner libraries - GitHub release; not pulled in transitively
implementation 'io.github.dsheirer:jhydrasdr:1.1.4.1' //HydraSDR tuners - GitHub release, see settings.gradle implementation 'io.github.dsheirer:jhydrasdr:1.1.4.1' //HydraSDR tuners - GitHub release, see settings.gradle
implementation 'io.github.dsheirer:jlimesdr:25.1.0.2' //LimeSDR tuners - GitHub release, see settings.gradle implementation 'io.github.dsheirer:jlimesdr:25.1.0.2' //LimeSDR tuners - GitHub release, see settings.gradle

View File

@@ -83,6 +83,15 @@ dependencyResolutionManagement {
content { includeModule 'io.github.dsheirer', 'jbladerf' } content { includeModule 'io.github.dsheirer', 'jbladerf' }
} }
//JMBE API is published as a GitHub release. It holds only the codec interfaces; users create the JMBE codec
//library itself with the JMBE creator, which sdrtrunk downloads from the release matching the API major version
ivy {
url = 'https://github.com/DSheirer/jmbe/releases/download'
patternLayout { artifact 'v[revision]/[artifact]-[revision].[ext]' }
metadataSources { artifact() }
content { includeModule 'io.github.dsheirer', 'jmbe-api' }
}
//radio-reference-api is published as a GitHub release. Its dependencies (jackson-dataformat-xml, slf4j-api) //radio-reference-api is published as a GitHub release. Its dependencies (jackson-dataformat-xml, slf4j-api)
//are not pulled in transitively and are declared directly in build.gradle //are not pulled in transitively and are declared directly in build.gradle
ivy { ivy {

View File

@@ -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 * 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 * 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.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import jmbe.frame.ICorrectedFrame;
import jmbe.iface.IAudioCodec; import jmbe.iface.IAudioCodec;
import jmbe.iface.IAudioCodecLibrary; import jmbe.iface.IAudioCodecLibrary;
import jmbe.iface.IAudioCodecLibraryV2; import jmbe.iface.IAudioCodecLibraryV2;
import jmbe.iface.IAudioCodecLibraryV3;
import jmbe.iface.IAudioCodecV2; import jmbe.iface.IAudioCodecV2;
import jmbe.iface.IAudioCodecV3;
import jmbe.iface.IAudioWithMetadata;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 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 Logger LOG = LoggerFactory.getLogger(JmbeAudioModule.class);
private static final String JMBE_AUDIO_LIBRARY = "JMBE"; 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 static final List<String> mLibraryLoadStatusLogged = new ArrayList<>();
private IAudioCodec mAudioCodec; private IAudioCodec mAudioCodec;
private final UserPreferences mUserPreferences; private final UserPreferences mUserPreferences;
@@ -128,6 +139,56 @@ public abstract class JmbeAudioModule extends AbstractAudioModule implements Lis
return getAudioCodec() != null; 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 @Override
public Listener<IMessage> getMessageListener() public Listener<IMessage> getMessageListener()
{ {
@@ -177,27 +238,26 @@ public abstract class JmbeAudioModule extends AbstractAudioModule implements Lis
URLClassLoader childClassLoader = new URLClassLoader(new URL[]{path.toUri().toURL()}, URLClassLoader childClassLoader = new URLClassLoader(new URL[]{path.toUri().toURL()},
this.getClass().getClassLoader()); this.getClass().getClassLoader());
try for(String className: JMBE_LIBRARY_CLASS_NAMES)
{
sLoadedJmbeAudioConverterClass = Class.forName("jmbe.JMBEAudioLibraryV2", true, childClassLoader);
}
catch(ClassNotFoundException legacyLibrary)
{ {
try 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)) //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 + LOG.error("Couldn't load JMBE audio conversion library from [" + path +
"] - neither V2 nor V1 library class was found"); "] - none of the library classes " + JMBE_LIBRARY_CLASS_NAMES + " were found");
mLibraryLoadStatusLogged.add(JMBE_AUDIO_LIBRARY); mLibraryLoadStatusLogged.add(JMBE_AUDIO_LIBRARY);
} }
} }
}
}
catch(IllegalArgumentException iae) catch(IllegalArgumentException iae)
{ {
if(!mLibraryLoadStatusLogged.contains(JMBE_AUDIO_LIBRARY + getCodecName())) if(!mLibraryLoadStatusLogged.contains(JMBE_AUDIO_LIBRARY + getCodecName()))
@@ -229,9 +289,18 @@ public abstract class JmbeAudioModule extends AbstractAudioModule implements Lis
if((library.getMajorVersion() == 1 && library.getMinorVersion() >= 0 && if((library.getMajorVersion() == 1 && library.getMinorVersion() >= 0 &&
library.getBuildVersion() >= 0) || library.getMajorVersion() >= 1) library.getBuildVersion() >= 0) || library.getMajorVersion() >= 1)
{ {
audioConverter = library instanceof IAudioCodecLibraryV2 libraryV2 ? if(library instanceof IAudioCodecLibraryV3 libraryV3)
libraryV2.getAudioConverterV2(getCodecName()) : {
library.getAudioConverter(getCodecName()); 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(); String codecStatusKey = JMBE_AUDIO_LIBRARY + ":codec:" + getCodecName();
if(!mLibraryLoadStatusLogged.contains(codecStatusKey)) if(!mLibraryLoadStatusLogged.contains(codecStatusKey))

View File

@@ -36,7 +36,7 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Collection; import java.util.Collection;
import jmbe.iface.IAudioCodec; import jmbe.frame.CorrectedIMBEFrame;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.DirectoryFileFilter; import org.apache.commons.io.filefilter.DirectoryFileFilter;
import org.apache.commons.io.filefilter.SuffixFileFilter; 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()) for(VoiceFrame voiceFrame: callSequence.getVoiceFrames())
{ {
byte[] frameBytes = voiceFrame.getFrameBytes(); 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); audioModule.addAudio(audio);
} }

View File

@@ -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 * 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 * it under the terms of the GNU General Public License as published by
@@ -171,12 +171,17 @@ public class JmbeLibraryPreferenceEditor extends VBox
try try
{ {
Version current = mUserPreferences.getJmbeLibraryPreference().getCurrentVersion(); 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")); 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) || final boolean canUpdate = (release != null) && ((current == null) ||
!current.hasMajor() || current.getMajor() != JmbeCreator.JMBE_API_MAJOR_VERSION ||
(release.getVersion().compareTo(current) > 0)); (release.getVersion().compareTo(current) > 0));
if(release != null) if(release != null)

View File

@@ -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 * 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 * 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); 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"; 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_LINUX = "creator";
public static final String CREATOR_SCRIPT_WINDOWS = "creator.bat"; public static final String CREATOR_SCRIPT_WINDOWS = "creator.bat";
@@ -331,7 +339,7 @@ public class JmbeCreator
public static void main(String[] args) 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"); Path library = Paths.get("/home/denny/temp/jmbe.jar");
JmbeCreator jmbeCreator = new JmbeCreator(release, library); JmbeCreator jmbeCreator = new JmbeCreator(release, library);

View File

@@ -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 * 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 * it under the terms of the GNU General Public License as published by
@@ -19,7 +19,6 @@
package io.github.dsheirer.jmbe.github; package io.github.dsheirer.jmbe.github;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
@@ -33,6 +32,8 @@ import java.net.http.HttpRequest;
import java.net.http.HttpResponse; import java.net.http.HttpResponse;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.StandardOpenOption; import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.List;
/** /**
* Utilities for accessing GitHub repositories and releases * Utilities for accessing GitHub repositories and releases
@@ -41,6 +42,12 @@ public class GitHub
{ {
private final static Logger mLog = LoggerFactory.getLogger(GitHub.class); 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() private GitHub()
{ {
//There's nothing to construct in this class //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 * @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(); 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 try
{ {
@@ -97,7 +107,7 @@ public class GitHub
if(response.statusCode() == 200) if(response.statusCode() == 200)
{ {
return parseResponse(response.body()); return getLatestRelease(parseReleases(response.body()), majorVersion);
} }
else else
{ {
@@ -113,13 +123,38 @@ public class GitHub
} }
/** /**
* Parses a json string containing an array or GitHub release objects and returns the latest release. * Finds the latest release in the list whose major version matches the specified major version.
* @param json string returned from URL call * @param releases to search
* @return latest release version * @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) if(json != null)
{ {
@@ -127,9 +162,7 @@ public class GitHub
if(element.isJsonArray()) if(element.isJsonArray())
{ {
JsonArray array = element.getAsJsonArray(); for(JsonElement child: element.getAsJsonArray())
for(JsonElement child: array)
{ {
if(child.isJsonObject()) if(child.isJsonObject())
{ {
@@ -138,17 +171,14 @@ public class GitHub
if(version != null) if(version != null)
{ {
if(release == null || release.getVersion().compareTo(version) < 0) releases.add(new Release(version, releaseObject));
{
release = new Release(version, releaseObject);
}
} }
} }
} }
} }
} }
return release; return releases;
} }
/** /**

View File

@@ -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 * 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 * 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(hasMajor() && other.hasMajor())
{ {
if(getMajor() != other.getMajor()) if(!getMajor().equals(other.getMajor()))
{ {
return Integer.compare(getMajor(), other.getMajor()); return Integer.compare(getMajor(), other.getMajor());
} }
@@ -175,7 +175,7 @@ public class Version implements Comparable<Version>
{ {
if(hasMinor() && other.hasMinor()) if(hasMinor() && other.hasMinor())
{ {
if(getMinor() != other.getMinor()) if(!getMinor().equals(other.getMinor()))
{ {
return Integer.compare(getMinor(), other.getMinor()); return Integer.compare(getMinor(), other.getMinor());
} }
@@ -183,7 +183,7 @@ public class Version implements Comparable<Version>
{ {
if(hasRelease() && other.hasRelease()) if(hasRelease() && other.hasRelease())
{ {
if(getRelease() != other.getRelease()) if(!getRelease().equals(other.getRelease()))
{ {
return Integer.compare(getRelease(), other.getRelease()); return Integer.compare(getRelease(), other.getRelease());
} }
@@ -200,6 +200,10 @@ public class Version implements Comparable<Version>
return 0; return 0;
} }
} }
else if(hasPatch() == other.hasPatch())
{
return 0;
}
else else
{ {
return hasPatch() ? 1 : -1; return hasPatch() ? 1 : -1;

View File

@@ -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 * 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 * 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.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import jmbe.frame.CorrectedAMBEFrame;
import jmbe.iface.IAudioWithMetadata; import jmbe.iface.IAudioWithMetadata;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -60,7 +61,7 @@ public class DMRAudioModule extends AmbeAudioModule implements IdentifierUpdateP
private SquelchStateListener mSquelchStateListener = new SquelchStateListener(); private SquelchStateListener mSquelchStateListener = new SquelchStateListener();
private ToneMetadataProcessor mToneMetadataProcessor = new ToneMetadataProcessor(); private ToneMetadataProcessor mToneMetadataProcessor = new ToneMetadataProcessor();
private Listener<IdentifierUpdateNotification> mIdentifierUpdateNotificationListener; private Listener<IdentifierUpdateNotification> mIdentifierUpdateNotificationListener;
private List<byte[]> mQueuedAmbeFrames = new ArrayList<>(); private List<AmbeFrame> mQueuedAmbeFrames = new ArrayList<>();
private boolean mEncryptedCallStateEstablished = false; private boolean mEncryptedCallStateEstablished = false;
private boolean mEncryptedCall = false; private boolean mEncryptedCall = false;
private Listener<IMessage> mMessageListener; private Listener<IMessage> mMessageListener;
@@ -175,9 +176,16 @@ public class DMRAudioModule extends AmbeAudioModule implements IdentifierUpdateP
else else
{ {
List<byte[]> frames = voiceMessage.getAMBEFrames(); 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 * Processes the audio frame. Queues the frame until encryption state is determined. Once determined, the audio
* frames are dequeued and audio is generated. * frames are dequeued and audio is generated.
*/ */
private void processAudio(byte[] frame, long timestamp) private void processAudio(AmbeFrame frame, long timestamp)
{ {
if(mEncryptedCallStateEstablished) if(mEncryptedCallStateEstablished)
{ {
@@ -212,7 +220,7 @@ public class DMRAudioModule extends AmbeAudioModule implements IdentifierUpdateP
{ {
if(!mEncryptedCall) if(!mEncryptedCall)
{ {
for(byte[] queuedFrame: mQueuedAmbeFrames) for(AmbeFrame queuedFrame: mQueuedAmbeFrames)
{ {
produceAudio(queuedFrame, timestamp); 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 try
{ {
IAudioWithMetadata audioWithMetadata = getAudioCodec().getAudioWithMetadata(frame); IAudioWithMetadata audioWithMetadata = getAudioWithMetadata(frame.frame(), frame.correctedFrame());
addAudio(audioWithMetadata.getAudio()); addAudio(audioWithMetadata.getAudio());
processMetadata(audioWithMetadata, timestamp); processMetadata(audioWithMetadata, timestamp);
} }
@@ -407,4 +415,11 @@ public class DMRAudioModule extends AmbeAudioModule implements IdentifierUpdateP
mCurrentTone = null; 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) {}
} }

View File

@@ -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 * 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 * 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.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import jmbe.frame.CorrectedAMBEFrame;
/** /**
* Base DMR Voice Message * 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_2_IV_FRAGMENT = new int[]{215, 211, 207, 203};
public static int[] FRAME_3_IV_FRAGMENT = new int[]{287, 283, 279, 275}; public static int[] FRAME_3_IV_FRAGMENT = new int[]{287, 283, 279, 275};
private Boolean mValid; 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 * 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; 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 * 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 * fragments of the initialization vector (IV) for encrypted calls. Since we don't have access to the deinterleaved

View File

@@ -35,6 +35,7 @@ import io.github.dsheirer.preference.UserPreferences;
import io.github.dsheirer.sample.Listener; import io.github.dsheirer.sample.Listener;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import jmbe.frame.CorrectedAMBEFrame;
/** /**
* NXDN AMBE audio module * 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 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 else

View File

@@ -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.module.decode.nxdn.layer3.type.AudioCodec;
import io.github.dsheirer.util.ByteUtil; import io.github.dsheirer.util.ByteUtil;
import java.nio.ByteOrder; import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import jmbe.frame.CorrectedAMBEFrame;
/** /**
* NXDN audio frame data * NXDN audio frame data
@@ -46,6 +48,7 @@ public class Audio extends NXDNMessage
private final AudioCodec mAudioCodec; private final AudioCodec mAudioCodec;
private final List<byte[]> mAudioFrames; private final List<byte[]> mAudioFrames;
private List<CorrectedAMBEFrame> mCorrectedAudioFrames;
private SACCHFragment mSACCHFragment; private SACCHFragment mSACCHFragment;
/** /**
@@ -119,6 +122,27 @@ public class Audio extends NXDNMessage
return mAudioFrames; 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 * AMBE+ audio codec format
* @return full or half rate * @return full or half rate

View File

@@ -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 * 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 * 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 io.github.dsheirer.sample.Listener;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import jmbe.frame.CorrectedIMBEFrame;
public class P25P1AudioModule extends ImbeAudioModule public class P25P1AudioModule extends ImbeAudioModule
{ {
@@ -133,9 +134,14 @@ public class P25P1AudioModule extends ImbeAudioModule
{ {
if(!mEncryptedCall) 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 else

View File

@@ -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 * 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 * 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.List;
import java.util.Map; import java.util.Map;
import java.util.Queue; import java.util.Queue;
import jmbe.frame.CorrectedAMBEFrame;
import jmbe.iface.IAudioWithMetadata; import jmbe.iface.IAudioWithMetadata;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -119,7 +120,7 @@ public class P25P2AudioModule extends AmbeAudioModule implements IdentifierUpdat
{ {
if(!mEncryptedCall) if(!mEncryptedCall)
{ {
processAudio(abstractVoiceTimeslot.getVoiceFrames(), message.getTimestamp()); processAudio(abstractVoiceTimeslot, message.getTimestamp());
} }
} }
else else
@@ -174,20 +175,27 @@ public class P25P2AudioModule extends AmbeAudioModule implements IdentifierUpdat
/** /**
* Process the audio voice frames * Process the audio voice frames
* @param voiceFrames to process * @param timeslot containing the voice frames to process
* @param timestamp of the carrier message * @param timestamp of the carrier message
*/ */
private void processAudio(List<BinaryMessage> voiceFrames, long timestamp) private void processAudio(AbstractVoiceTimeslot timeslot, long timestamp)
{ {
if(hasAudioCodec()) 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 try
{ {
IAudioWithMetadata audioWithMetadata = getAudioCodec().getAudioWithMetadata(voiceFrameBytes); IAudioWithMetadata audioWithMetadata = getAudioWithMetadata(voiceFrameBytes,
correctedFrames != null ? correctedFrames.get(x) : null);
addAudio(audioWithMetadata.getAudio()); addAudio(audioWithMetadata.getAudio());
processMetadata(audioWithMetadata, timestamp); processMetadata(audioWithMetadata, timestamp);
} }

View File

@@ -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 * 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 * 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 io.github.dsheirer.module.decode.p25.phase1.message.P25P1Message;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import jmbe.frame.CorrectedIMBEFrame;
/** /**
* LDU voice frame * 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, public static final int[] LOW_SPEED_DATA = {1392, 1393, 1394, 1395, 1396, 1397, 1398, 1399, 1408, 1409, 1410, 1411,
1412, 1413, 1414, 1415}; 1412, 1413, 1414, 1415};
private List<byte[]> mIMBIFrames; private List<byte[]> mIMBIFrames;
private List<CorrectedIMBEFrame> mCorrectedIMBEFrames;
/** /**
* Constructs an instance * Constructs an instance
@@ -98,4 +100,23 @@ public abstract class LDUMessage extends P25P1Message
return mIMBIFrames; 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;
}
} }

View File

@@ -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 * * 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 * * 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.identifier.Identifier;
import io.github.dsheirer.module.decode.p25.phase2.enumeration.DataUnitID; import io.github.dsheirer.module.decode.p25.phase2.enumeration.DataUnitID;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import jmbe.frame.CorrectedAMBEFrame;
public abstract class AbstractVoiceTimeslot extends Timeslot public abstract class AbstractVoiceTimeslot extends Timeslot
{ {
@@ -38,8 +40,31 @@ public abstract class AbstractVoiceTimeslot extends Timeslot
super(message, dataUnitID, scramblingSequence, timeslot, timestamp); super(message, dataUnitID, scramblingSequence, timeslot, timestamp);
} }
private List<CorrectedAMBEFrame> mCorrectedVoiceFrames;
public abstract List<BinaryMessage> getVoiceFrames(); 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 @Override
public List<Identifier> getIdentifiers() public List<Identifier> getIdentifiers()
{ {

View File

@@ -0,0 +1,86 @@
/*
* *****************************************************************************
* 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
* 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.jmbe;
import io.github.dsheirer.jmbe.github.GitHub;
import io.github.dsheirer.jmbe.github.Release;
import io.github.dsheirer.jmbe.github.Version;
import java.util.List;
import jmbe.iface.IAudioCodecLibrary;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Tests for selecting the JMBE creator release that matches the JMBE API major version.
*/
public class JmbeCreatorTest
{
private static final String RELEASES_JSON = """
[
{"tag_name": "v3.0.0", "name": "JMBE 3.0.0", "assets": []},
{"tag_name": "v2.1.1", "name": "JMBE 2.1.1", "assets": []},
{"tag_name": "v2.0.9", "name": "JMBE 2.0.9", "assets": []},
{"tag_name": "v1.0.9", "name": "JMBE 1.0.9", "assets": []},
{"tag_name": "not-a-version", "name": "Junk", "assets": []},
{"tag_name": "v2.1.0", "name": "JMBE 2.1.0", "assets": []}
]
""";
@Test
void apiMajorVersionMatchesApiDependency()
{
String implementationVersion = IAudioCodecLibrary.class.getPackage().getImplementationVersion();
assertNotNull(implementationVersion, "JMBE API jar manifest has no Implementation-Version");
Version apiVersion = Version.fromString(implementationVersion);
assertNotNull(apiVersion, "Unparsable JMBE API version: " + implementationVersion);
assertEquals(JmbeCreator.JMBE_API_MAJOR_VERSION, (int)apiVersion.getMajor(),
"JmbeCreator.JMBE_API_MAJOR_VERSION doesn't match the JMBE API dependency version " + implementationVersion);
}
@Test
void parseIgnoresUnversionedReleases()
{
assertEquals(5, GitHub.parseReleases(RELEASES_JSON).size());
}
@Test
void selectsLatestReleaseForMajorVersion()
{
List<Release> releases = GitHub.parseReleases(RELEASES_JSON);
assertEquals("2.1.1", GitHub.getLatestRelease(releases, 2).getVersion().toString());
assertEquals("3.0.0", GitHub.getLatestRelease(releases, 3).getVersion().toString());
assertEquals("1.0.9", GitHub.getLatestRelease(releases, 1).getVersion().toString());
assertNull(GitHub.getLatestRelease(releases, 4));
}
@Test
void versionCompare()
{
assertEquals(0, Version.fromString("v2.1.1").compareTo(Version.fromString("2.1.1")));
assertTrue(Version.fromString("v2.1.1a").compareTo(Version.fromString("v2.1.1")) > 0);
assertTrue(Version.fromString("v2.1.1").compareTo(Version.fromString("v2.1.1a")) < 0);
assertTrue(Version.fromString("v2.1.200").compareTo(Version.fromString("v2.1.199")) > 0);
assertTrue(Version.fromString("v2.10.0").compareTo(Version.fromString("v2.9.9")) > 0);
}
}