in reply to Music and FFT

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

Replies are listed 'Best First'.
Re^2: Music and FFT
by llancet (Friar) on Oct 20, 2010 at 04:53 UTC
    It seems /dev/dsp is required. However it seems that /dev/dsp is provided by a legancy kernel module named oss. What about alsa?
    I don't have much knowledge about linux sound architecture, is there any introduction materials?
      Google for "linux sound tutorial". Basically, OSS was the original sound system, which now has been replaced by alsa( which has a oss emulation layer for backward compatibility). Alsa is the low level device driver. There are even higher level sound daemons in use now. For instance, Ubuntu uses the Enlightenment sound daemon, which acts as a sound server, on top of alsa. Alsa is usually built into the kernel modules, and gives basic access to the DSP, speaker, microphone, etc. There is a set of basic alsa utilities, like aplay, arecord, amixer, and alsactl, with which you can use to control the /dev/dsp.

      It would seem to be simple, but sound can be complex with all the options available, like Jack, etc.

      If you want one good commandline tool for conversions on linux, see Sox


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