Skip to content

Commit b95a209

Browse files
committed
AR sound sync - make sequence checks user configurable
to support scenarios where several sending nodes are needed.
1 parent 03a909a commit b95a209

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

usermods/audioreactive/audio_reactive.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111

112112
static volatile bool disableSoundProcessing = false; // if true, sound processing (FFT, filters, AGC) will be suspended. "volatile" as its shared between tasks.
113113
static uint8_t audioSyncEnabled = AUDIOSYNC_NONE; // bit field: bit 0 - send, bit 1 - receive, bit 2 - use local if not receiving
114+
static bool audioSyncSequence = true; // if true, the receiver will drop out-of-sequence packets
114115
static bool udpSyncConnected = false; // UDP connection status -> true if connected to multicast group
115116

116117
#define NUM_GEQ_CHANNELS 16 // number of frequency channels. Don't change !!
@@ -1577,6 +1578,7 @@ class AudioReactive : public Usermod {
15771578
if(receivedPacket->frameCounter > lastFrameCounter) sequenceOK = true; // sequence OK
15781579
if((lastFrameCounter < 12) && (receivedPacket->frameCounter > 248)) sequenceOK = false; // prevent sequence "roll-back" due to late packets (1->254)
15791580
if((lastFrameCounter > 248) && (receivedPacket->frameCounter < 12)) sequenceOK = true; // handle roll-over (255 -> 0)
1581+
if(audioSyncSequence == false) sequenceOK = true; // sequence checking disabled by user
15801582
if((sequenceOK == false) && (receivedPacket->frameCounter != 0)) { // always accept "0" - its the legacy value
15811583
DEBUGSR_PRINTF("Skipping audio frame out of order or duplicated - %u vs %u\n", lastFrameCounter, receivedPacket->frameCounter);
15821584
return false; // reject out-of sequence frame
@@ -2415,7 +2417,10 @@ class AudioReactive : public Usermod {
24152417
if (audioSyncEnabled && udpSyncConnected && (millis() - last_UDPTime < AUDIOSYNC_IDLE_MS)) {
24162418
if (receivedFormat == 1) infoArr.add(F(" v1"));
24172419
if (receivedFormat == 2) infoArr.add(F(" v2"));
2418-
if (receivedFormat == 3) infoArr.add(F(" v2+"));
2420+
if (receivedFormat == 3) {
2421+
if (audioSyncSequence) infoArr.add(F(" v2+")); // Sequence checking enabled
2422+
else infoArr.add(F(" v2"));
2423+
}
24192424
}
24202425

24212426
#if defined(WLED_DEBUG) || defined(SR_DEBUG) || defined(SR_STATS)
@@ -2567,6 +2572,7 @@ class AudioReactive : public Usermod {
25672572
JsonObject sync = top.createNestedObject("sync");
25682573
sync[F("port")] = audioSyncPort;
25692574
sync[F("mode")] = audioSyncEnabled;
2575+
sync[F("check_sequence")] = audioSyncSequence;
25702576
}
25712577

25722578

@@ -2635,6 +2641,7 @@ class AudioReactive : public Usermod {
26352641

26362642
configComplete &= getJsonValue(top["sync"][F("port")], audioSyncPort);
26372643
configComplete &= getJsonValue(top["sync"][F("mode")], audioSyncEnabled);
2644+
configComplete &= getJsonValue(top["sync"][F("check_sequence")], audioSyncSequence);
26382645

26392646
return configComplete;
26402647
}
@@ -2813,7 +2820,12 @@ class AudioReactive : public Usermod {
28132820
#ifdef ARDUINO_ARCH_ESP32
28142821
oappend(SET_F("addOption(dd,'Receive or Local',6);")); // AUDIOSYNC_REC_PLUS
28152822
#endif
2816-
oappend(SET_F("addInfo('AudioReactive:sync:mode',1,'<br> Sync audio data with other WLEDs');"));
2823+
// check_sequence: Receiver skips out-of-sequence packets when enabled
2824+
oappend(SET_F("dd=addDropdown('AudioReactive','sync:check_sequence');"));
2825+
oappend(SET_F("addOption(dd,'Off',0);"));
2826+
oappend(SET_F("addOption(dd,'On',1);"));
2827+
2828+
oappend(SET_F("addInfo('AudioReactive:sync:check_sequence',1,'<i>when receiving</i> ☾<br> Sync audio data with other WLEDs');")); // must append this to the last field of 'sync'
28172829

28182830
oappend(SET_F("addInfo('AudioReactive:digitalmic:type',1,'<i>requires reboot!</i>');")); // 0 is field type, 1 is actual field
28192831
#ifdef ARDUINO_ARCH_ESP32
@@ -2856,7 +2868,7 @@ class AudioReactive : public Usermod {
28562868
oappend(SET_F("xOpt('AudioReactive:digitalmic:pin[]',5,' ⎌',")); oappendi(ES7243_SCLPIN); oappend(");");
28572869
#endif
28582870
oappend(SET_F("dRO('AudioReactive:digitalmic:pin[]',5);")); // disable read only pins
2859-
#endif
2871+
#endif
28602872
}
28612873

28622874

0 commit comments

Comments
 (0)