Quoth
(Alx):
> I was playing around yesterday, and I came out with a Perlish version
> of a simple Cellular Automata.
> Apart from visualizing the result (thank you, GD), I wanted to
> "listen" the result of the evolution of the automata as an audio file.
> After a day browsing CPAN, I say that I'm a little disappointed: I
> didn't find any <simple> way to output data (e.g. some @CA=(numbers,
> numbers, numbers,...) in .wav or other format.
> Yes, there is a ton of Audio::... modules.
> Yes, there are Audio::Wav and Audio:
ata.
> Yet, for a simple layman as me who does not recognize a bitrate from
> some other beast, the docs of those modules are really hard to master.
I would say from a quick look at the docs that you might want something
like this:
use Audio:

ata;
# $rate gives the number of samples per second: in other words, with a
# sample rate of 44100 (which is standard CD-quality) a data list of
# 44100 points will create one second of audio. Making this quantity
# larger will make the sound both faster, higher in pitch and better
# quality (there will be less 'buzz' in the sound); making it smaller
# will do the reverse.
my $rate = 44100;
# As Audio:

ata deals with float values rather than fixed- or
# variable-sized int values you don't have to worry about bitrates.
my $au = Audio:

ata->new(rate => $rate);
my @data = (list of floating-point values between -1.0 and 1.0);
$au->data(@data);
# The above will use the numbers directly as samples. You may get more
# harmonious results (you will also lose the dependancy on sample rate
# mentioned above) by using $au->tone to create, say, tenth-second
# samples whose pitch depends on your automaton and then adding all the
# samples for each time period with the overloaded + and joining the
# time periods together with the overloaded . . Say your automaton is a
# function which can be called
# @state = autom @state;
# to derive the state at a given time-period from the one before; then
# you could do something like
use List::Util qw/reduce/;
@state = (initial conditions);
for (1..100) {
my @au = map {
my $new = Audio:

ata->new(rate => $rate);
$new->tone($_, 0.1, 0.5);
$new;
} @state;
$au .= reduce { $a + $b } @au;
@state = autom @state;
}
# Note also that human perception of both pitch and amplitude is
# logarithmic, so you may well find ->tone(2**$_, works better...
# obviously this will all need lots of seasoning to taste
{
# This creates a Sun .au file. If you need M$ wav then you can use
# sox to convert it.
open my $AU, '>', 'file.au' or die "can't create file.au: $!";
$au->Save($AU);
}
# Caveat: the above is all *entirely* untested.
Ben
--
And if you wanna make sense / Whatcha looking at me for? (Fiona Apple)
*
*