Skip to content

Commit db437b3

Browse files
committed
further changes to the event driver and related calls
1 parent c70b718 commit db437b3

6 files changed

Lines changed: 60 additions & 27 deletions

File tree

Basis/Packages/com.basis.eventdriver/BasisEventDriver.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public void Update()
176176
}
177177

178178
OSCAcquisitionServer.Simulate();
179-
SMModuleAvatarPerformanceLimits.SimulateDebounce();
179+
SMModuleAvatarPerformanceLimits.Simulate();
180180
timeSinceLastUpdate += DeltaTime;
181181
}
182182

@@ -226,7 +226,6 @@ public void LateUpdate()
226226

227227
// ── Device management ──
228228
ProfileBegin(PROF_DEVICE_MANAGEMENT);
229-
BasisDeviceManagement.OnDeviceManagementLoop?.Invoke();
230229
if (BasisDeviceManagement.HasEvents)
231230
{
232231
BasisDeviceManagement.Instance.Simulate();
@@ -242,8 +241,8 @@ public void LateUpdate()
242241
ProfileBegin(PROF_LOCAL_PLAYER);
243242
if (BasisLocalPlayer.PlayerReady)
244243
{
245-
var LocalCameraDriver = BasisLocalCameraDriver.Instance;
246-
var localplayer = BasisLocalPlayer.Instance;
244+
BasisLocalCameraDriver LocalCameraDriver = BasisLocalCameraDriver.Instance;
245+
BasisLocalPlayer localplayer = BasisLocalPlayer.Instance;
247246
localplayer.FacialBlinkDriver.Simulate(TimeAsDouble);
248247
localplayer.LocalVisemeDriver.Apply();
249248
localplayer.Simulate(DeltaTime);

Basis/Packages/com.basis.framework/Device Management/BasisDeviceManagement.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ private async void OnDestroy()
259259
}
260260
public void Simulate()
261261
{
262+
OnDeviceManagementLoop?.Invoke();
262263
int Count = BaseTypes.Count;
263264
for (int Index = 0; Index < Count; Index++)
264265
{

Basis/Packages/com.basis.framework/Drivers/Local/BasisLocalMicrophoneDriver.cs

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -456,13 +456,23 @@ public static void MicrophoneUpdate()
456456

457457
int currentPosition = Microphone.GetPosition(MicrophoneDevice);
458458
position = currentPosition;
459-
if (position <= 0) return;
459+
if (position <= 0)
460+
{
461+
return;
462+
}
460463

461464
int clipFrames = clip.samples;
462-
if (clipFrames <= 0) return;
465+
if (clipFrames <= 0)
466+
{
467+
return;
468+
}
463469

464470
int ch = clip.channels;
465-
if (ch < 1) ch = 1;
471+
if (ch < 1)
472+
{
473+
ch = 1;
474+
}
475+
466476
channels = ch;
467477

468478
// Clamp to min(bufferLength, clipFrames) so a device restart that produced a
@@ -471,15 +481,16 @@ public static void MicrophoneUpdate()
471481
LocalOpusSettings.CreateOrResizeArray(framesToUse, ref microphoneBufferArray);
472482

473483
int dataLength = GetDataLength(framesToUse, head, position);
474-
if (dataLength < ProcessFrameSize) return;
484+
if (dataLength < ProcessFrameSize)
485+
{
486+
return;
487+
}
475488

476-
// Pull only the new region [head .. head+dataLength) from the clip, in fixed
477-
// chunks of one process frame. Each chunk is downmixed into the mono ring at
478-
// its matching ring positions. Replaces a previous full-clip GetData per tick
479-
// (~192 KB → ~3.8 KB per chunk for mono).
480489
int chunkInterleaved = ProcessFrameSize * channels;
481490
if (_micDelta == null || _micDelta.Length != chunkInterleaved)
491+
{
482492
_micDelta = new float[chunkInterleaved];
493+
}
483494

484495
// Serialize ring-buffer writes against the bg processor reading the same
485496
// region and advancing `head`. Without the lock, ProcessAudioData can read
@@ -500,9 +511,13 @@ public static void MicrophoneUpdate()
500511
processingEvent.Set();
501512

502513
if (Interlocked.Exchange(ref _scheduleMainHasAudio, 0) == 1)
514+
{
503515
MainThreadOnHasAudio?.Invoke();
516+
}
504517
else if (Interlocked.Exchange(ref _scheduleMainHasSilence, 0) == 1)
518+
{
505519
MainThreadOnHasSilence?.Invoke();
520+
}
506521
}
507522

508523
/// <summary>
@@ -512,16 +527,26 @@ public static void MicrophoneUpdate()
512527
/// </summary>
513528
private static void DownmixDeltaIntoRingMono(int headFrame, int frameCount, int ringFrames, int ch, float[] srcDelta, float[] dstMono)
514529
{
515-
if (srcDelta == null || dstMono == null || frameCount <= 0) return;
516-
if (ch < 1) ch = 1;
530+
if (srcDelta == null || dstMono == null || frameCount <= 0)
531+
{
532+
return;
533+
}
534+
535+
if (ch < 1)
536+
{
537+
ch = 1;
538+
}
517539

518540
int firstFrames = Mathf.Min(frameCount, ringFrames - headFrame);
519541

520542
if (ch == 1)
521543
{
522544
Array.Copy(srcDelta, 0, dstMono, headFrame, firstFrames);
523545
if (firstFrames < frameCount)
546+
{
524547
Array.Copy(srcDelta, firstFrames, dstMono, 0, frameCount - firstFrames);
548+
}
549+
525550
return;
526551
}
527552

Basis/Packages/com.basis.framework/Networking/BasisRemoteFaceManagement.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,36 +132,36 @@ public static void Simulate(double t, float dt)
132132
byte* pUse = (byte*)useJobEye.GetUnsafePtr();
133133
byte* pLastHas = (byte*)lastHasEyeBones.GetUnsafePtr();
134134

135-
for (int i = 0; i < count; i++)
135+
for (int Index = 0; Index < count; Index++)
136136
{
137-
BasisNetworkReceiver receiver = snapshot[i];
137+
BasisNetworkReceiver receiver = snapshot[Index];
138138
BasisRemoteFaceDriver Face = receiver.RemotePlayer.RemoteFaceDriver;
139139

140-
bool slotChanged = i >= lastBuiltCount
141-
|| !ReferenceEquals(faceCache[i], Face)
142-
|| lastFaceGen[i] != Face.FaceGeneration;
140+
bool slotChanged = Index >= lastBuiltCount
141+
|| !ReferenceEquals(faceCache[Index], Face)
142+
|| lastFaceGen[Index] != Face.FaceGeneration;
143143

144144
if (slotChanged)
145145
{
146146
bool hasValidEyeBones = Face.HasEyeBones
147147
&& Face.LeftEyeTransform != null
148148
&& Face.RightEyeTransform != null;
149149

150-
faceCache[i] = Face;
151-
eyesCache[i] = receiver.EyesAndMouth;
152-
lastFaceGen[i] = Face.FaceGeneration;
153-
pLastHas[i] = hasValidEyeBones ? (byte)1 : (byte)0;
150+
faceCache[Index] = Face;
151+
eyesCache[Index] = receiver.EyesAndMouth;
152+
lastFaceGen[Index] = Face.FaceGeneration;
153+
pLastHas[Index] = hasValidEyeBones ? (byte)1 : (byte)0;
154154

155155
// Blit on eye-bone presence, not useJob, so calibration is ready when OverrideEye later clears.
156156
if (hasValidEyeBones)
157157
{
158-
pCalL[i] = new EyeCalibrationBlit
158+
pCalL[Index] = new EyeCalibrationBlit
159159
{
160160
basis = Face.calLeft.basis,
161161
invBasis = Face.calLeft.invBasis,
162162
initialRotation = Face.calLeft.initialRotation,
163163
};
164-
pCalR[i] = new EyeCalibrationBlit
164+
pCalR[Index] = new EyeCalibrationBlit
165165
{
166166
basis = Face.calRight.basis,
167167
invBasis = Face.calRight.invBasis,
@@ -172,7 +172,7 @@ public static void Simulate(double t, float dt)
172172
needRebuild = true;
173173
}
174174

175-
pUse[i] = (pLastHas[i] != 0 && !Face.OverrideEye) ? (byte)1 : (byte)0;
175+
pUse[Index] = (pLastHas[Index] != 0 && !Face.OverrideEye) ? (byte)1 : (byte)0;
176176
}
177177
}
178178

Basis/Packages/com.basis.framework/Settings/SMModuleAvatarPerformanceLimits.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ private static void OnTagFilterChanged()
3333
{
3434
ScheduleReconcile();
3535
}
36-
public static void SimulateDebounce()
36+
public static void Simulate()
3737
{
3838
if (RequiresPerformanceCheck != false)
3939
{

Basis/Packages/com.basis.framework/UI/NamePlate/BasisRemoteNamePlateDriver.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,9 @@ public static void ScheduleSimulate(double now)
732732
ProcessBakeQueue();
733733

734734
if (!ShouldRunJobs())
735+
{
735736
return;
737+
}
736738

737739
ScheduleSimulate(now, returnDelay, transitionDuration, NormalColorFloat4);
738740
}
@@ -748,7 +750,9 @@ public static void ScheduleSimulate(double now, float hold, float fade, float4 n
748750
{
749751
// If a job is still running, don't stomp buffers.
750752
if (jobScheduled && !handle.IsCompleted)
753+
{
751754
return;
755+
}
752756

753757
// If it finished, complete it now so we can apply structural changes/resizes safely.
754758
if (jobScheduled)
@@ -758,10 +762,14 @@ public static void ScheduleSimulate(double now, float hold, float fade, float4 n
758762
}
759763

760764
if (pendingRemove.Count > 0 || pendingAdd.Count > 0)
765+
{
761766
ApplyPendingStructuralChanges();
767+
}
762768

763769
if (count == 0)
770+
{
764771
return;
772+
}
765773

766774
EnsureCapacity(count);
767775

0 commit comments

Comments
 (0)