<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sun, May 1, 2016 at 9:59 PM, Jeremy Shaw <span dir="ltr"><<a href="mailto:jeremy@n-heptane.com" target="_blank">jeremy@n-heptane.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You might consider using the pipes library:<br>
<br>
<a href="http://hackage.haskell.org/package/pipes-4.1.8/docs/Pipes-Tutorial.html" rel="noreferrer" target="_blank">http://hackage.haskell.org/package/pipes-4.1.8/docs/Pipes-Tutorial.html</a><br>
<br>
The pipes library will allow you to generate audio and write it to<br>
disk with out having to worry if you are going to suck up all the RAM<br>
accidentally.<br>
<br>
It should also help you  decompose your pipeline into smaller pieces.<br>
For example, you would like to be able to decompose your code into<br>
things like:<br>
<br>
 1. the code that generates the audio<br>
 2. the code that converts the audio into a format like wav/aiff/etc<br>
 3. the code that writes binary data to disk<br>
<br>
And then simply glue those pieces together, while feeling secure that<br>
you don't create a space leak in the process.<br>
<br>
It will also allow you to use StateT or IO (or anything other type<br>
with a Monad instance) if you need to.<br>
<br>
The pipes library is not trivial to learn. But it is well designed.<br>
<br>
Without using the pipes library you have two options:<br>
<br>
 1. understand how laziness works and then be very careful to make<br>
sure you never accidentally hold onto data too long and cause a space<br>
leak.<br>
<br>
 2. use strict IO functions and write code that generates the output<br>
in little chunks at a time. The concept is, perhaps, easy to<br>
understand. But as your code base grows, the code will become harder<br>
to understand and to modify.<br></blockquote><div><br></div><div><br></div><div>Thanks, Jeremy. At this time the code is experimental and may never go anywhere after the initial experiments, so if your option #2 is the easiest to get going, that would be my choice. </div><div><br></div><div>Mike</div><div><br></div><div><br></div><div> </div></div></div></div>