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 FMOD;
|
||||
using FMODUnity;
|
||||
using Whisper; // WhisperManager, WhisperStream, WhisperResult
|
||||
using Whisper;
|
||||
using Whisper.Utils;
|
||||
using Debug = UnityEngine.Debug; // AudioChunk
|
||||
using Debug = UnityEngine.Debug;
|
||||
|
||||
/// <summary>
|
||||
/// 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;
|
||||
[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 event OnWhisperSegmentUpdatedDelegate OnWhisperSegmentUpdated;
|
||||
|
||||
@@ -44,7 +38,6 @@ public class FMODWhisperBridge : MonoBehaviour
|
||||
private FMOD.System _core;
|
||||
private Sound _recSound;
|
||||
private Channel _playChannel;
|
||||
private ChannelGroup _masterGroup;
|
||||
private uint _soundPcmLength; // in samples
|
||||
private int _nativeRate;
|
||||
private int _nativeChannels;
|
||||
@@ -138,24 +131,6 @@ public class FMODWhisperBridge : MonoBehaviour
|
||||
_core.getRecordPosition(recordDriverId, out _lastRecordPos);
|
||||
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().
|
||||
await System.Threading.Tasks.Task.Yield();
|
||||
}
|
||||
@@ -217,11 +192,6 @@ public class FMODWhisperBridge : MonoBehaviour
|
||||
_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
|
||||
ClearRecordRingBuffer();
|
||||
|
||||
@@ -231,13 +201,8 @@ public class FMODWhisperBridge : MonoBehaviour
|
||||
// We’ll skip feeding for one frame to guarantee a clean start
|
||||
_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;
|
||||
Debug.Log("[FMOD→Whisper] Stream activated (buffer cleared; reading from current head).");
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -249,10 +214,6 @@ public class FMODWhisperBridge : MonoBehaviour
|
||||
return;
|
||||
|
||||
isRecordingActivated = false;
|
||||
|
||||
// Pause loopback if it should only be active during recording
|
||||
if (playLoopback && loopbackOnlyWhenActive && _playChannel.hasHandle())
|
||||
_playChannel.setPaused(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -277,7 +238,6 @@ public class FMODWhisperBridge : MonoBehaviour
|
||||
return Mathf.Clamp01(Mathf.InverseLerp(-60f, -15f, db));
|
||||
}
|
||||
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// Always tick FMOD
|
||||
@@ -285,8 +245,7 @@ public class FMODWhisperBridge : MonoBehaviour
|
||||
if (!_recSound.hasHandle()) return;
|
||||
|
||||
// Compute how many samples recorded since last frame.
|
||||
uint recPos;
|
||||
_core.getRecordPosition(recordDriverId, out recPos);
|
||||
_core.getRecordPosition(recordDriverId, out uint recPos);
|
||||
|
||||
uint deltaSamples = (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.
|
||||
}
|
||||
finally
|
||||
@@ -364,7 +322,6 @@ public class FMODWhisperBridge : MonoBehaviour
|
||||
if (_skipOneFeedFrame) _skipOneFeedFrame = false;
|
||||
|
||||
_lastRecordPos = recPos;
|
||||
|
||||
}
|
||||
|
||||
private string PostProcessInput(string input)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"isContinuousLocomotion": true,
|
||||
"continuousLocomotionSpeed": 3.0,
|
||||
"volumeMaster": 0.6466318964958191,
|
||||
"volumeMaster": 0.5095056295394898,
|
||||
"volumeAmbient": 0.1889490932226181,
|
||||
"volumeMusic": 0.5,
|
||||
"volumeSFX": 0.5,
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"HighScore":1.0}
|
||||
{"HighScore":212.0}
|
||||
@@ -4,6 +4,10 @@
|
||||
"name": "karlkolm",
|
||||
"score": 241.0
|
||||
},
|
||||
{
|
||||
"name": "jass",
|
||||
"score": 212.0
|
||||
},
|
||||
{
|
||||
"name": "andreas",
|
||||
"score": 207.0
|
||||
@@ -20,6 +24,10 @@
|
||||
"name": "jjkujkkg",
|
||||
"score": 194.0
|
||||
},
|
||||
{
|
||||
"name": "kuues",
|
||||
"score": 186.0
|
||||
},
|
||||
{
|
||||
"name": "gert",
|
||||
"score": 184.0
|
||||
@@ -32,6 +40,10 @@
|
||||
"name": "f",
|
||||
"score": 181.0
|
||||
},
|
||||
{
|
||||
"name": "kosta",
|
||||
"score": 180.0
|
||||
},
|
||||
{
|
||||
"name": "gg",
|
||||
"score": 179.0
|
||||
@@ -47,14 +59,6 @@
|
||||
{
|
||||
"name": "hendrik",
|
||||
"score": 163.0
|
||||
},
|
||||
{
|
||||
"name": "andeas",
|
||||
"score": 161.0
|
||||
},
|
||||
{
|
||||
"name": "fark..........",
|
||||
"score": 142.0
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user