Multiplying buffers
Hello, I'm somewhat experienced with some aspects of Max but there are some things I don't know yet. What I'd like to do is keep track of the last, say, 1000 values of a signal and store it in a buffer, which I think I'd do with poke~ (please let me know if I'm wrong).
Then I would like to take another 1000 element long buffer that is loaded from a file when the patcher is started and multiply them together, element by element, and add the 1000 resulting elements together to get just one number. Basically I want to take the dot product of two long vectors/buffers.
I would like to do this whole calculation at the sampling frequency, so I get a new number every sample, which I then add to the original signal (the calculation is a bit more complicated than that, but once I know how to do this, I think I can add the rest).
I'm thinking of using vexpr for the multiplication. The examples give very much shorter lists of numbers as inputs, so I'm not sure whether it will work with buffers or how to get it to do that. Also, I'm not entirely sure how to get the sum of a buffer.
Would poke and vexpr work for this, and how does one get the sum of a buffer? Someone asked this 15 years ago (https://cycling74.com/forums/values-from-a-buffer) and never got an answer. Is it even possible to get the sum of a buffer? Would I have to use Uzi to step through or can it just do the calculation without that? Would Uzi be fast enough for it to work at the sampling rate?
Thanks.
first of all, if you want to do that permanently for an incoming audio stream and not only for a single time, it is out of question to have data rate objects involved.
finding the dot product of (0.1 0.2 0.3)•(0.4 0.5 0.6) is indeed a bit complicated with signals.
there is an accumulation operator for signals, [+=~] - but can not be reset to zero using signals.
so for operating on a stream you would need to make windows and alternately use 2 of those. (the inactive accumulator can then be set to 0 by a bang message)
maybe you can also just abuse some other object and for example do convolution with buffir~ or something like that, but i had not have my coffee yet.