[CM] [Snd] Guile newbie help?

Bill Schottstaedt bil@ccrma.Stanford.EDU
Mon, 5 Mar 2007 04:03:50 -0800

Your code returns the value of the last sample (you're integrating
the differences, so you end up re-making the original).
The following is perhaps what you're aiming at:

(let ((prev 0.0)
       (sum 0.0))
     (lambda (next)
       (set! sum (+ sum (- next prev)))
       (set! prev next)

But, I think the confusion comes from the question of when the reader
sets its "at-end" flag. Since the reader returns 0.0 when it hits the
end (and then notices that it has hit the end), your code always
ends with a 0.0 sample, and that becomes the value of the sum.
One (slightly bizarre) way around this is:

(let ((prev 0.0)
      (sum 0.0)
      (next 0.0)
      (rdr (make-sample-reader 0)))
  (while (let ()
           (set! next (rdr))
           (not (sample-reader-at-end? rdr)))
    ;(snd-print (format #f "~%;sum: ~A, ~A ~A" sum next prev))
    (set! sum (+ sum (- next prev)))
    (set! prev next))

Anyway, I think reader-at-end? probably should be true one sample
earlier -- I'll look at this later today.