[erlang-questions] Generating sine waves and/or audio stream output
Willem de Jong
Thu Mar 25 20:04:39 CET 2010
Hmm, I had forgotten about some of the complexities involved.
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.
I added a function that puts together the parts of the sound. You can write
it to a file like this:
> file:write_file("sinus.raw", sound:sound(440, 3, 0.5, sinus)).
(440 hertz, 3 seconds, volume 0.5 (50%), sinus wave form).
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.
On Thu, Mar 25, 2010 at 9:51 AM, Ivan Uemlianin <> wrote:
> Dear Willem
> Thanks very much for you email and your code. This looks good.
> The functions generate binaries. Do you stream the binaries to audio or do
> you write them to a file?
> 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).
> Thanks and best wishes
> Willem de Jong wrote:
>> Hello Ivan,
>> 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.
>> 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
>> 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.
>> 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.
>> I created this to generate music for my web-site: http://coria.nl. 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.
>> Any comments or suggestions will be quite welcome, Good luck,
>> On Wed, Mar 24, 2010 at 11:28 AM, Ivan Uemlianin <<mailto:
>> >> wrote:
>> Dear All
>> I am learning Erlang and one of the things I'm interested in is
>> generating sine waves, merging them and streaming them to audio
>> I can kind of imagine how generating and merging would work, with
>> a sine
>> wave represented as a list of numbers. Is there an Erlang library or
>> project working with sine waves?
>> I can't imagine how to stream a list of numbers to audio output. Can
>> anyone point me to projects/libraries/ideas for that one? Writing the
>> data to a file would be OK for now, but "live" sound would be much
>> With thanks and best wishes
>> -- ============================================================
>> Ivan A. Uemlianin
>> Speech Technology Research and Development
>> www.llaisdy.com <http://www.llaisdy.com>
>> "Froh, froh! Wie seine Sonnen, seine Sonnen fliegen"
>> (Schiller, Beethoven)
>> erlang-questions (at) erlang.org <http://erlang.org> mailing list.
>> See http://www.erlang.org/faq.html
>> To unsubscribe; mailto:
> Ivan A. Uemlianin
> Speech Technology Research and Development
> "Froh, froh! Wie seine Sonnen, seine Sonnen fliegen"
> (Schiller, Beethoven)
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:
-------------- next part --------------
An HTML attachment was scrubbed...
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 5718 bytes
Desc: not available
More information about the erlang-questions