Hmm, I had forgotten about some of the complexities involved. <div><br></div><div>I do not have a function that writes wav files. I put the pcm data that is generated by this into a flash file. For wav files you have to do add a header and framing, I believe. </div>
<div><br></div><div>I added a function that puts together the parts of the sound. You can write it to a file like this:</div><div><div>> file:write_file("sinus.raw", sound:sound(440, 3, 0.5, sinus)).</div><div>
<br></div><div>(440 hertz, 3 seconds, volume 0.5 (50%), sinus wave form).</div><div><br></div><div>This file will be in "raw" format (pcm without headers). With the current settings the sample rate is 22050, mono, sample size 16 bits big endian. </div>
<div><br></div><div>Regards,</div><div>Willem</div><div><br></div><br><div class="gmail_quote">On Thu, Mar 25, 2010 at 9:51 AM, Ivan Uemlianin <span dir="ltr"><<a href="mailto:ivan@llaisdy.com">ivan@llaisdy.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Dear Willem<br>
<br>
Thanks very much for you email and your code.  This looks good.<br>
<br>
The functions generate binaries.  Do you stream the binaries to audio or do you write them to a file?<br>
<br>
Do you have a function that writes wav files?  If not I shall write one (unless a function to stream to audio will be easier but I don't think it will be).<br>
<br>
Thanks and best wishes<br>
<br>
Ivan<br>
<br>
Willem de Jong wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
Hello Ivan,<br>
<br>
I have an erlang module that generates sounds. It can generate different wave forms (right now all I need is a saw-like shape and a sinus shape). I am attaching it. It is a bit messy, perhaps, but it should give you an impression of how it can be done.<br>

<br>
The synthesize() function uses the sinus() function to create a number of complete waves, and then pastes  these together repeatedly (I assumed that would be more efficient that calculating the sinus() function for each sample).<br>

<br>
The syntesize() function returns a couple of sound fragments: an "attaque" bit that starts with an amplitude of zero, a fade-out bit where the volume decreases back to 0, and a long and a short bit of sound with a stable volume. Another module creates a complete sound-fragment of the desired duration by pasting together the attaque, a number of long fragments and short fragments in such a way that it matches the duration (as precisely as possible), and a fade out bit.<br>

<br>
As you can see this creates sounds with a fixed pitch and volume (within one sound, that is). Also note that both the length and the pitch of the sound will be approximations.<br>
<br>
I created this to generate music for my web-site: <a href="http://coria.nl" target="_blank">http://coria.nl</a>.  You can try the result there, if you want. It is a site that enables me and the other members of my choir (and anyone else who is interested) to practise our music. <br>

Any comments or suggestions will be quite welcome, Good luck,<br>
Willem <br>
<br>
<br>
<br>
<br></div><div class="im">
On Wed, Mar 24, 2010 at 11:28 AM, Ivan Uemlianin <<a href="mailto:ivan@llaisdy.com" target="_blank">ivan@llaisdy.com</a> <mailto:<a href="mailto:ivan@llaisdy.com" target="_blank">ivan@llaisdy.com</a>>> wrote:<br>

<br>
    Dear All<br>
<br>
    I am learning Erlang and one of the things I'm interested in is<br>
    generating sine waves, merging them and streaming them to audio<br>
    output.<br>
<br>
    I can kind of imagine how generating and merging would work, with<br>
    a sine<br>
    wave represented as a list of numbers.  Is there an Erlang library or<br>
    project working with sine waves?<br>
<br>
    I can't imagine how to stream a list of numbers to audio output.  Can<br>
    anyone point me to projects/libraries/ideas for that one?  Writing the<br>
    data to a file would be OK for now, but "live" sound would be much<br>
    nicer.<br>
<br>
    With thanks and best wishes<br>
<br>
    Ivan<br>
<br>
    --     ============================================================<br>
    Ivan A. Uemlianin<br>
    Speech Technology Research and Development<br>
<br></div>
                      <a href="mailto:ivan@llaisdy.com" target="_blank">ivan@llaisdy.com</a> <mailto:<a href="mailto:ivan@llaisdy.com" target="_blank">ivan@llaisdy.com</a>><br>
                       <a href="http://www.llaisdy.com" target="_blank">www.llaisdy.com</a> <<a href="http://www.llaisdy.com" target="_blank">http://www.llaisdy.com</a>><br>
                           <a href="http://llaisdy.wordpress.com" target="_blank">llaisdy.wordpress.com</a><br>
    <<a href="http://llaisdy.wordpress.com" target="_blank">http://llaisdy.wordpress.com</a>><div class="im"><br>
                       <a href="http://www.linkedin.com/in/ivanuemlianin" target="_blank">www.linkedin.com/in/ivanuemlianin</a><br></div>
    <<a href="http://www.linkedin.com/in/ivanuemlianin" target="_blank">http://www.linkedin.com/in/ivanuemlianin</a>><div class="im"><br>
<br>
      "Froh, froh! Wie seine Sonnen, seine Sonnen fliegen"<br>
                       (Schiller, Beethoven)<br>
    ============================================================<br>
<br>
<br>
<br>
    ________________________________________________________________<br></div>
    erlang-questions (at) <a href="http://erlang.org" target="_blank">erlang.org</a> <<a href="http://erlang.org" target="_blank">http://erlang.org</a>> mailing list.<div class="im"><br>
    See <a href="http://www.erlang.org/faq.html" target="_blank">http://www.erlang.org/faq.html</a><br>
    To unsubscribe; mailto:<a href="mailto:erlang-questions-unsubscribe@erlang.org" target="_blank">erlang-questions-unsubscribe@erlang.org</a><br>
    <mailto:<a href="mailto:erlang-questions-unsubscribe@erlang.org" target="_blank">erlang-questions-unsubscribe@erlang.org</a>><br>
<br>
<br>
</div></blockquote><div><div></div><div class="h5">
<br>
<br>
-- <br>
============================================================<br>
Ivan A. Uemlianin<br>
Speech Technology Research and Development<br>
<br>
                   <a href="mailto:ivan@llaisdy.com" target="_blank">ivan@llaisdy.com</a><br>
                    <a href="http://www.llaisdy.com" target="_blank">www.llaisdy.com</a><br>
                        <a href="http://llaisdy.wordpress.com" target="_blank">llaisdy.wordpress.com</a><br>
                    <a href="http://www.linkedin.com/in/ivanuemlianin" target="_blank">www.linkedin.com/in/ivanuemlianin</a><br>
<br>
   "Froh, froh! Wie seine Sonnen, seine Sonnen fliegen"<br>
                    (Schiller, Beethoven)<br>
============================================================<br>
<br>
<br>
________________________________________________________________<br>
erlang-questions (at) <a href="http://erlang.org" target="_blank">erlang.org</a> mailing list.<br>
See <a href="http://www.erlang.org/faq.html" target="_blank">http://www.erlang.org/faq.html</a><br>
To unsubscribe; mailto:<a href="mailto:erlang-questions-unsubscribe@erlang.org" target="_blank">erlang-questions-unsubscribe@erlang.org</a><br>
<br>
</div></div></blockquote></div><br></div>