Audio
view release on metacpan or search on metacpan
y_max_value => PI,
y_tick_number => 8,
title => 'FFT');
$mw->Button(-text => 'Play', -command => \&play)->pack;
$mw->Label(-image => $org,-anchor => 'e')->pack(-anchor => 'e',-fill => 'x');
$mw->Label(-image => $ffta,-anchor => 'e')->pack(-anchor => 'e',-fill => 'x');
$mw->Label(-image => $fftp,-anchor => 'e')->pack(-anchor => 'e',-fill => 'x');
MainLoop;
sub xfftx
{
my ($x,$au,$v) = @_;
my $n = $au->samples;
my $f = $au->rate;
unless ($au->amplitude($x) > 1e-3)
{
# undef $_[2];
return '';
}
return $x * $f / $N;
}
sub fftx
{
my ($x,$au,$v) = @_;
my $n = $au->samples;
my $f = $au->rate;
return $x * $f / $N;
}
sub datax
{
my ($x,$au) = @_;
my $n = $au->samples;
my $f = $au->rate;
return 1000 * $x / $f;
}
sub Audio_image
{
my ($mw,$au,%args) = @_;
my $meth = delete $args{Method};
my $xfunc = delete $args{Xfunc};
my $range = delete $args{Range} || [0,$au->samples-1];
my $class = delete($args{Class}) || 'lines';
my $graph = "GD::Graph::$class"->new(640,240);
$meth ||= 'data';
$graph->set(%args);
my @data = $au->$meth(@$range);
my $n = @data;
my @x = (0..$n-1);
if (defined $xfunc)
{
foreach my $x (@x)
{
$x = &$xfunc($x,$au,$data[$x]);
}
}
my $gd = $graph->plot([\@x,\@data]);
my $file = "temp$$.png";
open(IMG, ">$file") or die "Cannot open $file:$!";
binmode IMG;
print IMG $gd->png;
close IMG;
my $img = $mw->Photo(-format => 'png', -file => $file);
unlink($file);
return $img;
}
( run in 1.358 second using v1.01-cache-2.11-cpan-df04353d9ac )