On Thu, Feb 17, 2011 at 6:21 PM, Henning Thielemann <
lemm...@henning-thielemann.de> wrote:

> John Lato schrieb:
>
> > Does anyone know of a purely functional equivalent to a circular buffer?
>
> It depends on the application you have in mind.
> For programming a constant delay of n samples of a lazy list including
> feedback,
> you can use a lazy list instead of a circular buffer.
> For efficiency reasons you can use a chunky StorableVector with chunk
> size up to n.
> This is like rolling out the circular buffer to an infinite list.
>
> Something simple like
>
> let output :: [Double]
>    output = mix (input + delay n output)
>
> would work.
>

For a constant delay, one of the real-time queues would probably be better
yet.

A chunky StorableVector can work, but there's a lot of copying unless n is
very small.  If I use a Sequence for the mutating chunk and vectors for
other chunks, it might work well.  Sort of like a Builder.  I'll try it and
report back if I find anything interesting.  But I'm really interested in
long-ish (several seconds) delay lines with multiple varying taps.  The
other "brillant" idea I have involves reconfiguring queue lengths based upon
lookups, similar to a splay tree.  I may try to implement it but I would be
surprised if get it right.


>
> >  I'm looking for something that supports efficient insertion and lookup,
> > and doesn't rely upon mutable data.  I don't want to use mutable data
> > because I'd like to embed this in CCA, which to my knowledge doesn't yet
> > support Kleisli arrows.
>
> Embedding the above idea into an arrow that emits one output sample per
> input sample would not work. Mutable arrays in the ST monad would help,
> but this requires that the arrow is built around the ST monad.
>

 Exactly, hence the problem using this with CCA at the moment.
_______________________________________________
haskell-art mailing list
haskell-art@lurk.org
http://lists.lurk.org/mailman/listinfo/haskell-art

Reply via email to