Merging stereo to mono with fluid.bufcompose~?

This is more of a noob-ish question, but I feel like I’m overlooking something and the helpfile/reference isn’t super clear since fluid.bufcompose~ is such a Swiss army knife-esque external.

I am trying to take a stereo file and sum it to mono, ala vanilla processing in any DAW, such that if i have two identically channels, the stereo summed version would be identical to either of the L/R channels. So I would think that I would just take each channel and individually copy them into a single channel buffer with @destgain 0.5. This, however, doesn’t work and the results are louder than each channel individually.

In testing with synthetic buffers (e.g. fill 0.5) I found out that to get the expected results I have to do @destgain 0.5 and @gain 0.666667, which feels kind of hacky.

Am I missing or overlooking something here?


----------begin_max5_patcher----------
1115.3ocwYksihiCE8Y3qvJpklokXhrc16mp+ioFUx.FpTShCJ1oVlVc8sO1
WmPwRGH.F3kDryM95y4tFyOGOxaZ06boG5Gn+FMZzOGOZDLkYhQsiG4UxdeV
ASBh4MqprjKTdSrOSweWAyG5iXyeoQpPKY4htGuhol8btX4S07YJqZBSS8wS
PjDBbKH1bil4iQ+S6KsnRnVvlwMxSZmSzTlKJ3J4lSlOGTc0zW9qfLuujrpQ
0IJdi0Tl+evZRw9Xyr+Z7XykIWHxC7Q0bYSgRhX0bwenPOpks1f3G8VSDZQz
uLSkWIdpHWvmU0Hf2OnephjAjSDl5Go4nvT2PUw2Mph5ijMkH0y7xC3gPvYF
fF.nlPibCpCuan9O03slidlIQpJzTNhounT7ZzarOLSo8WJ3r5G8LLCZZyhE
75u2sLa4rP6m0nAXHfJNBnsHXTPvFz1QoHZOTjC4hxJQ0Sk75k74s.8.NBIo
g.HvfK.gBPxbc3PBe8gj7Cg54ACFRbf4lM62IgEZp6vxzFkpZcVZ6ho9XE2t
U8lxDK8Vuw9cIww1DS1j2gcWGNVh+hopYkbcvvSbAaZAeyXxswIwg1LhOpj8
ulHwElaG03EhSLXLDhsnX2Tyhd8SIsnnRu18Zm8lL.acR1F1ZBw53R2B60kL
P33ghbxoa9omA7K4RIaIeOy+2H8SIGmJBixZs+Q6vDaga593lj34LW69vlwi
IWHYkqjH74ASRHApgXSRkFsmE+X3LHvc3TveSuj6ASaH6mnMJnzKX0QAZ+yg
3q2hbJgZq3jbXn+absIQdNy8sGnunnIetul.nE4RUunFd3.7lIvsD5IakIz6
gUV2dHF6.Sca831L6jnS2Tm4NK8arW4lzne1sjVfKz4F2ssoiC8C7CqCywxx
011U.zoBMBR7G2a48n8Yld5TI9JvLP2W2LNgjQNWNIwcbxk18lMvOH5Lad6F
06VeE3VjWTfv9QmWssfHvqNzl6CexI8n2tRa1OrvjtCQcPBuVjmY+XJR5oWZ
K8pWZSgldwt0j3t9xNQ7EDc0MsqKcq+vjUUR9mnGjUM0y3sF6GlykpbAbLQa
UzCdf4j0Ld91QREqVyAL8T5UY8.B5A8127SIhbvN+GBYl.8CEmbFdKY2tFgt
drI1krIMAx2bNrYHwcrISopax6VOyHX5NN47xqFZKPRwPRFR6nSxgAeapqzC
7ubnSSOanStLnCJBNovcNKeX2Zlea9vFkzhstV4Qese2HtYCgLGZyFBUUOmW
2uQXnp1j08np1jLwHzEoIiC1f0ztfDeYplb+Tc1PTM0A7a3P.Ym49hzT7.Tz
N6FG4sNHenqjpI2OUmLjzCDWDiNjDQ6rcbTfxPbpLGrk607NqZOf1EANzAoo
z8zjs.Ca0pW40xVoAknKs9REPAoSfg4B6P3u0zql+Zdm7PcOOVst7oRW6ro1
9A7uGaOFbuxJMYJzUlstqZ3oUIT117w9xUsmtNTce7uF++.4p8vF
-----------end_max5_patcher-----------

(the intended use case here is to check for mono/stereo when analyzing a corpus, and if the file is stereo, to sum it to mono for the purposes of analysis/matching, but then still do normal stereo playback on the back end. so I have a whole forking process that checks for channel count and minimum file size and fluid.bufcompose~s as required to make sure it all works)

the problem is destgain should be gain

destgain is how much the destination ‘rectangle’ zone where you will write should be scaled before you write the new values. aka overdub gain.

so you need to do this for it to work:

  1. you indeed delete with resizing to 0 - bufcompose doesn’t resize the destination downwards to enable writing within a range.

  2. you write as you did with @gain 0.5 the first channel

  3. you write above with @gain 0.5 and @destgain 1.0 - the first scales the new values by half, the second keeps the first channel written material at the volume it was.

I hope this helps

p

1 Like

Ok, this works!

I never would have figured this out, mainly because the helpfile (incorrectly states that):

By default the destination gain is 1 meaning the content is overwritten. You can “dub” new content variably, by using the destgain attribute.

So I assumed that @destgain 1 = overwriting stuff.

Cross referencing with the reference file and that one appears to say the correct information:

The gain applied to the samples in the region of the destination buffer over which the source is to be copied. The default value (0) will overwrite that section of the destination buffer, and a value of 1.0 would sum the source to the material that was present.

Made a github issue for the typo.

1 Like

fixed on dev, thanks for the catch. I’m trying to include it in the release of early next week - more soon

1 Like