On Fri, Jul 15, 2016 at 12:23:55AM +0200, Bart Brouns wrote:
> Hi everybody,
>
> Let me introduce myself:
> My name is Bart Brouns and I've been doing some form of dsp for almost
> 20 years.
Hi Bart
> Started with a Nord Micro Modular, then learned pure-data, and for the
> last 3 years moved to faust. http://faust.grame.fr/
>
> I made an algorithm that applies a binary operator to the last N
> samples, where N is variable at runtime.
>
> It's very cheap: it uses just two delay lines and two operators for each
> doubling of the number of samples you want to apply the operator to.
> So for calculating the sum of the last 65536 samples, you need just 32
> delay lines and 32 plus operators.
> You can still continuously vary the number of samples to compute at
> runtime.
>
> It is written in faust, but I hope the comments make it clear what I'm
> doing:
>
> https://github.com/magnetophon/faustCompressors/blob/master/slidingReduce.lib
>
> If it helps, here is the cpp version as produced by the faust compiler,
> with + as the operator and maxN = 8:
> https://github.com/magnetophon/faustCompressors/blob/master/slidingsum.cpp
>
> I would love to know if this is a known algorithm.
> I imagine it is, but have no idea how to find out.
Sorry, I don't know if your algorithm exists. However, I have used a
different technique written from scratch to implement a moving average
filter for my lisp tool.
There is a buffer with an index (if you prefer, a delay line with length
max_size). "size" represents the number of the values to sum and it is
less than or equal to max_size. The core of the algo is:
/* Subtract the oldest, add the new and update the index. */
sum = sum - buffer[i] + input;
buffer[i] = input;
i = (i >= size ? 0 : i + 1);
If "size" changes and it is less than the old size, it is necessary to
decrement the accumulated sum:
for (j = size; j < old_size; j++) {
sum -= buffer[j];
buffer[j] = 0;
}
old_size = size;
That's all. The original code of my MAF is
;;; Virtual UGen from incudine/src/vug/filter.lisp
(define-vug maf (in (max-size positive-fixnum) (size positive-fixnum))
"Moving Average Filter."
(with ((data (make-frame max-size :zero-p t))
(sum 0.0d0)
(old-size 0)
(size (prog1 (min size max-size)
(when (< 0 size old-size)
;; Update the sum
(loop for i from size below old-size do
(decf sum (smp-ref data i))
(setf (smp-ref data i) +sample-zero+)))
(setf old-size size)))
(index 0))
(declare (type pointer data) (type sample sum)
(type non-negative-fixnum index old-size)
(type positive-fixnum size))
;; Subtract the old, add the new and update the index
(setf sum (+ (- sum (smp-ref data index)) in))
(setf (smp-ref data index) in)
(let ((new (1+ index)))
(setf index (if (>= index size) 0 new)))
(/ sum size)))
___
dupswapdrop: music-dsp mailing list
music-dsp@music.columbia.edu
https://lists.columbia.edu/mailman/listinfo/music-dsp