@Sam_Pluta AOO is for real-time audio streaming, but I don’t think that’s what @retroriff is trying to do.
Since OSC does not support raw Blob types directly, we believe it must be sent as a
Uint8Array
.
I’m not sure what you mean here, OSC blobs are literally raw bytes. Which JS OSC library are you using? What does the documentation say about OSC blobs?
There are few issues in the code.
#1 You need to make sure that ~numChunks
is an Integer:
~numChunks = (~int8Array.size / 1024).ceil.asInteger;
#2 Unfortunately, .clump
does not seem to preserve the original type, instead it always returns an Array
! In your case this has unexpected and drastic consequences: NetAddr.sendMsg
treats Array
as a nested sclang-style OSC message, converts it to raw bytes and sends it as a blob. (This behavior is not actually documented, but I think this is meant for OSC completion messages, such as in SynthDef.add
or Buffer.write
.) This means your audio data is accidentally interpreted as an OSC message! You need to make sure that you are really sending an Int8Array
.
Here’s a working version of the sending part:
(
~sc = NetAddr.localAddr;
~int8Array = Int8Array.fill(44100 * 8, { 127.rand2 });
~numChunks = (~int8Array.size / 1024).ceil.asInteger;
~sc.sendMsg("/test", -1, ~numChunks);
~numChunks.do { |i|
var index = i * 1024;
~sc.sendMsg("/test", i, ~int8Array[index..(index + 1024 - 1)]);
};
)
Regarding the lost messages: every UDP socket has a send and receive buffer with a fixed capacity and if you send messages at a faster rate than the receiving end is able to process, packets that do not fit into the receive buffer are simply discarded. That is one reason why UDP is considered an unreliable protocol.
The default capacity of the buffer depends on the OS and its settings. (Applications can also manually set the socket buffer size, see GitHub · Where software is built) Windows, for example, has a notoriously small default size, typically 65 kB. In your case this corresponds to about 64 chunks of 1024 samples. And indeed, here on Windows 10 I can only send about 64 chunks.
This means you must be careful not to send too many UDP messages in one go. Instead, you should wait for a few milliseconds between every N messages to avoid overflowing the receiver’s socket buffer. See this recent post for how to do this in sclang: How best to slow down / queue outgoing OSC messages - #2 by Spacechild1
In JS you can do something very similar, but you would need to implement your own wait
function: What is the JavaScript version of sleep()? - Stack Overflow.
Side note: why is ~receivedChunks
a Dictionary
and not an Array
?