Skip to content

Commit d9a91ee

Browse files
authored
Refactor audioSyncPacket structure for V2 format
Updated the V2 format structure for audio sync packets to improve clarity / readability.
1 parent 69a9568 commit d9a91ee

1 file changed

Lines changed: 12 additions & 15 deletions

File tree

docs/soundreactive/sync.md

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,27 +61,24 @@ UDP_SYNC_HEADER is a versioning number that's defined in audio_reactive.h
6161
6262
### V2 Format - WLED version >= 0.14.0 (including MoonModules fork)
6363
64-
<div style="background-color: Gray">
65-
66-
```c++
64+
``` { .cpp .copy }
6765
#define UDP_SYNC_HEADER_V2 "00002"
6866
6967
// new "V2" audiosync struct - 44 Bytes
70-
struct __attribute__ ((packed)) audioSyncPacket { // WLEDMM "packed" ensures that there are no additional gaps
71-
char header[6]; // 06 Bytes offset 0 - "00002" for protocol version 2 ( includes \0 for c-style string termination)
72-
uint8_t pressure[2]; // 02 Bytes, offset 6 - optional - sound pressure as fixed point (8bit integer, 8bit fraction)
73-
float sampleRaw; // 04 Bytes offset 8 - either "sampleRaw" or "rawSampleAgc" depending on soundAgc setting
74-
float sampleSmth; // 04 Bytes offset 12 - either "sampleAvg" or "sampleAgc" depending on soundAgc setting
75-
uint8_t samplePeak; // 01 Bytes offset 16 - 0 no peak; >=1 peak detected. In future, this will also provide peak Magnitude
76-
uint8_t frameCounter; // 01 Bytes offset 17 - optional - rolling counter to track duplicate/out of order packets
77-
uint8_t fftResult[16]; // 16 Bytes offset 18 - 16 GEQ channels, each channel has one byte (uint8_t)
78-
uint16_t zeroCrossingCount; // 02 Bytes, offset 34 - optional - number of zero crossings seen in 23ms
79-
float FFT_Magnitude; // 04 Bytes offset 36 - largest FFT result from a single run (raw value, can go up to 4096)
80-
float FFT_MajorPeak; // 04 Bytes offset 40 - frequency (Hz) of largest FFT result
68+
struct __attribute__ ((packed)) audioSyncPacket {
69+
char header[6]; // 06 Bytes offset 0 - "00002" for protocol version 2 ( includes \0 for c-style string termination)
70+
uint8_t pressure[2]; // 02 Bytes, offset 6 - optional - sound pressure as fixed point (8bit integer, 8bit fraction)
71+
float sampleRaw; // 04 Bytes offset 8 - either "sampleRaw" or "rawSampleAgc" depending on soundAgc setting
72+
float sampleSmth; // 04 Bytes offset 12 - either "sampleAvg" or "sampleAgc" depending on soundAgc setting
73+
uint8_t samplePeak; // 01 Bytes offset 16 - 0 no peak; >=1 peak detected. In future, this will also provide peak Magnitude
74+
uint8_t frameCounter; // 01 Bytes offset 17 - optional - rolling counter to track duplicate/out of order packets
75+
uint8_t fftResult[16]; // 16 Bytes offset 18 - 16 GEQ channels, each channel has one byte (uint8_t)
76+
uint16_t zeroCrossingCount; // 02 Bytes, offset 34 - optional - number of zero crossings seen in 23ms
77+
float FFT_Magnitude; // 04 Bytes offset 36 - largest FFT result from a single run (raw value, can go up to 4096)
78+
float FFT_MajorPeak; // 04 Bytes offset 40 - frequency (Hz) of largest FFT result
8179
};
8280
8381
```
84-
</div>
8582

8683
The V2 format expects that AGC is performed by the sender, so there is no need to transmit "AGC" and "non-AGC" samples separately. To save bandwidth, the `myvals[]` array was removed, and all numbers are either `float` or `uint8_t`.
8784

0 commit comments

Comments
 (0)