jmbe
Copyright (C) 2015-2020 Dennis Sheirer
Audio conversion library for decoding MBE encoded audio frames.
Decodes IMBE 144-bit and AMBE 72-bit encoded 20 millisecond audio frames to 8 kHz 16-bit mono PCM encoded audio.
Version 3 also decodes TETRA speech: TETRA ACELP 30 millisecond frames (ETSI EN 300 395-2) and AMR 4.75 kbps 20 millisecond frames as used on the TETRA speech traffic channel, including the TETRA channel decoding. These decoders are bit exact transcriptions of the ETSI EN 300 395-2 and 3GPP TS 26.073 reference C code and pass the ETSI EN 300 395-4 speech decoder conformance sequences.
PATENT NOTICE
This source code is provided for educational purposes only. It is a written description of how certain voice encoding/decoding algorithms could be implemented. Executable objects compiled or derived from this package may be covered by one or more patents. Readers are strongly advised to check for any patent restrictions or licensing requirements before compiling or using this source code.
Note: this patent notice is verbatim from the mbelib library README at (https://github.com/szechyjs/mbelib)
End Users: Creating the JMBE Library (Version 1.0.7+)
YOU DO NOT HAVE TO INSTALL THE JAVA JDK. The instructions for creating the JMBE library have changed starting with version 1.0.7.
- Download the latest JMBE Creator for your operating system from the Releases page. Each JMBE Creator builds the library version that matches its own release (e.g. JMBE Creator 3.0.0 builds JMBE library 3.0.0).
- Unzip the JMBE Creator
- Open a command/console window and run the JMBE Creator application
- Windows: (unzip directory)/bin/creator.bat
- Linux/OSX: (unzip directory)/bin/creator
- When the program finishes, it will display the location of your JMBE library.
- Move the library to a permanent location
Note: for sdrtrunk use the menu item View > Preferences and then use the JMBE Audio Library section to tell sdrtrunk where your compiled JMBE library is located.
Software Developers - Using the JMBE audio conversion library in your own java program
- Follow the same instructions for downloading the source code above. Use the following command to build the API:
WINDOWS:
gradlew.bat api
LINUX:
./gradlew api
Add the API library jar to your project.
Add the following code to your program
IAudioCodecLibrary audioCodecLibrary = null; try { URLClassLoader childClassLoader = new URLClassLoader(new URL[]{path.toUri().toURL()}, this.getClass().getClassLoader()); Class classToLoad = Class.forName("jmbe.JMBEAudioLibrary", true, childClassLoader); Object instance = classToLoad.getDeclaredConstructor().newInstance(); if(instance instanceof IAudioCodecLibrary) { audioCodecLibrary = (IAudioCodecLibrary)instance; } catch (Exception e) { //error handling }To convert 18-byte IMBE audio frames:
IAudioCodec audioCodec = library.getAudioConverter("IMBE"); float[] convertedAudio = audioCodec.getAudio(byte[] imbeFrameData);To convert 21-byte EDACS ProVoice IMBE 7100 audio frames (one 7x24 bit grid, packed row-major, MSB first):
IAudioCodec audioCodec = library.getAudioConverter("PROVOICE"); float[] convertedAudio = audioCodec.getAudio(byte[] proVoiceFrameData);To convert 9-byte AMBE audio and tone frames:
IAudioCodec audioCodec = library.getAudioConverter("AMBE"); float[] convertedAudio = audioCodec.getAudio(byte[] ambeFrameData);To convert 9-byte AMBE audio frames and tone frames along with tone frame metadata:
IAudioCodec audioCodec = library.getAudioConverter("AMBE"); IAudioWithMetadata convertedAudio = audioCodec.getAudioWithMetadata(byte[] ambeFrameData);To error correct frames in the host application (for example, to use the error counts) and convert them without the library repeating the error correction, load jmbe.JMBEAudioLibraryV3 as an IAudioCodecLibraryV3:
CorrectedIMBEFrame imbeFrame = CorrectedIMBEFrame.correct(byte[] imbeFrameData); int c0Errors = imbeFrame.getErrors()[0]; IAudioCodecV3 imbeCodec = library.getAudioConverterV3("IMBE"); float[] convertedAudio = imbeCodec.getAudio(imbeFrame); CorrectedAMBEFrame ambeFrame = CorrectedAMBEFrame.correct(byte[] ambeFrameData); IAudioCodecV3 ambeCodec = library.getAudioConverterV3("AMBE 3600 x 2450"); IAudioWithMetadata convertedAudio = ambeCodec.getAudioWithMetadata(ambeFrame); CorrectedProVoiceFrame proVoiceFrame = CorrectedProVoiceFrame.correct(byte[] proVoiceFrameData); IAudioCodecV3 proVoiceCodec = library.getAudioConverterV3("PROVOICE"); float[] convertedAudio = proVoiceCodec.getAudio(proVoiceFrame);To convert TETRA speech, load jmbe.JMBEAudioLibraryV3 as an IAudioCodecLibraryV3 and use the ACELP or AMR (4.75 kbps only) codec. A TETRA speech traffic channel (TCH/S) time slot is 432 type-4 bits (the descrambled type-5 bits of blocks 1 and 2) packed MSB first into 54 bytes, and carries two ACELP frames or three AMR frames:
IAudioCodecV3 acelpCodec = library.getAudioConverterV3("ACELP"); float[] convertedAudio = acelpCodec.getAudio(byte[] slotData); //54 bytes -> 480 samples //Channel decode in the host application, for example to use the bad frame indicator or bit error count for(CorrectedACELPFrame frame : CorrectedACELPFrame.correct(byte[] slotData)) { float[] frameAudio = acelpCodec.getAudio(frame); //240 samples per frame } //When block 1 of the slot is stolen for signalling (STCH), decode block 2 only (27 bytes) CorrectedACELPFrame[] frames = CorrectedACELPFrame.correctStolen(byte[] block2Data); IAudioCodecV3 amrCodec = library.getAudioConverterV3("AMR"); for(CorrectedAMRFrame frame : CorrectedAMRFrame.correct(byte[] slotData)) { float[] frameAudio = amrCodec.getAudio(frame); //160 samples per frame }The codecs also accept speech frames that were channel decoded by the host application: an 18-byte (137-bit) ACELP frame or a 12-byte (95-bit, 3GPP TS 26.073 parameter order) AMR frame, either directly with getAudio(byte[]) or with CorrectedACELPFrame.fromSpeechBits() and CorrectedAMRFrame.fromSpeechBits() to pass the bad frame indicator. Call reset() at the end of each call.
The TETRA codec tests include bit exact conformance tests with the ETSI EN 300 395-4 test sequences, which aren't distributed with JMBE. Extract ORIGNL.ZIP and AMR.ZIP from en_30039504v010301p0.zip and set the JMBE_TETRA_VECTORS environment variable to the folder that contains the ORIGNL and AMR folders to run them.
Creating Legacy JMBE Library (Versions prior to 1.0.7)
Preparing to Compile the Library From Source Code
Install the Java 8 (or higher) Java Development Kit (JDK). Note: this is different from the Java Runtime Environment (JRE) that most users have installed on their computers.
- Liberica OpenJDK: (https://bell-sw.com/)
- Oracle: (http://www.oracle.com/technetwork/java/javase/downloads/index.html)
Download the source code branch from GitHub:
- Version 1.0.6 (current): (https://github.com/DSheirer/jmbe/archive/v1.0.6.zip)
- Version 0.3.4 (previous): (https://github.com/DSheirer/jmbe/archive/v0.3.4.zip)
WINDOWS: Compiling the Library from Source Code
Setup the JAVA_HOME and PATH environment variables
Verify that JAVA_HOME points to the Java Development Kit (JDK) version 8 or higher. At a command prompt type:
- > echo %JAVA_HOME%
This should respond with the directory where you have installed the JDK.
Verify that your computer is using the correct version of the Java compiler. At a command prompt type:
- > javac -version
This should respond with the java version.
Unzip the source code file with a tool like 7-Zip or using the Windows File Manager (right-click on file)
Using the command prompt, change to the directory where you downloaded and unzipped the source code (jmbe-master.zip in this example):
- > cd C:\Users\Denny\Downloads\jmbe-1.0.6
Run the build script
- > gradlew.bat build
The build script will compile the source code and create the library. The first time that you run the build script, it may download some additional files needed for installing the gradle build tool and some java libraries needed for compiling the jmbe library code.
The compiled JMBE library will be located in a sub-folder named '\codec\build\libs', for example:
- > C:\Users\Denny\Downloads\jmbe-master\codec\build\libs\jmbe-1.0.6.jar
Follow the instructions for the application that will use the JMBE library.
Note: for sdrtrunk use the menu item View > Preferences and then use the JMBE Audio Library section to tell sdrtrunk where your compiled JMBE library is located.
LINUX: Compiling the Library from Source Code
- Setup the JAVA_HOME and PATH environment variables
(https://askubuntu.com/questions/175514/how-to-set-java-home-for-java)
Verify that JAVA_HOME points to the Java Development Kit (JDK) version 8 or higher. Open a terminal and type:
- > echo $JAVA_HOME$
This should respond with the directory where you have installed the JDK.
Verify that your computer is using the correct version of the Java compiler. At a command prompt type:
- > javac -version
This should respond with the java version.
Unzip the source code file with a tool like 7-Zip or ark using the File Manager (right-click on file)
In the terminal window, change to the directory where you downloaded and unzipped the source code (jmbe-master.zip in this example):
- > denny@denny-desktop:~$ cd Downloads\jmbe-1.0.6
Run the build script
- > ./gradlew build
The build script will compile the source code and create the library. The first time that you run the build script, it may download some additional files needed for installing the gradle build tool and some java libraries needed for compiling the jmbe library code.
The compiled JMBE library will be located at:
- > ~\Downloads\jmbe-master\codec\build\libs\jmbe-1.0.6.jar
Follow the instructions for the application that will use the JMBE library.
