Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > output data to audio

Reply
Thread Tools

output data to audio

 
 
Alx
Guest
Posts: n/a
 
      05-22-2004
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.

Do you know of some other way to do it?

Thanks!

Alessandro Magni
 
Reply With Quote
 
 
 
 
rduke15
Guest
Posts: n/a
 
      05-22-2004

> 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.
>
> Do you know of some other way to do it?


I suppose your problem is not putting out the audio itself, but
packaging it into some standard container like WAV?

WAV is one of the types that can go into a RIFF file. It would not be
hard to build the file yourself.

You can start here:

http://ccrma.stanford.edu/courses/42...ts/WaveFormat/

or here:

http://netghost.narod.ru/gff/graphic...ry/micriff.htm

You may also find riffwalk.exe useful for debugging if you have a
Windows box. There seems to be a copy here:
http://www.xiph.org/archives/vorbis-...1-RIFFWALK.EXE


 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      05-23-2004

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)
* *
 
Reply With Quote
 
Alx
Guest
Posts: n/a
 
      05-23-2004
Thank you people, you already have been more than useful - Ben, I find
now after your explanation that Audio:ata can be simpler than I
thought (but what an awful perldoc!).
Going on harder and harder questions ... mind you, I know nothing
about audio so the question may be silly:
if you had to generate sounds from data with the timber of a given
instrument - what would you do? I'd really like my cellular automata
to play the sax à la Lester Young !

Thx

Alessandro Magni
 
Reply With Quote
 
Alx
Guest
Posts: n/a
 
      05-23-2004
..
..
..

P.S. I might add that I cannot play MIDI files on my soundcard - so
writing to MIDI cannot work for me!


Alessandro Magni
 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      05-23-2004

Quoth (Alx):
> if you had to generate sounds from data with the timber of a given


(just curious: did you mean 'timbre' or do Americans spell it that way?)

> instrument - what would you do? I'd really like my cellular automata
> to play the sax à la Lester Young !


A simple approach is to make a short recording of a single note on the
instrument concerned and loop it to the appropriate length. The
beginning and end of the note should be cut off, and stuck back on after
the looping, so that it sounds (relatively) smooth. The pitch can be
varied with the $au * $scalar and $au / $scalar operators; though the
calculation of the factors required may get a little involved.

I know there are many more sophisticated techniques, and there may be
ways of achieving a better result with less work, but at this point I'm
really getting out of my depth...

Ben

--
Outside of a dog, a book is a man's best friend.
Inside of a dog, it's too dark to read.
Groucho Marx
 
Reply With Quote
 
Alythh
Guest
Posts: n/a
 
      05-24-2004
Ben Morrow <> wrote in message news:<c8puai$b$>...
> Quoth (Alx):
> > if you had to generate sounds from data with the timber of a given

>
> (just curious: did you mean 'timbre' or do Americans spell it that way?)


Italians that do not know well english language often use dict:
dict timber
....
5: (music) the distinctive property of a complex sound (a voice
or noise or musical sound); "the timbre of her soprano was
rich and lovely"; "the muffled tones of the broken bell
summoned them to meet" [syn: {timbre}, {quality}, {tone}]

BUT, checking dict timbre I saw that same definition - so we have a
case similar to neighbor/neighbout I guess...

PS thanks for your help on Audio:ata ! Unfortunately I cannot make
it on my Knoppix machine (due to bug
http://rt.cpan.org/NoAuth/Bug.html?id=5384),
I'll see if Audio::Wav works better

Alessandro Magni
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how mix multi-audio file to a audio file? aeonsun Java 2 03-11-2007 06:07 AM
use audio device to play recieved partial audio data sick dick Javascript 0 04-03-2006 04:47 AM
cannot playback audio strem, audio not available or hardware not responding chieyenne Computer Support 2 05-19-2005 07:01 PM
copying audio extras on dvd to audio CD? Mad Scientist Jr DVD Video 2 10-07-2004 03:17 PM
Any way to take the audio from a concert DVD to make audio files? NOT TO BE USED FOR PIRACY. Ant DVD Video 8 06-24-2004 05:52 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57