@@ -65,6 +65,7 @@ class OSCContainerEncoder : public AudioEncoder {
6565 writeAudioInfo ();
6666 }
6767 writeAudio (data, len);
68+ packet_count++;
6869 return len;
6970 }
7071
@@ -93,7 +94,10 @@ class OSCContainerEncoder : public AudioEncoder {
9394 uint8_t osc_data[len + 20 ]; // 20 is guess to cover address & fmt
9495 OSCData osc{osc_data, sizeof (osc_data)};
9596 osc.setAddress (" /audio/data" );
96- osc.setFormat (" b" );
97+ osc.setFormat (" ttb" );
98+ osc.write ((uint64_t )millis ());
99+ // we use a uint64_t for a sequence number
100+ osc.write (packet_count);
97101 osc.write (data, len);
98102 p_out->write (osc_data, osc.size ());
99103 }
@@ -163,6 +167,16 @@ class OSCContainerDecoder : public ContainerDecoder {
163167 // / Provides the mime type from the encoder
164168 const char *mime () { return mime_str.c_str (); };
165169
170+ // / Replace the write to the decoder with a callback
171+ void setWriteCallback (
172+ bool (*write_callback)(uint64_t time, uint64_t seq, uint8_t *data,
173+ size_t len, void *ref)) {
174+ this ->write_callback = write_callback;
175+ }
176+
177+ // / Provide a reference object to the callback
178+ void setReference (void *ref) { this ->ref = ref; }
179+
166180 protected:
167181 bool is_active = false ;
168182 AudioDecoder *p_codec = nullptr ;
@@ -171,10 +185,19 @@ class OSCContainerDecoder : public ContainerDecoder {
171185 Print *p_out = nullptr ;
172186 OSCData osc;
173187 Str mime_str;
188+ bool (*write_callback)(uint64_t time, uint64_t seq, uint8_t *data, size_t len, void * ref) = nullptr;
189+ void *ref = nullptr ;
174190
175191 static bool parseData (OSCData &osc, void *ref) {
192+ uint64_t time = osc.readTime ();
193+ uint64_t seq = osc.readTime ();
176194 OSCBinaryData data = osc.readData ();
177195 OSCContainerDecoder *self = static_cast <OSCContainerDecoder *>(ref);
196+ // call write callbak if defined
197+ if (self->write_callback != nullptr ) {
198+ return self->write_callback (time, seq, data.data , data.len , ref);
199+ }
200+ // output to decoder
178201 if (self->p_codec != nullptr ) {
179202 self->p_codec ->write (data.data , data.len );
180203 }
0 commit comments