< Back to IRCAM Forum

Scaling a bpf-lib

Hi,
this is a very old problem that, as far as I know, has never been solved. The bpf-scale function seems to work correctly for a single bpf, but when used in a loop for a bpf-lib, it always gives wrong results. I am attaching here a mwe that encapsulates the issue. Is there any chance to fix it? Thanks in advance for all.
Best,
Francesco
bpf-scale mwe.omp (10.9 KB)

Dear Francesco,

This is logical. Since you are scaling THREE different bpfs with the same values.
if you need to have a “correct” sequential bpfs, you should merge the bpfs into one bpf OR consider changing the x0x1y0y1 values at each bpf.

Best
K

Dear Karim,
it’s my bad, the example I chose was not the right one. I’m trying to write a function that scales the bpf-lib as an object (changing the x-min/max and the ymin/max relatively for each bpf), but I get a “bad binding error”. Maybe it’s some silly mistake. Surely you’ll spot right away what does not work here.
Here’s the code:

(in-package :om)

; new method for scaling the entire BPF-lib as an object 

(defmethod! bpf-lib-scale ((self bpf-lib) &key ymin ymax xmin xmax) 
            (let* ((bpflist (bpf-list self))
                   (theymin (list-min (loop for bpf in bpflist collect
                                            (list-min (y-points bpf)))))
                   (theymax (list-max (loop for bpf in bpflist collect
                                            (list-max (y-points bpf)))))
                   (thexmin (list-min (loop for bpf in bpflist collect
                                            (list-min (x-points bpf)))))
                   (thexmax (list-max (loop for bpf in bpflist collect
                                            (list-max (x-points bpf)))))
             

              (print (format nil "ymin=~d ymax=~d xmin=~d xmax=~d" theymin theymax thexmin thexmax))

 (make-instance 'bpf-lib
                             :bpf-list (loop for bpf in bpflist collect
                                             (bpf-from-list (om-scale (x-points bpf) (or xmin thexmin) (or xmax thexmax) thexmin thexmax) 
                                                            (om-scale (y-points bpf) (or ymin theymin) (or ymax theymax) theymin theymax)
                                                            'bpf (decimals bpf)))
              ))))

And here’s the error:
Error while evaluating the box BPF-LIB-SCALE : Bad binding form: (make-instance (quote bpf-lib) :bpf-list (loop for bpf in bpflist collect (bpf-from-list (om-scale (x-points bpf) (or xmin thexmin) (or xmax thexmax) thexmin thexmax) (om-scale (y-points bpf) (or ymin theymin) (or ymax theymax) theymin theymax) (quote bpf) (decimals bpf)))).

Best,
Francesco

Dear Francesco,

Good, but you have some errors in your code. Here it is corrected:
Unnamed.lisp (1.2 KB)

And it works!

Best
K