forked from cgvr/DeltaVR
remove mic buffer clearing functionality
This commit is contained in:
@@ -47,7 +47,6 @@ public class FMODWhisperBridge : MonoBehaviour
|
||||
|
||||
// Whisper
|
||||
private WhisperStream _stream;
|
||||
private bool _streamStarted;
|
||||
|
||||
// temp conversion buffer
|
||||
private float[] _floatTmp = new float[0];
|
||||
@@ -156,8 +155,7 @@ public class FMODWhisperBridge : MonoBehaviour
|
||||
|
||||
if (_stream != null)
|
||||
{
|
||||
try { _stream.StopStream(); } catch { }
|
||||
_streamStarted = false;
|
||||
_stream.StopStream();
|
||||
}
|
||||
|
||||
try
|
||||
@@ -168,7 +166,6 @@ public class FMODWhisperBridge : MonoBehaviour
|
||||
{
|
||||
Debug.LogError($"[FMOD→Whisper] CreateStream exception: {e}");
|
||||
_stream = null;
|
||||
_streamStarted = false;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -189,11 +186,6 @@ public class FMODWhisperBridge : MonoBehaviour
|
||||
whisper.useVad = useVadInStream;
|
||||
|
||||
_stream.StartStream();
|
||||
_streamStarted = true;
|
||||
|
||||
|
||||
// Clear buffer bytes
|
||||
ClearRecordRingBuffer();
|
||||
|
||||
// Reset our read pointer to the current write head
|
||||
_core.getRecordPosition(recordDriverId, out _lastRecordPos);
|
||||
@@ -210,7 +202,7 @@ public class FMODWhisperBridge : MonoBehaviour
|
||||
/// </summary>
|
||||
public void DeactivateRecording()
|
||||
{
|
||||
if (!isRecordingActivated && !_streamStarted)
|
||||
if (!isRecordingActivated)
|
||||
return;
|
||||
|
||||
isRecordingActivated = false;
|
||||
@@ -296,7 +288,7 @@ public class FMODWhisperBridge : MonoBehaviour
|
||||
}
|
||||
|
||||
// 2) Feed audio to Whisper
|
||||
if (_streamStarted && _stream != null)
|
||||
if (_stream != null)
|
||||
{
|
||||
if (isRecordingActivated && !_skipOneFeedFrame)
|
||||
{
|
||||
@@ -407,56 +399,6 @@ public class FMODWhisperBridge : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void ClearRecordRingBuffer()
|
||||
{
|
||||
if (!_recSound.hasHandle() || _soundPcmLength == 0) return;
|
||||
|
||||
uint totalBytes = _soundPcmLength * (uint)_nativeChannels * 2; // PCM16
|
||||
IntPtr p1, p2;
|
||||
uint len1, len2;
|
||||
|
||||
// Lock the whole buffer (start=0, length=totalBytes)
|
||||
var r = _recSound.@lock(0, totalBytes, out p1, out p2, out len1, out len2);
|
||||
if (r != FMOD.RESULT.OK)
|
||||
{
|
||||
Debug.LogWarning($"[FMOD→Whisper] Could not lock ring buffer to clear: {r}");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (len1 > 0)
|
||||
{
|
||||
// zero p1
|
||||
// We’ll reuse a static zero array to avoid allocating huge buffers repeatedly
|
||||
ZeroMem(p1, (int)len1);
|
||||
}
|
||||
if (len2 > 0)
|
||||
{
|
||||
ZeroMem(p2, (int)len2);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_recSound.unlock(p1, p2, len1, len2);
|
||||
}
|
||||
}
|
||||
|
||||
// cheap zeroing helper (avoids allocating len-sized arrays each time)
|
||||
private static readonly byte[] _zeroChunk = new byte[16 * 1024]; // 16 KB
|
||||
private static void ZeroMem(IntPtr dst, int byteLen)
|
||||
{
|
||||
int offset = 0;
|
||||
while (byteLen > 0)
|
||||
{
|
||||
int n = Math.Min(_zeroChunk.Length, byteLen);
|
||||
Marshal.Copy(_zeroChunk, 0, dst + offset, n);
|
||||
offset += n;
|
||||
byteLen -= n;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes RMS (root mean square) from a PCM16 block using only safe code.
|
||||
/// Uses the shared _shortOverlay buffer (no allocations).
|
||||
|
||||
Reference in New Issue
Block a user