forked from cgvr/DeltaVR
remove audio loopback functionality
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -4,9 +4,9 @@ using System.Runtime.InteropServices;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using FMOD;
|
using FMOD;
|
||||||
using FMODUnity;
|
using FMODUnity;
|
||||||
using Whisper; // WhisperManager, WhisperStream, WhisperResult
|
using Whisper;
|
||||||
using Whisper.Utils;
|
using Whisper.Utils;
|
||||||
using Debug = UnityEngine.Debug; // AudioChunk
|
using Debug = UnityEngine.Debug;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// FMOD mic is initialized once (Start) and runs continuously in a ring buffer.
|
/// FMOD mic is initialized once (Start) and runs continuously in a ring buffer.
|
||||||
@@ -28,12 +28,6 @@ public class FMODWhisperBridge : MonoBehaviour
|
|||||||
public int channels = 1;
|
public int channels = 1;
|
||||||
[Range(1, 10)] public int bufferLengthSec = 5;
|
[Range(1, 10)] public int bufferLengthSec = 5;
|
||||||
|
|
||||||
[Header("Loopback (monitor your voice)")]
|
|
||||||
public bool playLoopback = true;
|
|
||||||
[Tooltip("If true, loopback plays only while active; otherwise it’s always on.")]
|
|
||||||
public bool loopbackOnlyWhenActive = true;
|
|
||||||
[Range(0f, 2f)] public float loopbackVolume = 1.0f;
|
|
||||||
|
|
||||||
public delegate void OnWhisperSegmentUpdatedDelegate(string result);
|
public delegate void OnWhisperSegmentUpdatedDelegate(string result);
|
||||||
public event OnWhisperSegmentUpdatedDelegate OnWhisperSegmentUpdated;
|
public event OnWhisperSegmentUpdatedDelegate OnWhisperSegmentUpdated;
|
||||||
|
|
||||||
@@ -44,7 +38,6 @@ public class FMODWhisperBridge : MonoBehaviour
|
|||||||
private FMOD.System _core;
|
private FMOD.System _core;
|
||||||
private Sound _recSound;
|
private Sound _recSound;
|
||||||
private Channel _playChannel;
|
private Channel _playChannel;
|
||||||
private ChannelGroup _masterGroup;
|
|
||||||
private uint _soundPcmLength; // in samples
|
private uint _soundPcmLength; // in samples
|
||||||
private int _nativeRate;
|
private int _nativeRate;
|
||||||
private int _nativeChannels;
|
private int _nativeChannels;
|
||||||
@@ -138,24 +131,6 @@ public class FMODWhisperBridge : MonoBehaviour
|
|||||||
_core.getRecordPosition(recordDriverId, out _lastRecordPos);
|
_core.getRecordPosition(recordDriverId, out _lastRecordPos);
|
||||||
Debug.Log("[FMOD→Whisper] Recording started.");
|
Debug.Log("[FMOD→Whisper] Recording started.");
|
||||||
|
|
||||||
// Loopback channel (optional). Start once; pause when inactive if desired.
|
|
||||||
_core.getMasterChannelGroup(out _masterGroup);
|
|
||||||
if (playLoopback)
|
|
||||||
{
|
|
||||||
res = _core.playSound(_recSound, _masterGroup, false, out _playChannel);
|
|
||||||
if (res == RESULT.OK && _playChannel.hasHandle())
|
|
||||||
{
|
|
||||||
_playChannel.setMode(MODE._2D);
|
|
||||||
_playChannel.setVolume(loopbackVolume);
|
|
||||||
if (loopbackOnlyWhenActive) _playChannel.setPaused(true); // keep muted until Activate
|
|
||||||
Debug.Log("[FMOD→Whisper] Loopback playback ready.");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Debug.LogWarning($"[FMOD→Whisper] playSound failed or channel invalid: {res}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// No Whisper stream here. It will be created on ActivateRecording().
|
// No Whisper stream here. It will be created on ActivateRecording().
|
||||||
await System.Threading.Tasks.Task.Yield();
|
await System.Threading.Tasks.Task.Yield();
|
||||||
}
|
}
|
||||||
@@ -217,11 +192,6 @@ public class FMODWhisperBridge : MonoBehaviour
|
|||||||
_streamStarted = true;
|
_streamStarted = true;
|
||||||
|
|
||||||
|
|
||||||
// --- NEW: Clear the ring buffer and reset read pointer ---
|
|
||||||
// Pause loopback while we clear (optional, but avoids clicks)
|
|
||||||
if (playLoopback && _playChannel.hasHandle())
|
|
||||||
_playChannel.setPaused(true);
|
|
||||||
|
|
||||||
// Clear buffer bytes
|
// Clear buffer bytes
|
||||||
ClearRecordRingBuffer();
|
ClearRecordRingBuffer();
|
||||||
|
|
||||||
@@ -231,13 +201,8 @@ public class FMODWhisperBridge : MonoBehaviour
|
|||||||
// We’ll skip feeding for one frame to guarantee a clean start
|
// We’ll skip feeding for one frame to guarantee a clean start
|
||||||
_skipOneFeedFrame = true;
|
_skipOneFeedFrame = true;
|
||||||
|
|
||||||
// Unpause loopback if we want it active during recording
|
|
||||||
if (playLoopback && _playChannel.hasHandle() && (!loopbackOnlyWhenActive || isRecordingActivated))
|
|
||||||
_playChannel.setPaused(loopbackOnlyWhenActive ? false : _playChannel.getPaused(out var paused) == FMOD.RESULT.OK && paused ? false : false);
|
|
||||||
|
|
||||||
isRecordingActivated = true;
|
isRecordingActivated = true;
|
||||||
Debug.Log("[FMOD→Whisper] Stream activated (buffer cleared; reading from current head).");
|
Debug.Log("[FMOD→Whisper] Stream activated (buffer cleared; reading from current head).");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -249,10 +214,6 @@ public class FMODWhisperBridge : MonoBehaviour
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
isRecordingActivated = false;
|
isRecordingActivated = false;
|
||||||
|
|
||||||
// Pause loopback if it should only be active during recording
|
|
||||||
if (playLoopback && loopbackOnlyWhenActive && _playChannel.hasHandle())
|
|
||||||
_playChannel.setPaused(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -277,7 +238,6 @@ public class FMODWhisperBridge : MonoBehaviour
|
|||||||
return Mathf.Clamp01(Mathf.InverseLerp(-60f, -15f, db));
|
return Mathf.Clamp01(Mathf.InverseLerp(-60f, -15f, db));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
// Always tick FMOD
|
// Always tick FMOD
|
||||||
@@ -285,8 +245,7 @@ public class FMODWhisperBridge : MonoBehaviour
|
|||||||
if (!_recSound.hasHandle()) return;
|
if (!_recSound.hasHandle()) return;
|
||||||
|
|
||||||
// Compute how many samples recorded since last frame.
|
// Compute how many samples recorded since last frame.
|
||||||
uint recPos;
|
_core.getRecordPosition(recordDriverId, out uint recPos);
|
||||||
_core.getRecordPosition(recordDriverId, out recPos);
|
|
||||||
|
|
||||||
uint deltaSamples = (recPos >= _lastRecordPos)
|
uint deltaSamples = (recPos >= _lastRecordPos)
|
||||||
? (recPos - _lastRecordPos)
|
? (recPos - _lastRecordPos)
|
||||||
@@ -353,7 +312,6 @@ public class FMODWhisperBridge : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// If skipping, we just discard this frame to ensure no stale data leaks.
|
// If skipping, we just discard this frame to ensure no stale data leaks.
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
@@ -364,7 +322,6 @@ public class FMODWhisperBridge : MonoBehaviour
|
|||||||
if (_skipOneFeedFrame) _skipOneFeedFrame = false;
|
if (_skipOneFeedFrame) _skipOneFeedFrame = false;
|
||||||
|
|
||||||
_lastRecordPos = recPos;
|
_lastRecordPos = recPos;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private string PostProcessInput(string input)
|
private string PostProcessInput(string input)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"isContinuousLocomotion": true,
|
"isContinuousLocomotion": true,
|
||||||
"continuousLocomotionSpeed": 3.0,
|
"continuousLocomotionSpeed": 3.0,
|
||||||
"volumeMaster": 0.6466318964958191,
|
"volumeMaster": 0.5095056295394898,
|
||||||
"volumeAmbient": 0.1889490932226181,
|
"volumeAmbient": 0.1889490932226181,
|
||||||
"volumeMusic": 0.5,
|
"volumeMusic": 0.5,
|
||||||
"volumeSFX": 0.5,
|
"volumeSFX": 0.5,
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
{"HighScore":1.0}
|
{"HighScore":212.0}
|
||||||
@@ -4,6 +4,10 @@
|
|||||||
"name": "karlkolm",
|
"name": "karlkolm",
|
||||||
"score": 241.0
|
"score": 241.0
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "jass",
|
||||||
|
"score": 212.0
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "andreas",
|
"name": "andreas",
|
||||||
"score": 207.0
|
"score": 207.0
|
||||||
@@ -20,6 +24,10 @@
|
|||||||
"name": "jjkujkkg",
|
"name": "jjkujkkg",
|
||||||
"score": 194.0
|
"score": 194.0
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "kuues",
|
||||||
|
"score": 186.0
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "gert",
|
"name": "gert",
|
||||||
"score": 184.0
|
"score": 184.0
|
||||||
@@ -32,6 +40,10 @@
|
|||||||
"name": "f",
|
"name": "f",
|
||||||
"score": 181.0
|
"score": 181.0
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "kosta",
|
||||||
|
"score": 180.0
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "gg",
|
"name": "gg",
|
||||||
"score": 179.0
|
"score": 179.0
|
||||||
@@ -47,14 +59,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hendrik",
|
"name": "hendrik",
|
||||||
"score": 163.0
|
"score": 163.0
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "andeas",
|
|
||||||
"score": 161.0
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "fark..........",
|
|
||||||
"score": 142.0
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user