!7 module ReceiveAudio > DynPrintLog { bool enabled; L chunks = synchroLinkedList(); transient int minChunksToPlay = 2; start { vmBus_onMessage('gotFromPrivateChat, voidfunc(S sender, S msg) { if (startsWith(msg, "audio:")) chunks.add(shortArrayFromBytes_littleEndian(base64decode(substring(msg, 6)))); }); dm_addSoundSource(new VF1() { int sampleIndex; short[] samples; public void get(double[] pair) { pair[0] = pair[1] = 0; if (!enabled) ret; if (samples == null) { if (l(chunks) < minChunksToPlay) { minChunksToPlay = 2; ret; } minChunksToPlay = 1; samples = syncPopFirst(chunks); sampleIndex = 0; } pair[0] = samples[sampleIndex]; pair[1] = samples[sampleIndex+1]; sampleIndex += 2; if (sampleIndex >= l(samples)) samples = null; } }); } visualize { ret centerAndSouthWithMargins(super.visualize(), centerAndEast(withLabel("Send to:", dm_fieldTextField('sendTo)), dm_fieldCheckBox('enabled))); } }