I know that PDL can do FFT.....The remained problem is: how can I get the time-amplitude data as the input of FFT

You probably want the Audio::DSP module. Here is an example of pulling the audio bits right off of the capture device of the soundcard's playback device.

#!/usr/bin/perl use Audio::DSP; #alsamixer must be setup right, just turn everything up :-) ($buf, $chan, $fmt, $rate) = (4096, 1, 16, 22050); # $fmt=8 will work, but it's better to use the formats in soundcard. +h # some soundcards won't like 8-bit sound, or may need to be re-initial +ized $dsp = new Audio::DSP(buffer => $buf, channels => $chan, format => $fmt, rate => $rate); $dsp->init() || die $dsp->errstr(); open(OUT, ">out.raw") or warn $!; while ( $buffer = $dsp->dread(4096) ) { print OUT $buffer; } $dsp->close(); # to convert to wave # sox -r 8000 -u -b -c 1 out.raw out.wav
You will then have the raw audio data, which you will have to separate out into individaul audio bytes by channels, format and rate.

It is not simple code, to put audio onto a canvas, have a cursor select a section, determine the actual seek positions for begin and end in the audio file, then feed that to FFT.

To compound the problem, Perl is much slower than C for doing numerical computations, so you probably want a module that does the FFT thru a C based xs based module.

Even to plot the audio on a canvas, requires some intensive calculations to read the audio file, byte by audio byte. See Zero sound detection with Tk graphics and Tk-applause-meter


I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

In reply to Re: Music and FFT by zentara
in thread Music and FFT by llancet

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.