On Tue, 15 Nov 2011, Stephen Sinclair wrote:
> However, there is certainly potential to implement a FAUST-like DSL in
> Haskell. The trick would be to compile it to machine code in-memory
> in a non-realtime thread and be able to dynamically modify the DSP
> graph by adding and removing blocks without interrupting the audio
> stream. I believe this could be achieved by atomic pointer swapping
> to new bits of real-time code, but I haven't personally tested the
> idea.
>
> It's already possible to do similar things using Haskell-LLVM, isn't it?
In terms of Haskell, FAUST is a DSL based on arrows. I also use (causal)
arrows for LLVM based signal processing.
> Of course swapping sub-blocks in and out of a larger DSP graph implies
> that on some level there is a master "mixer" or something, which is
> itself a DSP block. This implies to me that there are multiple levels
> of optimization possible. If a subblock is swapped out, should its
> parent be recompiled for maximum efficiency? How do you decide where
> to stop? Maybe some incremental compilation strategy could be used to
> first swap a child and then recompile parents up the chain, eventually
> resulting in the whole graph being recompiled.
In my LLVM software synthesizer I already swap blocks in and out, since
whenever a key is pressed a new signal generator is started and it is
stopped and removed when the release phase terminates. The results of all
signal generators are mixed. However this is hard-coded and does not yet
use one of the functional reactive programming frameworks.
I considered on-demand compilation, that is compilation of instrument
specific code once the instrument is used first, but this would yield a
high latency for the first played tone.
> In any case, another difficulty is maintaining state between
> recompilations. If a block is swapped out and the parent is
> recompiled, it would be desirable for any state (filter history, etc)
> in the parent not affected by the child to remain intact. This may
> require some tracking strategy in the compiler, but I see it as a
> possibly surmountable obstacle.
Because of all of these difficulties and because I suspect that the
benefit is small, I have not tried to do clever recompilation and
optimization during the musical performance.
Currently I structure instruments like this:
complexSound (append attackDecay release)
where each of attackDecay, release, complexSound contains a block of LLVM
compiled code and Haskell manages routing of the signal chunks.
___
haskell-art mailing list
haskell-art@lurk.org
http://lists.lurk.org/mailman/listinfo/haskell-art