I am learning Erlang and one of the things I'm interested in is
generating sine waves, merging them and streaming them to audio output.
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 nicer.
With thanks and best wishes
Ivan
--
============================================================
Ivan A. Uemlianin
Speech Technology Research and Development
iv...@llaisdy.com
www.llaisdy.com
llaisdy.wordpress.com
www.linkedin.com/in/ivanuemlianin
"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:erlang-questio...@erlang.org
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
Ivan
> iv...@llaisdy.com <mailto:iv...@llaisdy.com>
> www.llaisdy.com <http://www.llaisdy.com>
> llaisdy.wordpress.com
> <http://llaisdy.wordpress.com>
> www.linkedin.com/in/ivanuemlianin
> <http://www.linkedin.com/in/ivanuemlianin>
>
> "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:erlang-questio...@erlang.org
> <mailto:erlang-questio...@erlang.org>
Could you also please send me the code if possible? as I am also highly
interested in using Erlang for sound generation.
Regards and thanks,
-Gene
Thanks Willem. I'll write a function to write a wav header and report
back: I've got one I wrote in C somewhere; might be interesting to
compare the two.
I'll also look into streaming to audio (there is esdl, an erlang binding
for sdl, but that looks a bit hefty, and doesn'ty work with smp enabled
erlang).
Best
Ivan
On 25/03/2010 19:04, Willem de Jong wrote:
> 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.
>
> Regards,
> Willem
--
This hacky little script (my first in erlang!) will write a sound and
pipe it to audio.
play(Sound) ->
Fn = sinus,
file:write_file(io_lib:format("~p.raw", [Fn]), Sound),
os:cmd(io_lib:format("sox -r ~B -c 1 -w -s ~p.raw ~p.wav",
[?SamplingRate, Fn, Fn])),
os:cmd(io_lib:format("afplay ~p.wav", [Fn])).
sox is a unix tool, here it converts the raw audio file to wav format
file. On a proper unix platform sox can output to audio. On MacOSX you
have to write to a file and use afplay to play the file.
This is not a very nice function. I shall write a function to convert a
raw sound into a wav format binary. It would be v nice to habe
something like an erlang binding for PortAudio. In the meantime, the
function above makes it possible to listen to generated sounds fmor the
erlang shell.
With thanks and apologies
Ivan
On 25/03/2010 19:04, Willem de Jong wrote:
> 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.
>
> Regards,
> Willem
--