crucialfelix / supercolliderjs

The JavaScript client library for SuperCollider
https://crucialfelix.github.io/supercolliderjs/
MIT License
473 stars 41 forks source link

bufferSetn not working as expected #115

Open relativeflux opened 2 years ago

relativeflux commented 2 years ago

I am attempting to use bufferSetn to set samples into a pre-allocated buffer, but it's not working for me. I allocate the buffer like this:

await server.buffer(10);

Then I try to set it like this:

const payload = [
  -0.000732421875,
  0.00103759765625,
  -0.000823974609375,
  0.00103759765625,
  -0.00103759765625,
  0.000732421875,
  -0.000732421875,
  0.000823974609375,
  -0.000732421875,
  0.000823974609375
];

sc.server.msg.bufferSetn(0, 0, payload);

But when I subsequently use bufferGetn to interrogate the buffer contents it shows it to be still empty:

console.log(await server.callAndResponse(sc.server.msg.bufferGetn(0, 0, 10)));

Using readBuffer works fine, in that case bufferGetn shows me that the contents of the buffer have been set (readBuffer allocates it's own buffer, though).

What am I doing wrong? Is this the expected result?