Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Sample Rate issue with fluid.bufcompose~ #269

Open
rconstanzo opened this issue Apr 30, 2024 · 5 comments
Open

Bug: Sample Rate issue with fluid.bufcompose~ #269

rconstanzo opened this issue Apr 30, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@rconstanzo
Copy link

rconstanzo commented Apr 30, 2024

Please tell us what you were doing! You can include code and files by drag and dropping them into the text area.

As outlined in this thread on the discourse, 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.

As mentioned by @weefuzzy "we should probably check the behaviour for bufnmf~ because that also has its own witchy buffer writing code"

7ed66b122b67368758421f1a60a2825999de154d

----------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
XCFoO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agHQTV.J5LWj2f
N9pj2pMyuppFAOaICFmlVJq8rrZg+PpoFbuZpsbtfqVc0E.96IBdbih+D4G4
aaWFpfcz94fhQxcCREZoTqzwCptN573AjyWGEgpuNN373PTia.FptkpeDqDQ
MX0UYwmxY6Re59pkIpC+P3USk2rRZHomJowcUIsBHA+J+v1JYWHd1HPueoba
J+i5cZ2+GMLOuXyREq2kX9raXLAJhLeOZzFujg06a7xH7WgV13.r071kd3fd
t2WsL7L2ZGyPeDV8PConXBT8PCUWne7Ap+E1uLzGQUOgH6rkWgk7WX8yh.k6
GtvS3MoWIJha8FkvycFo0DJE784IaSYFmktmkzy4DOW0UdybnSbL4tBmfeOU
+HLpYRn8DMV+Dz8G7+7AlqehpwaCelDrsJhsRCvY6bi2URi4fLyoSCzPkS3.
jCcBji5aj6hBR8gQBf0Shmuko8Af2.Q2FvqEs+3Ds+PfW3TfuCPPtAcGffCb
A1pXMtrKRjKz4gI5Pmn0nAHZrSrzCSzNwOhLDW3ovMhLDGVxTP7hGBZBmBpW
0KO+x1soPmPCA8f3oPRCQPjIPPvfg.dAtveaXhl5B+M3PX0qVeiSRjg3vMEa
YfsrQ8flNwNN.AivW1LZxoL4zoGY4E1aWKTYx2exTrP7R8OSyL+TmprWN6wz
p4aFIIWlUqPlRaYtoTnmBLszwSUrYdVYpUqkpqTj5D6U0+UbxVhpN++691c+
KbP7WxC
-----------end_max5_patcher-----------

What operating system were you using?

Mac

Operating system version

macOS 14.4

FluCoMa Version

1.0.7

@rconstanzo rconstanzo added the bug Something isn't working label Apr 30, 2024
@weefuzzy weefuzzy transferred this issue from flucoma/flucoma-max Apr 30, 2024
@weefuzzy
Copy link
Member

After some prodding, I've decided this is just a core issue that comes down to a logic error in BufCompose

  1. BufCompose always uses the destination sample rate when resizing the destination buffer. Surely it should be using the source sample rate, or is there some reason I've forgotten that we'd want to preserve the desination sr?
  2. The weirdness with falling back onto the system sr the first time this is run is a side-effect of using the destination sr: when (in Max) a buffer is initialized without any samples it reports as not 'valid' in our code and (for better or worse, possibly worse) reports an sr of 0; this gets sent into resize() and when you send 0 to a max buffer's sr selector, this is interpreted as 'use the system sr', it seems
  3. Meanwhile there's another logic error here, I think: surely (if we're propagating the source sr) an invariant of successfully calling BufCompose::process should be that – even if the destination buffer didn't need to resize – dest sr should equal source sr. This won't currently be the case. Indeed, we don't have a way at the moment to set the sr of a host buffer without going through resize().

So, not completely trivial to fix, it turns out. We should probably check the effects of this in supercollider as well, which will have its own buffer logic. In pure data, arrays don't have sample rates, so I'm guessing this isn't a problem in the same way.

Suggest two-stage fix, if we do want to propagate source sr:

  1. Change BufCompose call to resize() with the source sr
  2. Then think about how to deal with the no-resize case

@tremblap
Copy link
Member

tremblap commented May 9, 2024

The idea was that if we composite sections we want to be able to not change the features of the output (sr and size) - for instance, what we currently do when loading folders of files in a single buffer.

So the solution is definitely not to systematically apply source SR. I'll get thinking of what a good interface would be, but maybe fixing a default SR if it is not assigned, and a support for a SR method is the most flexible approach.

@weefuzzy
Copy link
Member

weefuzzy commented May 9, 2024

Hmm. Well, I think our current problem is that we're violating a principle of least surprise for the simplest case and meanwhile there's no useful thing we can do if someone decides to concatenate heterogeneous SR stuff into a single buffer: it would always require manual action from the user. So, I'm still sceptical about the usefulness of a flag vs people just setting the dest sr explicitly for these edge cases.

@tremblap
Copy link
Member

tremblap commented May 9, 2024

as ever the wise one, @weefuzzy - we'll just need to check how it behaves in SC then - I don't think it would cause problem as one can assign the SR post creation without issue - if we go that route we'll flag as (edgecase) breaking change

@rconstanzo
Copy link
Author

The idea was that if we composite sections we want to be able to not change the features of the output (sr and size) - for instance, what we currently do when loading folders of files in a single buffer.

I haven't tested this (thoroughly) but at the moment, when you concatenate stuff into a buffer~ isn't it just mushing whatever the original SRs are into a single buffer~ with whatever the current system SR is set to (sans any resampling) such that if you play back audio this way you'll potentially hear arbitrary playback rates based on the difference between the source SR and whatever your current system SR was at the time of bufcompose~-ing?

So, I'm still sceptical about the usefulness of a flag vs people just setting the dest sr explicitly for these edge cases.

I guess it's especially tricky since buffer~s are both audio and data here, so sometimes the SR matters (e.g. playback) and sometimes it doesn't (e.g. descriptor/stats).

I can see the usefulness of having a @destbuffersr (or whatever) attribute if someone is doing something especially fiddly, but I would think that a default behavior as you've suggested (source SR = destination SR) probably fits in with most expectations and use cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants