Sample rate bug in fluid.bufcompose~?

As always, making a thread before a github repo since I want to make sure I’m not overlooking anything.

So after banging my head against the wall trying to figure why I was getting weird sample rates in my corpus I managed to narrow things down to something in fluid.bufcompose~. This is either a bug or an overlooked edge case, but either way, I don’t think it should be doing what it’s doing.

Here’s a patch showing the issue:


----------begin_max5_patcher----------
1666.3oc0ZszjiZCD9rmeEpnxosbbgdwibJImxgjKYOlJ0TXaYOrqMxEHlcl
r0t+1idAFx.iYLHSlspEvZDzp+Z0e8C3q2svaM+IVgG3m.+EXwhud2hE5gTC
rv96EdGSdZygjB8z71vOdjkI7VZ9aB1SB83Qq.oB.+QVdd5VVAP7.CHOKRyR
Do7LvG+ypa4PZFaCuLSeeH6fqKWu9.SMBr0HExGlZTe6n63YhcIaZMS0ZXC+
.O2nGvU9KA90Gj+D721YltUuV4q+zORIUqmrxioYGXhhlOSkbJR+GsbPpmS8
b4khpI2bQkkbTOYueic3QlHcSR0y+ThXyCoY6uOmsQXWhwnUzkf3X8ZEFGqN
EPUqT087s6tScX4HMIgq.ELQKq.eGXc4N4MbhWvdUCRW.cS3COivWDUgdQ9Z
XCFoOQBlXzKX8JvlGXa9rbqqB2XGOIdVgd6X4fj8IoYiB+PyH9E3GpfLJ1s.
3FEkPAHi+E.grB9YugAMjvYDZnXh1WLTiPvf.0Iz0BMqKEBd89jl5Xz40Ptb
8IX42yxRrTf9ul92VQqF0Lj34SLid3sNIauWMwWmaBvZMknOgHUGuJE8HqnH
YO6E6AHDnu+pt.f3NMxn2lR9pJHECMJnV0nQZEDM0VRp+raIog5.cTp+DXIy
XeQpVuvPllsi+cPRFWFWOuKX.58FTU+9z0cG3IRlDfjSsPetdfgbg5+oYlKG
BfEq2S.gXU3jqdqQu7eIp.HRiGSEAoEC30DwfDLizh33.SDCChghbRDCpLj6
V1tjxCxvFBNn34BA63kRc7R3FYVCmzJZBZTvVubP34OZBDgtAQSh76NZB9FD
Mw+FDLgL+ASLICNqwRHn2QwRr3kaCkPS5uVjwvMh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qEs+3Ds+PfW3TfuCPPtAcGffCb
A1pXMtrKRjKz4gI5Pmn0nAHZrSrzCSzNwOhLDW3ovMhLDGVxTP7hGBZBmBpW
0KO+x1soPmPCA8f3oPRCQPjIPPvfg.dAtveaXhl5B+M3PX0qVeiSRjg3vMEa
YfsrQ8flNwNN.AivW1LZxoL4zoGY4E1aWKTYx2exTrP7R8OSyL+TmprWN6wz
p4aFIIWlUqPlRaYtoTnmBLszwSUrYdVYpUqkpqTj5D6U0+UbxVhpN++691c+
KbP7WxC
-----------end_max5_patcher-----------

In short, if the buffer~ that fluid.bufcompose~ is copying into has no size (as in, not declared, or after a sizeinsamps 0), when you copy something into it, the SR is set to the system SR, and not the @source SR or even the SR if the buffer~ if you manually declare it.

This means that any automatic buffer management-related things with fluid.bufcompose~ will end up getting the SRs changed for all the newly created buffers, which can be a huge problem on its own. And whenever using sizeinsamps 0 to specifically empty/clear a buffer~ for iterative/loop-based processes, the SRs also get changed.

Is this a bug or an overlooked edge case?

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

In either case, some thoughts. An ideal solution would be able to specify a @destsamplerate, but I think the plumbing required for that is probably too late. Another possible solution would be to always inherit the SR from @source when creating new buffers (probably simplest and most elegant). AND/OR respecting the SR of a buffer~ if it already exists. I can see this being problematic, however, as a sizeinsamps 0 buffer~ will always default to the system SR and I wouldn’t think there’s a way to tell the difference between a manually set or default SR for an empty buffer~.

Can confirm that it’s not doing what you think it should be doing. Patch below more concisely isolates the actual behaviour, which is that the ‘sample rate’ of the destination buffer~ is what gets used. Agree that this probably isn’t the desired behaviour but can’t for the life of me remember if it was deliberately designed that way or not. @tremblap might.

Anyway, please do file on gh, along with a note that we should probably check the behaviour for bufnmf~ because that also has its own witchy buffer writing code. The fix would be to use the source SR; can’t see any benefit to adding params to choose, tbh: the sr on buffers in Max and SC doesn’t actually do anything except tell playback objects something useful.

So, for now a (slightly tedious) workaround if needed would be to set the destination SR from the source in Max when you’re doing batches of bufcompose in cases where this will be an issue.


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D0vokzzuWP0q6WPs
bXVVX06q9K.+t7C3
-----------end_max5_patcher-----------

Thinking on this further, and this is likely the best solution.

///////////////////////////////////////////////////////

Hmm, your ‘workaround’ patch seems extra weird and inconsistent (I’m left more confused than before!).

Your patch when I run it for the first time (with my system SR at 44.1k):

(I see 44.1k, not 48k)

When I run it again after changing my SR to 48k:

(the SR changes to follow the system/buffer SR)

When I change the SR back to 44.1k:

So the fluid.bufcompose~ SR is kind-of based on system SR, sometimes?

Ah sorry, that wasn’t the workaround but the patch reproducing the issue. Workaround is trivial, so didn’t occur to me that a patch would be needed.

However, that changing the system SR has any bearing on that patch is weird, so now I need to look at the code again and figure out where that’s coming from.

1 Like

Gotcha. I did read/respond to this on very little sleep so didn’t process things fully.

I guess given the funky behavior from my last post explains why any workaround I was trying wasn’t working (consistently).

I’ve also now made a github issue (I put it in Max rather than Core as I don’t know if this is a wrapper-layer issue or more underlying (seems the latter, but I don’t know enough to say)).

Cheers. I suspect it might be both Max and Core

  1. The actual desired behaviour (that BufCompose uses the source buffer SR) is a core thing
  2. The weirdness with 0-length buffers getting stuck with the system SR looks like a Max thing

(but we can sort that out whilst we fix)

2 Likes