diff --git a/.gitmodules b/.gitmodules index 451fac4f6..e554c886a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,9 @@ -[submodule "binding/unity/Assets/Rhino/VoiceProcessor"] - path = binding/unity/Assets/Rhino/VoiceProcessor +[submodule "binding/unity/VoiceProcessor"] + path = binding/unity/VoiceProcessor url = ../unity-voice-processor.git [submodule "demo/c/dr_libs"] path = demo/c/dr_libs url = ../../mackron/dr_libs.git [submodule "demo/c/pvrecorder"] path = demo/c/pvrecorder - url = ../pvrecorder.git \ No newline at end of file + url = ../pvrecorder.git diff --git a/binding/unity/Assets/Rhino/RhinoManager.cs b/binding/unity/Assets/Rhino/RhinoManager.cs index b5e313a47..ace62f7b0 100644 --- a/binding/unity/Assets/Rhino/RhinoManager.cs +++ b/binding/unity/Assets/Rhino/RhinoManager.cs @@ -19,7 +19,6 @@ namespace Pv.Unity public class RhinoManager { - private VoiceProcessor _voiceProcessor; private Rhino _rhino; private Action _inferenceCallback; private Action _processErrorCallback; @@ -69,26 +68,29 @@ private RhinoManager(Rhino rhino, Action inferenceCallback, Action /// Action to catch audio frames as voice processor produces them /// - /// Frame of pcm audio - private void OnFrameCaptured(short[] pcm) + /// Frame of audio + private void OnFrameCaptured(short[] frame) { try { - bool _isFinalized = _rhino.Process(pcm); + bool _isFinalized = _rhino.Process(frame); if (_isFinalized) { Inference inference = _rhino.GetInference(); if (_inferenceCallback != null) _inferenceCallback.Invoke(inference); - _voiceProcessor.StopRecording(); + VoiceProcessor.Instance.RemoveFrameListener(OnFrameCaptured); + if (VoiceProcessor.Instance.NumFrameListeners == 0) + { + VoiceProcessor.Instance.StopRecording(); + } } } catch (RhinoException ex) @@ -104,7 +106,7 @@ private void OnFrameCaptured(short[] pcm) /// Checks to see whether RhinoManager is capturing audio or not /// /// whether RhinoManager is capturing audio or not - public bool IsRecording => _voiceProcessor.IsRecording; + public bool IsRecording => VoiceProcessor.Instance.IsRecording; /// /// Checks to see whether there are any audio capture devices available @@ -112,8 +114,8 @@ private void OnFrameCaptured(short[] pcm) /// whether there are any audio capture devices available public bool IsAudioDeviceAvailable() { - _voiceProcessor.UpdateDevices(); - return _voiceProcessor.CurrentDeviceIndex >= 0; + VoiceProcessor.Instance.UpdateDevices(); + return VoiceProcessor.Instance.CurrentDeviceIndex >= 0; } /// @@ -121,11 +123,11 @@ public bool IsAudioDeviceAvailable() /// public void Process() { - if (_rhino == null || _voiceProcessor == null) + if (_rhino == null) { throw new RhinoInvalidStateException("Cannot start RhinoManager - resources have already been released"); } - _voiceProcessor.StartRecording(_rhino.SampleRate, _rhino.FrameLength); + VoiceProcessor.Instance.StartRecording(_rhino.FrameLength, _rhino.SampleRate); } /// @@ -133,19 +135,14 @@ public void Process() /// public void Delete() { - if (_voiceProcessor != null) + if (_rhino != null) { - if (_voiceProcessor.IsRecording) + VoiceProcessor.Instance.RemoveFrameListener(OnFrameCaptured); + if (VoiceProcessor.Instance.NumFrameListeners == 0) { - _voiceProcessor.StopRecording(); + VoiceProcessor.Instance.StopRecording(); } - _voiceProcessor.OnFrameCaptured -= OnFrameCaptured; - _voiceProcessor = null; - } - - if (_rhino != null) - { _rhino.Dispose(); _rhino = null; } diff --git a/binding/unity/Assets/Rhino/VoiceProcessor b/binding/unity/Assets/Rhino/VoiceProcessor deleted file mode 160000 index c7ece44be..000000000 --- a/binding/unity/Assets/Rhino/VoiceProcessor +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c7ece44be8f1a6c6466863c5241e750be0e334f2 diff --git a/binding/unity/Assets/Rhino/VoiceProcessor.meta b/binding/unity/Assets/Rhino/VoiceProcessor.meta index 0310e4431..f1b6221f2 100644 --- a/binding/unity/Assets/Rhino/VoiceProcessor.meta +++ b/binding/unity/Assets/Rhino/VoiceProcessor.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 48ca1db7d1fcc1c41a3cd516ff802443 +guid: b9d0c217c5fff9d89a02b8345b3fdba5 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/binding/unity/Assets/StreamingAssets/test.meta b/binding/unity/Assets/StreamingAssets/test.meta deleted file mode 100644 index 37eafb432..000000000 --- a/binding/unity/Assets/StreamingAssets/test.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 47e544f7c76df0f0bacf3b82f16c6846 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/binding/unity/README.md b/binding/unity/README.md index 295f95b0b..f0bc8ae5b 100644 --- a/binding/unity/README.md +++ b/binding/unity/README.md @@ -23,7 +23,7 @@ Rhino is: ## Compatibility -[Rhino unity package](./rhino-2.2.1.unitypackage) is for running Rhino on **Unity 2017.4+** on the following platforms: +[Rhino unity package](./rhino-2.2.2.unitypackage) is for running Rhino on **Unity 2017.4+** on the following platforms: - Android 4.4+ (API 19+) (ARM only) - iOS 9.0+ @@ -31,11 +31,11 @@ Rhino is: - macOS (x86_64) - Linux (x86_64) -For running Rhino on **macOS m1 (arm64)**, use the [Apple silicon](./rhino-2.2.1-Apple-silicon.unitypackage) version on **Unity 2021.2+**. +For running Rhino on **macOS m1 (arm64)**, use the [Apple silicon](./rhino-2.2.2-Apple-silicon.unitypackage) version on **Unity 2021.2+**. ## Installation -The easiest way to install the Rhino Unity SDK is to import the [Rhino Unity Package](./rhino-2.2.1.unitypackage) into your Unity project by either dropping it into the Unity editor or going to _Assets>Import Package>Custom Package..._ +The easiest way to install the Rhino Unity SDK is to import the [Rhino Unity Package](./rhino-2.2.2.unitypackage) into your Unity project by either dropping it into the Unity editor or going to _Assets>Import Package>Custom Package..._ **NOTE:** On macOS, the Rhino library may get flagged as having come from an unverified source if you've downloaded the `.unitypackage` directly from github. This should only come up when running your project in the Editor. To disable this warning, go to Security & Preferences and choose to allow pv_rhino.dylib to run. diff --git a/binding/unity/VoiceProcessor b/binding/unity/VoiceProcessor new file mode 160000 index 000000000..c7e647434 --- /dev/null +++ b/binding/unity/VoiceProcessor @@ -0,0 +1 @@ +Subproject commit c7e647434905f330e8d73c92ae3a25d169374567 diff --git a/binding/unity/copy.sh b/binding/unity/copy.sh index 41cb4b691..af4805727 100755 --- a/binding/unity/copy.sh +++ b/binding/unity/copy.sh @@ -20,6 +20,13 @@ cp ../../lib/windows/amd64/libpv_rhino.dll ./Assets/Rhino/Plugins/windows/amd64/ echo "Copying Rhino common lib..." cp ../../lib/common/rhino_params.pv ./Assets/StreamingAssets/rhino_params.pv +echo "Copying Voice Processor files..." +if [ ! -d "./Assets/Rhino/VoiceProcessor" ] +then + mkdir -p ./Assets/Rhino/VoiceProcessor +fi +cp -rp VoiceProcessor/Assets/UnityVoiceProcessor/*.cs ./Assets/Rhino/VoiceProcessor + echo "Copying demo files..." if [ ! -d "./Assets/Rhino/Demo" ] then diff --git a/binding/unity/rhino-2.2.1-Apple-silicon.unitypackage b/binding/unity/rhino-2.2.1-Apple-silicon.unitypackage deleted file mode 100644 index 9a3e45e6b..000000000 Binary files a/binding/unity/rhino-2.2.1-Apple-silicon.unitypackage and /dev/null differ diff --git a/binding/unity/rhino-2.2.1.unitypackage b/binding/unity/rhino-2.2.1.unitypackage deleted file mode 100644 index 7b3982054..000000000 Binary files a/binding/unity/rhino-2.2.1.unitypackage and /dev/null differ diff --git a/binding/unity/rhino-2.2.2-Apple-silicon.unitypackage b/binding/unity/rhino-2.2.2-Apple-silicon.unitypackage new file mode 100644 index 000000000..3b6863ec7 Binary files /dev/null and b/binding/unity/rhino-2.2.2-Apple-silicon.unitypackage differ diff --git a/binding/unity/rhino-2.2.2.unitypackage b/binding/unity/rhino-2.2.2.unitypackage new file mode 100644 index 000000000..c82b515a9 Binary files /dev/null and b/binding/unity/rhino-2.2.2.unitypackage differ