@@ -275,21 +275,19 @@ double SyncStream::getSyncAccuracy()
275275 if (pulses.size () > 0 )
276276 {
277277
278- // LOGD ("Sync accuracy for stream ", streamKey);
278+ LOGD (" Sync accuracy for stream " , streamKey);
279279
280- // LOGD ("latestSyncSampleNumber: ", latestSyncSampleNumber);
281- // LOGD ("latestGlobalSyncTime: ", latestGlobalSyncTime);
282- // LOGD ("globalStartTime: ", globalStartTime);
283- // LOGD ("actualSampleRate: ", actualSampleRate);
284- // ORIGINAL CALCULATION:
285- // double estimatedGlobalTime = latestSyncSampleNumber / actualSampleRate + globalStartTime;
280+ LOGD (" latestSyncSampleNumber: " , latestSyncSampleNumber);
281+ LOGD (" latestGlobalSyncTime: " , latestGlobalSyncTime);
282+ LOGD (" globalStartTime: " , globalStartTime);
283+ LOGD (" actualSampleRate: " , actualSampleRate);
286284
287285 // NEW CALCULATION:
288286 double estimatedGlobalTime = double (latestSyncSampleNumber - baselineMatchingPulse.localSampleNumber )
289287 / actualSampleRate
290288 + (baselineMatchingPulse.globalTimestamp );
291- // LOGD ("estimatedGlobalTime: ", estimatedGlobalTime);
292- // LOGD ("difference: ", latestGlobalSyncTime - estimatedGlobalTime);
289+ LOGD (" estimatedGlobalTime: " , estimatedGlobalTime);
290+ LOGD (" difference: " , latestGlobalSyncTime - estimatedGlobalTime);
293291
294292 return (estimatedGlobalTime - latestGlobalSyncTime) * 1000 ;
295293 }
@@ -301,8 +299,8 @@ double SyncStream::getSyncAccuracy()
301299
302300void SyncStream::syncWith (const SyncStream* mainStream)
303301{
304- // LOGD ("Synchronizing ", streamKey, " with ", mainStream->streamKey, "...");
305- // LOGD ("Expected sample rate: ", expectedSampleRate);
302+ LOGD (" Synchronizing " , streamKey, " with " , mainStream->streamKey , " ..." );
303+ LOGD (" Expected sample rate: " , expectedSampleRate);
306304
307305 if (mainStream->pulses .size () < 2 || pulses.size () < 2 )
308306 {
@@ -591,61 +589,13 @@ void SyncStream::attemptBarcodeDecoding()
591589 {
592590 LOGD (" Successful decoding...setting isHarpStream to true." );
593591 isHarpStream = true ;
592+ isSynchronized = true ;
594593 }
595594 else
596595 {
597596 LOGD (" Unsuccessful decoding...setting harpDetectionActive to false." )
598597 harpDetectionActive = false ;
599598 }
600-
601- /* // Check if enough time has elapsed to consider the barcode potentially complete
602- int64 currentTime = Time::currentTimeMillis();
603- double elapsedTimeMs = double(currentTime - barcodeStartTime);
604-
605- // If we've been collecting for more than the expected barcode duration, try to decode
606- if (elapsedTimeMs >= HarpDecoder::EXPECTED_BARCODE_DURATION_MS * 0.8) // Allow some tolerance
607- {
608- // Try to decode with current events
609- HarpBarcode barcode;
610-
611- if (harpDecoder.decodeBarcode(currentBarcodeEvents, barcode, expectedSampleRate))
612- {
613- if (validateBarcodeStructure(barcode) && validateBarcodeTimestamp(barcode))
614- {
615- completedBarcodes.push_back(barcode);
616- consecutiveValidBarcodes++;
617-
618- LOGD("Valid Harp barcode decoded via timer: timestamp=", barcode.encodedTime, ", consecutive=", consecutiveValidBarcodes);
619-
620- // Check if we have enough valid barcodes to confirm Harp mode
621- if (consecutiveValidBarcodes >= MIN_VALID_BARCODES_FOR_HARP)
622- {
623- harpState = HarpDetectionState::HARP_CONFIRMED;
624- isHarpStream = true;
625- harpDetectionActive = false; // Stop dual detection
626-
627- LOGD("Stream ", streamKey, " confirmed as Harp stream via timer");
628-
629- // Set baseline for synchronization
630- if (!baselineMatchingBarcode.isComplete)
631- {
632- baselineMatchingBarcode = barcode;
633- }
634- }
635-
636- predictNextBarcodeStart(barcode);
637- }
638- else
639- {
640- consecutiveValidBarcodes = 0; // Reset count on invalid barcode
641- }
642- }
643-
644- // Reset for next barcode regardless of decode success
645- harpState = HarpDetectionState::IDLE;
646- currentBarcodeEvents.clear();
647- barcodeStartTime = -1;
648- }*/
649599}
650600
651601
@@ -669,9 +619,11 @@ void SyncStream::syncWithHarp()
669619
670620 // Calculate global start time
671621 LOGD (" Estimated global start time: " , double (firstBarcode.encodedTime ) - firstBarcode.localStartTimestamp );
672- globalStartTime = double (firstBarcode.encodedTime ) - firstBarcode.localStartTimestamp ;
622+ globalStartTime = ( double (firstBarcode.encodedTime ) - firstBarcode.localStartTimestamp ) / 1000 ;
673623 baselineMatchingPulse.globalTimestamp = double (firstBarcode.encodedTime );
674624 baselineMatchingPulse.localSampleNumber = firstBarcode.localStartSample ;
625+ latestSyncSampleNumber = lastBarcode.barcodeEvents .front ().first ;
626+ latestGlobalSyncTime = double (lastBarcode.encodedTime );
675627
676628 isSynchronized = true ;
677629
@@ -853,7 +805,7 @@ double Synchronizer::getAccuracy (String streamKey)
853805 return 0.0 ;
854806 else
855807 {
856- if (streamKey == mainStreamKey)
808+ if (streamKey == mainStreamKey && !streams[streamKey]-> isHarpStream )
857809 return 0.0 ;
858810 else
859811 {
@@ -894,15 +846,8 @@ SyncStatus Synchronizer::getStatus (String streamKey)
894846 if (streamGeneratesTimestamps (streamKey))
895847 return SyncStatus::HARDWARE_SYNCED;
896848
897- // Check for Harp-specific states
898849 if (streams[streamKey]->isHarpStream )
899- {
900850 return SyncStatus::HARP_CLOCK;
901- }
902- else if (streams[streamKey]->harpDetectionActive )
903- {
904- return SyncStatus::HARP_DETECTING;
905- }
906851
907852 if (isStreamSynced (streamKey))
908853 return SyncStatus::SYNCED;
0 commit comments