Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/henkelmax/opus4j
A Java wrapper for the Opus Codec.
https://github.com/henkelmax/opus4j
codec java jna opus
Last synced: about 2 months ago
JSON representation
A Java wrapper for the Opus Codec.
- Host: GitHub
- URL: https://github.com/henkelmax/opus4j
- Owner: henkelmax
- Created: 2021-03-15T20:19:26.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-08-16T08:31:56.000Z (5 months ago)
- Last Synced: 2024-08-16T09:48:45.345Z (5 months ago)
- Topics: codec, java, jna, opus
- Language: Rust
- Homepage:
- Size: 5.2 MB
- Stars: 7
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Opus4J
A Java wrapper for the [Opus Codec](https://opus-codec.org/) written in Rust using JNI.
## Usage
**Maven**
``` xml
de.maxhenkel.opus4j
opus4j
2.0.2
henkelmax.public
https://maven.maxhenkel.de/repository/public
```
**Gradle**
``` groovy
dependencies {
implementation 'de.maxhenkel.opus4j:opus4j:2.0.2'
}repositories {
maven {
name = "henkelmax.public"
url = 'https://maven.maxhenkel.de/repository/public'
}
}
```### Example Code
**Encoding**
``` java
short[] rawAudio = ...;// Creates a new encoder instance with 48kHz mono VOIP
OpusEncoder encoder = new OpusEncoder(48000, 1, OpusEncoder.Application.VOIP);// Sets the max payload size to 1500 bytes
encoder.setMaxPayloadSize(1500);// Encodes the raw audio
byte[] encoded = encoder.encode(rawAudio);// Resets the encoder state
encoder.resetState();...
// Closes the encoder - Not calling this will cause a memory leak!
encoder.close();
```**Decoding**
``` java
byte[] encodedAudio = ...;// Creates a new decoder instance with 48kHz mono
OpusDecoder decoder = new OpusDecoder(48000, 1);// Sets the frame size to 960 samples
// If this is not set properly, decoded FEC frames will have the wrong size
decoder.setFrameSize(960);// Decodes the encoded audio
short[] decoded = decoder.decode(encodedAudio);// Decode a missing packet with FEC (Forward Error Correction)
decoded = decoder.decodeFec();// Resets the decoder state
decoder.resetState();...
// Closes the decoder - Not calling this will cause a memory leak!
decoder.close();
```## Credits
- [Opus](https://opus-codec.org/)
- [opus-rs](https://github.com/SpaceManiac/opus-rs)
- [jni-rs](https://github.com/jni-rs/jni-rs)