Concentus Opus Implementations

repository·master·Indexed 43 days ago

https://github.com/lostromb/concentus

Portable, native implementations of the Opus audio codec for C#, Java, and Go, based on libopus master 1.1.2. Designed to provide high-fidelity audio encoding and decoding without requiring native C libraries, P/Invoke, or JNI. Includes a port of the libspeexdsp resampler and a JavaScript port of opusenc.js.

Tokens
5.9K
Snippets
18
Records
29
Agent score
56%

What's inside Concentus

  1. Overview of Concentus Opus implementations

    master

    Concentus provides portable, native implementations of the Opus codec for C#, Java, and Go. These implementations are based on libopus master 1.1.2 (configured with FIXED_POINT) and are designed to be bit-exact with the original C functions in common use cases. The project also includes a port of the libspeexdsp resampler for general use.

    Use Concentus when you need a pure-language implementation that avoids the complexities of native library linking (like P/Invoke or JNI), provided that the performance characteristics meet your requirements.

  2. License terms for opusenc.js

    master

    The opusenc.js project is primarily licensed under the three-clause BSD license.

    Additionally, code written by the maintainer (Rillke) is available under the MIT license, CC-By-SA 3.0, or the three-clause BSD license at your option.

    When contributing to this repository, you agree to license your code under the license of the file you are modifying, plus the MIT license, CC-By-SA 3.0, and the three-clause BSD license.

  3. Performance characteristics of Concentus Go

    master
    The Go implementation is a direct translation of the original Java code. It produces identical output to the Java version but is approximately 40% faster in execution time for the same input samples. It is recommended for cross-platform development.
  4. Understand Concentus performance characteristics

    master

    Concentus is designed for portability rather than maximum speed. Because it runs in managed environments, it typically performs at approximately 40-50% of the speed of the original C libopus implementation due to managed array overhead and the lack of direct vector instruction porting.

    When to use Concentus:

    • When you need a pure-language implementation (C#, Java, or Go).
    • When bit-exactness with the Opus reference is required.
    • When you want to avoid native dependencies.

    When to avoid Concentus:

    • If you require 'blazing-fast' performance, consider using a P/Invoke (P/Opus) or JNI-based library instead.
  5. Patent licenses for the Opus codec

    master

    The Opus codec is subject to royalty-free patent licenses provided by several entities. Developers should be aware of the following patent disclosures and license grants:

    Xiph.Org Foundation

    Grants a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable license under Licensed Patents to implement the Specification.

    Broadcom Corporation

    Grants a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable license under Licensed Patents to implement the Specification.

    Microsoft Corporation

    Grants a non-sublicensable, perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable license to:

    • Necessary Decoder Claims for your Specification Implementation.
    • Necessary Reference Implementation Claims to make, use, sell, offer for sale, import or distribute a Code Implementation.
  6. Performance characteristics of the Concentus Go implementation

    master
    The Go version of Concentus is a direct translation of the Java version. It produces bit-identical output for the same input samples but offers approximately 40% faster execution time. Additionally, Go is highly suitable for cross-platform development.
  7. Understand the underlying software licenses in opusenc.js

    master

    The opusenc.js repository is an Emscripten build of a modified version of opus-tools/opusenc. It incorporates several third-party components, each with its own licensing terms:

    • Opus Codec: 3-clause BSD license (subject to royalty-free patent licenses from Xiph.Org, Microsoft, and Broadcom).
    • libOgg: 3-clause BSD license.
    • FLAC: 3-clause BSD license.
    • opus-tools/opusenc (and encoder implementations): 2-clause BSD-style license.
    • Emscripten: MIT license and the University of Illinois/NCSA Open Source License.
    • LLVM: Credits provided in the source.
  8. Use opusenc.js via Web Workers

    master

    The library provides a pre-compiled script and auxiliary scripts in the /worker directory to make encoding via Web Workers easier. To encode a file, you must instantiate a Worker using worker/EmsWorkerProxy.js and send a message using postMessage with the encode command.

    Message Structure

    When calling worker.postMessage, provide an object with the following keys:

    • command: Set to 'encode' to start the process, or 'prefetch' to download the 850 KiB worker script in advance.
    • args: An Array of command-line arguments (as DOMString) for the encoder.
    • outData: An object literal defining the output files to be read from the worker's file system after encoding. Each entry should map the desired filename to its MIME type (e.g., {'encoded.opus': {'MIME': 'audio/ogg'}}).
    • fileData: An object literal mapping input filenames to their content as Uint8Arrays.
    var worker = new Worker( 'worker/EmsWorkerProxy.js' );
    
    // Files to be read and posted back after encoding completed
    var outData = {
    	'encoded.opus': {
    		'MIME': 'audio/ogg'
    	}
    };
    
    worker.onmessage = function( e ) {
    	// Handle incoming data
    };
    
    // Post all data and the encode command to the web worker
    worker.postMessage( {
    	command: 'encode',
    	args: args,
    	outData: outData,
    	fileData: storedFiles
    } );
  9. Build opusenc.js from source

    master

    To build opusenc.js yourself, you need a recent Linux build system and Emscripten 1.25.0 installed and activated. Use the provided make.sh script after cloning the repository and initializing submodules.

    git clone git://github.com/Rillke/opusenc.js.git opusenc.js
    cd opusenc.js
    git submodule update --init
    ./make.sh
  10. Prefetch the opusenc.js worker script

    master

    The worker script is approximately 850 KiB. To improve user experience and avoid latency during the encoding process, you can optionally send a 'prefetch' command to the worker before the user initiates an actual encoding task. This downloads the script in advance.

    var worker = new Worker( 'worker/EmsWorkerProxy.js' );
    worker.postMessage( {
    	command: 'prefetch'
    } );
  11. Compile libopus from source

    master

    You can build the library from a distribution tarball or directly from the git repository.

    From a distribution tarball

    ./configure
    make

    From the git repository

    1. Clone the repository:
    git clone https://git.xiph.org/opus.git
    cd opus
    1. Compile the source:
    ./autogen.sh
    ./configure
    make
    1. Install the codec libraries (optional):
    sudo make install
    # Build from git repository
    git clone https://git.xiph.org/opus.git
    cd opus
    ./autogen.sh
    ./configure
    make