ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/PDL-Audio/birds
Revision: 1.1
Committed: Tue Dec 28 01:05:16 2004 UTC (19 years, 4 months ago) by root
Branch: MAIN
CVS Tags: rel-1_1
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 #!/usr/bin/perl
2    
3     use PDL;
4     use PDL::Audio;
5     use PDL::Graphics::PGPLOT;
6    
7     #sub line {}
8    
9     $|=1;
10    
11     $birds = do 'bird-def.pl';
12    
13     sub hz(){ 44100 }
14    
15     sub bird {
16     my ($dur, $freq, $skew, $amp, $freqenv, $ampenv, $partials) = @_;
17     $freqenv = gen_env $dur, @$freqenv;
18     $ampenv = gen_env $dur, @$ampenv;
19     my $os = gen_oscil $dur, $freq, 0, $freqenv*$skew;#*PDL::Audio::PI2;
20     $os = pdl($partials)->partials2polynomial(1)->polynomial($os) if defined $partials;
21     $os*$ampenv;
22     }
23    
24     sub shuffle($) { # (x y x y ... => ((x y) (x y) ...
25     my $xy = pdl $_[0]; [$xy->slice("1:-1:2"), $xy->slice("0:-1:2")];
26     }
27    
28     sub gen_bird {
29     my @mix;
30     for (@{+shift}) {
31     my ($beg, $dur, $freq, $skew, $amp, $freqenv, $ampenv, $partials) = @$_;
32     $partials = pdl($partials)->slice("1:-1:2") if $partials;
33     push @mix, ($beg*hz, bird(hz*$dur, $freq/hz, $skew/hz, $amp, shuffle $freqenv, shuffle $ampenv, $partials));
34     line $mix[-1];
35     }
36     audiomix @mix;
37     }
38    
39     for (keys %$birds) {
40     print $_;
41     $chirp = (gen_bird $birds->{$_})->cut_leading_silence(0);
42     line $chirp;
43     print "\n";
44     scale2short($chirp)->playaudio(rate => hz);
45     }
46    
47