Based on some of the comments that @b.hackbarth made in the thread about AudioGuide, I decided to whip something up to compare spectral centroid using vanilla averaging (ala fluid.bufstats~
) vs applying a weighted average based on the linear amplitude for each entry.
For the sake of simplicity I’ve done all the stats-ing in Max-land, rather than peek~
-ing the values back into a buffer~
for fluid.bufstats~
to do its thing.
----------begin_max5_patcher----------
4003.3oc0c09iihil+yU+WAJ59zopy52sY+Tuys2MqzMyrq1YNM5TqUkHIjz
zMAh.RWcOq19u88w1.AHDfj3TolpjRQgw3mW94m2rcU+y27vrEoeILel2ez6
8dO7v+7MO7f4V5a7P4u+vrsAeYYbPt4wlsLc61vjhYOZaqH7KEl6mmDjEVc2
cAEK+PTxlmxBWVXe6TDcN5QOhOYNA4i4XJGIQBeI+QOpuoIzbj2+n7MDsx7V
SW7w2hwxp2ax9sQIwgEFRAe3lo6KptKRey+0adi9iGuRd5SQK+z.rDgaYIl+
bezguURklOGlkD2IVZQPxFuhTukAwK2GGTTqxhiRBWltOw7XjJlNKLGdKAEQ
oIO0+SbrXQhIyAkJHUnhFeKYO5gQHsXgIZHVVmlTrNXYXS9uknhOqwSlG8al
mTKYGRBpe1jfslmc1eIL9ygEQKClcyku+ZXzlOTDtxK3ygYAaFbFAVpEFbIs
kfhH.4jzBeNK4D62SxoeJMaaP7DjR9TwIkR7KPJQeMJkRBeFntiDR67Vre85
vr7AjObrOXPUgHTj8KsjgP3Fgl4SB4TFgv8ZDB0Oa0jDByJYlRtAjPQwgftL
GLTzPv8vrfc6Zb6GZzEsH3iolWj5w5aEkXuEt9VYgeNpp+756FjABhBPJrOy
pU9hnB+qeMoqByR1GYdS1aBJiRRxH10Zy7ck.Ei1op4FhVC7BiX5ePs3PJGe
PZBp0MwoK+T3pFRnGlktKLIJoosyVMuJbcv93hmZB.ASl81dETt2FqQj+orn
f3ZFXSVzpzDMQzRSnuc0v8dXtig23MYFySjDrqmNC3EPrbhFyAlbe9hfLshZ
QbXC+C.XNMMtcS08KNbcQYy6hRR5HEKR2c5FyzVYOc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F+7hv06iiKNuEXQenUjFQpnN
VccoO5t6S6twFUbN1VRaAURsmYAAx9uhIGJTsL0MhmbX98DkTYCrgVO0gR7o
9N05Yg9+vBulNu.OqqlyWO2sA.L9ZEjIGRZodAlbWtJMSptCS77FzlwohQqn
H12GYCKEvxrx0ZWfPTb68Lcm4y+4nrhu58euI8hlNaO5bm3eEUu4e8l+Mrdf
hX.
-----------end_max5_patcher-----------
I’m just using a kick and snare sound from jongly.aif
also for the sake of simplicity.
The results are pretty striking, particularly for the kick example. Without the weighted average, I get a spectral centroid of 3395.637244 Hz and with it I get 2781.255879 Hz.
I wonder if it would be more accurate to also do the averaging in the log domain for centroid.
Doing this for each channel of the output of fluid.bufspectralshape~
starts to get a bit messy as well, but I wanted to whip up a quick proof of concept for the idea.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
Interface-wise, with the currently implementation it can get a little tricky as I have no idea where this would fit into the workflow.
I suppose it would be interesting to generalize it out, so you can weigh whatever statistics by a specific descriptor (perhaps a @weighting
attribute or something). Could also be useful for weighting things by pitch confidence, as @tremblap alluded to, or something funkier like that.
I guess since fluid.bufloudness~
and fluid.bufspectralshape~
are completely independent processes, there’s no way to have this weighting be default (unless ...spectralshape~
did its own internal loudness calculation, which would be a bit wasteful).