{"id":19892978,"url":"https://github.com/labymod/opus-jni","last_synced_at":"2025-05-02T19:30:31.530Z","repository":{"id":41359332,"uuid":"245823514","full_name":"LabyMod/opus-jni","owner":"LabyMod","description":"Simple Java Opus library","archived":false,"fork":false,"pushed_at":"2022-07-30T21:42:24.000Z","size":624,"stargazers_count":27,"open_issues_count":3,"forks_count":8,"subscribers_count":4,"default_branch":"master","last_synced_at":"2023-02-28T17:22:15.873Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LabyMod.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-08T13:52:22.000Z","updated_at":"2023-02-25T03:03:54.000Z","dependencies_parsed_at":"2022-09-11T20:41:33.030Z","dependency_job_id":null,"html_url":"https://github.com/LabyMod/opus-jni","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LabyMod%2Fopus-jni","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LabyMod%2Fopus-jni/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LabyMod%2Fopus-jni/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LabyMod%2Fopus-jni/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LabyMod","download_url":"https://codeload.github.com/LabyMod/opus-jni/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224326959,"owners_count":17292972,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T18:26:30.918Z","updated_at":"2024-11-12T18:26:31.363Z","avatar_url":"https://github.com/LabyMod.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# opus-jni\n\nopus-jni is a very simple and comfortable to use JNI wrapper for the \n[Opus codec](https://opus-codec.org/), created for [LabyMod](https://github.com/LabyMod).\nIt might lack a few functions of the original Opus codec specifications but should be perfectly\nfine for most usecases.\n\n[![CI](https://github.com/LabyMod/opus-jni/workflows/CI/badge.svg)](https://github.com/LabyMod/opus-jni/actions?query=workflow%3ACI)\n\nSee [here](./opus-jni-java/src/test/java/net/labymod/opus/MinimalEchoExample.java) for a very\nsimple and complete echo example.\n## How to use:\n### Cloning\nThis repository uses submodules, so you need to clone with `--recurse-submodules` or after\ncloning run `git submodule update --init`\n\n### Building\nBuilding is slightly more complex than a normal Java project and only required if you want\nto change the way the library works.\n\n#### Building for your platform (development)\nInstall [CMake](https://cmake.org/download/) and make sure it is on the path. You will also need\na compiler (not a Java compiler, but a C one). For windows you should install Visual Studio. \nFor Linux and OSX choose your favorite method of installing the compiler (gcc and clang should \nboth work).\n\nAfter this is done, the project might be used like every other gradle project. Note that the\nresulting jar will be in `opus-jni-java/build/libs` and **will just work on the platform it\nwas built on!**. For instructions on how to build for all target platforms, see below.\n\n#### Building for all platforms (production)\nYou will need a machine for every platform you want to build on. This means, if you want to\nproduce a jar which works on Linux, Windows and OSX, you will need an installation of each of\nthe operating systems (it might be possible to just use Linux and cross compile, but that is\nnot officially supported by us).\n\nAll 3 machines will need CMake and a compiler installed (refer to\n[Building for your platform](#building-for-your-platform-development)). Then you need to run\nthe gradle task `opus-jni-native:build` on each machine, which will result in the following\nbinaries in `build/nativeBinaries`:\n- `libopus-jni-native.dylib` (OSX)\n- `libopus-jni-native.so` (Linux)\n- `opus-jni-native.dll` (Windows)\n\nCopy all of those binaries to one machine to one directory. On that machine invoke\n`gradlew -PnativeBinaryExternalDir=/path/to/your/directory opus-jni-java:build`, where\n`/path/to/your/directory` is the directory containing all 3 of the binaries above.\nThe final jar in `opus-jni-java/build/libs` will support all platforms you have built the \nbinaries for. You may leave the ones out you don't need to support.\n\nFor further details, refer to the [Github workflow](./.github/workflows/ci.yml).\n\n### Important to know:\n- Every audio stream requires its own codec instance, because Opus is not stateless.\n- Only the following sample rates are supported: 8khz, 12khz, 16khz, 24khz, 48khz\n- Recommended bitrates for your purpose found \n  [here](https://wiki.xiph.org/index.php?title=Opus_Recommended_Settings\u0026mobileaction=toggle_view_desktop)\n- The default codec settings should be fine for every simple VoIP communication\n- Unused instances of OpusCodec must be removed to prevent memory leaks with ```OpusCodec#destroy```. This might not be critical when using only a fixed amount of instances, but can get dangerous when those instances have a life cycle and might be recreated once in a while.\n\n#### Create a codec instance:\n###### Default settings\n```java\nOpusCodec codec = OpusCodec.createDefault();\n```\n\n###### Custom settings\n```java\nOpusCodec codec = OpusCodec.newBuilder()\n  .withSampleRate(24000)\n  .withChannels(2)\n  .withBitrate(128000)\n  ...\n  .build();\n```\n\n###### encode/decode\nEncoding/Decoding an audio chunk is very straight forward.\n```java\nbyte[] data = new byte[codec.getFrameSize() * codec.getChannels() * 2];\n... //Fill data\nbyte[] encoded = codec.encodeFrame(data);\nbyte[] decode = codec.decodeFrame(encoded);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flabymod%2Fopus-jni","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flabymod%2Fopus-jni","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flabymod%2Fopus-jni/lists"}