Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Compare wav files

by tobyink (Abbot)
on Apr 17, 2012 at 12:41 UTC ( #965502=note: print w/replies, xml ) Need Help??

in reply to Compare wav files

use 5.010; use Audio::Wav; my $file1 = Audio::Wav->read("file1.wav"); my $file2 = Audio::Wav->read("file2.wav"); say "Files same length (in seconds)" if $file1->length_seconds == $file2->length_seconds; say "Files same sample rate" if $file1->details->{sample_rate} == $file2->details->{sample_rate};
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Replies are listed 'Best First'.
Re^2: Compare wav files
by asha_mail (Novice) on Apr 17, 2012 at 13:04 UTC

    How to find the frequency of both .wav files? Comparing the frequency.

      I'm assuming you are tackling the slightly trickier problem of finding individual sound frequencies within the .wav file.

      To do this you will have to unpack the time domain data in the .wav (which you can do using Audio::Wav::Read or unpack) and then perform a Fourier transform to get this data into the frequency domain (Math::FFT). I recommend reading up on DSP a bit to learn the theory.

      You might also try Audio::Analyzer =)

        Suppose I have two .wav files having same sound but different pitch(one sound taken from near the mic and same sound from keeping the mic far away). So how can I identify at what second the sound has been produced?

        Will both the wav sound be having same sample rate?

      What do you mean by "frequency"? The frequency of the sound waves, or the sample frequency (a.k.a. sample rate)? If the latter, that's shown in my example.

      If you mean the frequency of the sound wave, that's a more complex matter. Most non-trivial audio files will contain sounds of many different frequencies. Even something simple like a violin playing a single long note will have a complex range of harmonics layered on top of the base note. Only things like sine wave generators will generate a single frequency.

      perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
      They call it sample rate, not frequency

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://965502]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2017-06-27 03:57 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (598 votes). Check out past polls.