@@ -65,6 +65,7 @@ class OSCContainerEncoder : public AudioEncoder {
65
65
writeAudioInfo ();
66
66
}
67
67
writeAudio (data, len);
68
+ packet_count++;
68
69
return len;
69
70
}
70
71
@@ -93,7 +94,10 @@ class OSCContainerEncoder : public AudioEncoder {
93
94
uint8_t osc_data[len + 20 ]; // 20 is guess to cover address & fmt
94
95
OSCData osc{osc_data, sizeof (osc_data)};
95
96
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);
97
101
osc.write (data, len);
98
102
p_out->write (osc_data, osc.size ());
99
103
}
@@ -163,6 +167,16 @@ class OSCContainerDecoder : public ContainerDecoder {
163
167
// / Provides the mime type from the encoder
164
168
const char *mime () { return mime_str.c_str (); };
165
169
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
+
166
180
protected:
167
181
bool is_active = false ;
168
182
AudioDecoder *p_codec = nullptr ;
@@ -171,10 +185,19 @@ class OSCContainerDecoder : public ContainerDecoder {
171
185
Print *p_out = nullptr ;
172
186
OSCData osc;
173
187
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 ;
174
190
175
191
static bool parseData (OSCData &osc, void *ref) {
192
+ uint64_t time = osc.readTime ();
193
+ uint64_t seq = osc.readTime ();
176
194
OSCBinaryData data = osc.readData ();
177
195
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
178
201
if (self->p_codec != nullptr ) {
179
202
self->p_codec ->write (data.data , data.len );
180
203
}
0 commit comments