Skip to content

Commit

Permalink
README: installation instructions and encoder.Encode tip
Browse files Browse the repository at this point in the history
  • Loading branch information
adrenak committed Dec 18, 2024
1 parent 1cfe90b commit 10524f4
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,47 @@
## UnityOpus
## UnityOpus 🔉
Note: A UPM fork of [UnityOps by TyounanMOTI](https://github.com/TyounanMOTI/UnityOpus) with some XML comments. The original project is sponsored by Cluster, Inc.

[Scripting reference](http://www.vatsalambastha.com/UnityOpus)

## Installation 📦
Ensure you have the NPM registry in the `packages.json` file of your Unity project with `com.adrenak.unityops` as one of the scopes
```
"scopedRegistries": [
{
"name": "npmjs",
"url": "https://registry.npmjs.org",
"scopes": [
"com.npmjs",
"com.adrenak.unityopus"
]
}
}
```

Add `"com.adrenak.unityopus" : "x.y.z"` to `dependencies` list in `packages.json` file where `x.y.z` is the version name

## Tip
The [Encoder.Encode](https://www.vatsalambastha.com/UnityOpus/api/Adrenak.UnityOpus.Encoder.html#Adrenak_UnityOpus_Encoder_Encode_System_Single___System_Byte___0) returns an int.
If it's > 0, encoding succeeded and this int represents the length of the encoded audio in the output array. You'll need to copy the encoded audio from the output.
If it's < 0, encoding has failed and the int actually represents the error code

```
// Assuming pcm is the float[] you want to encode
// The output array should be equal to the pcm array size in bytes, hence multuplied by 4
byte[] output = new byte[pcm.Length * 4];
int encodeResult = encoder.Encode(pcm, output);
if(encodedResult > 0) {
byte[] encodedBytes = new byte[encodeResult];
Array.Copy(encodeBuffer, encodedBytes, encodedBytes.Length);
// encodedBytes now has the encoded audio ready for your use
}
else {
// Get the error
ErrorCode errorCode = (ErrorCode)encodeResult;
}
```

## Contact 👥
[@github](https://www.github.com/adrenak)
[@website](http://www.vatsalambastha.com)
Expand Down

0 comments on commit 10524f4

Please sign in to comment.