forked from TyounanMOTI/UnityOpus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
65 changed files
with
682 additions
and
1,687 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: CI | ||
on: | ||
push: | ||
branches: | ||
- master | ||
jobs: | ||
release: | ||
name: Release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Check if README.md has changed | ||
id: readme_check | ||
run: | | ||
if git diff --name-only HEAD~1 HEAD | grep -q "README.md"; then | ||
echo "README_CHANGED=true" >> $GITHUB_ENV | ||
else | ||
echo "README_CHANGED=false" >> $GITHUB_ENV | ||
fi | ||
- name: Update package README | ||
if: env.README_CHANGED == 'true' | ||
run: | | ||
git branch -d upm &> /dev/null || echo upm branch not found | ||
cp README.md "$PKG_ROOT/README.md" | ||
git config --global user.name 'github-bot' | ||
git config --global user.email '[email protected]' | ||
git commit -am "Updated package README from root README" | ||
git push -f -u origin master | ||
- name: Create UPM branch | ||
run: | | ||
git subtree split -P "$PKG_ROOT" -b upm | ||
git checkout upm | ||
if [[ -d "Samples" ]]; then | ||
git mv Samples Samples~ | ||
rm -f Samples.meta | ||
git config --global user.name 'github-bot' | ||
git config --global user.email '[email protected]' | ||
git commit -am "fix: Samples => Samples~" | ||
fi | ||
git push -f -u origin upm | ||
env: | ||
PKG_ROOT: "Assets/Adrenak.UnityOpus" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"version": "1.0", | ||
"components": [ | ||
"Microsoft.VisualStudio.Workload.ManagedGame" | ||
] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Vatsal Ambastha | ||
Copyright (c) 2018 TyounanMOTI | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
2 changes: 1 addition & 1 deletion
2
...ck/Scenes/EncodeDecodeLoopback.unity.meta → Assets/Adrenak.UnityOpus/LICENSE.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## UnityOpus | ||
Note: This is simply a UPM fork of [UnityOps by TyounanMOTI](https://github.com/TyounanMOTI/UnityOpus) with some XML comments | ||
|
||
## Contact 👥 | ||
[@github](https://www.github.com/adrenak) | ||
[@website](http://www.vatsalambastha.com) | ||
@discord: `adrenak#1934` |
4 changes: 2 additions & 2 deletions
4
.../OnAudioFilterReadLatencyCheck.unity.meta → Assets/Adrenak.UnityOpus/README.md.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
3 changes: 3 additions & 0 deletions
3
Assets/Adrenak.UnityOpus/Runtime/Adrenak.UnityOpus.Runtime.asmdef
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "Adrenak.UnityOpus.Runtime" | ||
} |
5 changes: 2 additions & 3 deletions
5
Assets/Plugins/UnityOpus.meta → ...ime/Adrenak.UnityOpus.Runtime.asmdef.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using UnityEngine; | ||
using System; | ||
|
||
namespace Adrenak.UnityOpus { | ||
/// <summary> | ||
/// Represents an Opus decoder for decoding Opus-encoded data to PCM. | ||
/// </summary> | ||
public class Decoder : IDisposable { | ||
/// <summary> | ||
/// The maximum packet duration supported by the Opus decoder. | ||
/// </summary> | ||
public const int maximumPacketDuration = OpusLib.maximumPacketDuration; | ||
|
||
private IntPtr decoder; | ||
private readonly NumChannels channels; | ||
private readonly float[] softclipMem; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="Decoder"/> class. | ||
/// </summary> | ||
/// <param name="samplingFrequency">The sampling frequency of the input data.</param> | ||
/// <param name="channels">The number of audio channels.</param> | ||
public Decoder(SamplingFrequency samplingFrequency, NumChannels channels) { | ||
ErrorCode error; | ||
this.channels = channels; | ||
decoder = OpusLib.OpusDecoderCreate(samplingFrequency, channels, out error); | ||
if (error != ErrorCode.OK) { | ||
Debug.LogError("[UnityOpus] Failed to create Decoder. Error code is " + error.ToString()); | ||
decoder = IntPtr.Zero; | ||
} | ||
softclipMem = new float[(int)channels]; | ||
} | ||
|
||
/// <summary> | ||
/// Decodes the provided Opus data into PCM float format. | ||
/// </summary> | ||
/// <param name="data">The Opus-encoded byte data.</param> | ||
/// <param name="dataLength">The length of the input data.</param> | ||
/// <param name="pcm">Output float array for PCM data.</param> | ||
/// <param name="decodeFec">Flag to enable forward error correction (FEC).</param> | ||
/// <returns>The length of the decoded PCM data.</returns> | ||
public int Decode(byte[] data, int dataLength, float[] pcm, int decodeFec = 0) { | ||
if (decoder == IntPtr.Zero) { | ||
return 0; | ||
} | ||
var decodedLength = OpusLib.OpusDecodeFloat( | ||
decoder, | ||
data, | ||
dataLength, | ||
pcm, | ||
pcm.Length / (int)channels, | ||
decodeFec); | ||
OpusLib.OpusPcmSoftClip( | ||
pcm, | ||
decodedLength / (int)channels, | ||
channels, | ||
softclipMem); | ||
return decodedLength; | ||
} | ||
|
||
#region IDisposable Support | ||
private bool disposed = false; // To detect duplicate calls | ||
|
||
/// <summary> | ||
/// Releases the unmanaged resources used by the decoder. | ||
/// </summary> | ||
/// <param name="disposing">True if disposing managed resources.</param> | ||
protected virtual void Dispose(bool disposing) { | ||
if (!disposed) { | ||
if (decoder == IntPtr.Zero) { | ||
return; | ||
} | ||
OpusLib.OpusDecoderDestroy(decoder); | ||
decoder = IntPtr.Zero; | ||
|
||
disposed = true; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Finalizer for <see cref="Decoder"/>. | ||
/// </summary> | ||
~Decoder() { | ||
Dispose(false); | ||
} | ||
|
||
/// <summary> | ||
/// Disposes of the decoder and suppresses finalization. | ||
/// </summary> | ||
public void Dispose() { | ||
Dispose(true); | ||
GC.SuppressFinalize(this); | ||
} | ||
#endregion | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
using System; | ||
|
||
namespace Adrenak.UnityOpus { | ||
/// <summary> | ||
/// Represents an Opus encoder for encoding PCM data. | ||
/// </summary> | ||
public class Encoder : IDisposable { | ||
private int bitrate; | ||
/// <summary> | ||
/// Gets or sets the bitrate of the encoder. | ||
/// NOTE: get only returns the value that's been | ||
/// set by you before. | ||
/// </summary> | ||
public int Bitrate { | ||
get { return bitrate; } | ||
set { | ||
OpusLib.OpusEncoderSetBitrate(encoder, value); | ||
bitrate = value; | ||
} | ||
} | ||
|
||
private int complexity; | ||
/// <summary> | ||
/// Gets or sets the complexity level of the encoder. | ||
/// NOTE: get only returns the value that's been | ||
/// set by you before. | ||
/// </summary> | ||
public int Complexity { | ||
get { | ||
return complexity; | ||
} | ||
set { | ||
OpusLib.OpusEncoderSetComplexity(encoder, value); | ||
complexity = value; | ||
} | ||
} | ||
|
||
private OpusSignal signal; | ||
/// <summary> | ||
/// Gets or sets the signal type (e.g., voice, music) for the encoder. | ||
/// NOTE: get only returns the value that's been | ||
/// set by you before. | ||
/// </summary> | ||
public OpusSignal Signal { | ||
get { return signal; } | ||
set { | ||
OpusLib.OpusEncoderSetSignal(encoder, value); | ||
signal = value; | ||
} | ||
} | ||
|
||
private IntPtr encoder; | ||
private NumChannels channels; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="Encoder"/> class. | ||
/// </summary> | ||
/// <param name="samplingFrequency">The sampling frequency of the input data.</param> | ||
/// <param name="channels">The number of audio channels.</param> | ||
/// <param name="application">The Opus application type (e.g., VoIP, Audio).</param> | ||
public Encoder(SamplingFrequency samplingFrequency, NumChannels channels, OpusApplication application) { | ||
this.channels = channels; | ||
ErrorCode error; | ||
encoder = OpusLib.OpusEncoderCreate( | ||
samplingFrequency, | ||
channels, | ||
application, | ||
out error); | ||
if (error != ErrorCode.OK) { | ||
UnityEngine.Debug.LogError("[UnityOpus] Failed to init encoder. Error code: " + error.ToString()); | ||
encoder = IntPtr.Zero; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Encodes the provided PCM float data to Opus format. | ||
/// </summary> | ||
/// <param name="pcm">Input PCM float array.</param> | ||
/// <param name="output">Output byte array for encoded data.</param> | ||
/// <returns>The size of the encoded data in bytes.</returns> | ||
public int Encode(float[] pcm, byte[] output) { | ||
if (encoder == IntPtr.Zero) { | ||
return 0; | ||
} | ||
return OpusLib.OpusEncodeFloat( | ||
encoder, | ||
pcm, | ||
pcm.Length / (int)channels, | ||
output, | ||
output.Length | ||
); | ||
} | ||
|
||
#region IDisposable Support | ||
private bool disposed = false; // To detect duplicate calls | ||
|
||
/// <summary> | ||
/// Releases the unmanaged resources used by the encoder. | ||
/// </summary> | ||
/// <param name="disposing">True if disposing managed resources.</param> | ||
protected virtual void Dispose(bool disposing) { | ||
if (!disposed) { | ||
if (encoder == IntPtr.Zero) { | ||
return; | ||
} | ||
OpusLib.OpusEncoderDestroy(encoder); | ||
encoder = IntPtr.Zero; | ||
|
||
disposed = true; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Finalizer for <see cref="Encoder"/>. | ||
/// </summary> | ||
~Encoder() { | ||
Dispose(false); | ||
} | ||
|
||
/// <summary> | ||
/// Disposes of the encoder and suppresses finalization. | ||
/// </summary> | ||
public void Dispose() { | ||
Dispose(true); | ||
GC.SuppressFinalize(this); | ||
} | ||
#endregion | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.