@@ -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
0 commit comments