mad-dev-request@lists.mars.org wrote:
Message: 1 Date: Wed, 30 Jul 2003 16:56:15 -0700 (PDT) From: Shiming Dong dong_sm@yahoo.com To: mad-dev@lists.mars.org Subject: [mad-dev] How to know the frequency of a frame
--0-1603577723-1059609375=:7610 Content-Type: text/plain; charset=us-ascii
Hi there:
I have one question: I was supposed to implement a program to detect a specific marker tone. But my problem is how to know the frequency of each frame?
Thank you!
shiming
I guess you mean the samplerate? For instance 44,1kHz. In that case it is easy. Once you have decoded a frame, at some point you will synthesise it to PCM samples.
struct mad_frame myFrame ; struct mad_synth mySynth ;
[...lots of code...]
mad_synth_frame( &mySynth, &myFrame ) ;
After that mySynth.pcm.samplerate will contain the samplerate. For instance 44100 for 44,1kHz.
Regards,
Armin
But I found the samplerate for all the frames are the same. And I think for each frame the frequency, which is the X-axis value of visualized mp3 player for each tone will be different. (When you use mp3 player to play a CD, the X-axis displays the frequency and the Y-axis is the volume I think. I want to know the X-axis value for each frame. )How do I get this information?
Thank you!
shiming --- armin.gerritsen@philips.com wrote:
mad-dev-request@lists.mars.org wrote:
Message: 1 Date: Wed, 30 Jul 2003 16:56:15 -0700 (PDT) From: Shiming Dong dong_sm@yahoo.com To: mad-dev@lists.mars.org Subject: [mad-dev] How to know the frequency of a
frame
--0-1603577723-1059609375=:7610 Content-Type: text/plain; charset=us-ascii
Hi there:
I have one question: I was supposed to implement a
program to detect
a specific marker tone. But my problem is how to
know the frequency
of each frame?
Thank you!
shiming
I guess you mean the samplerate? For instance 44,1kHz. In that case it is easy. Once you have decoded a frame, at some point you will synthesise it to PCM samples.
struct mad_frame myFrame ; struct mad_synth mySynth ;
[...lots of code...]
mad_synth_frame( &mySynth, &myFrame ) ;
After that mySynth.pcm.samplerate will contain the samplerate. For instance 44100 for 44,1kHz.
Regards,
Armin
__________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com
Mp3s store information based on frequencies, instead of time. That is, instead of an x-axis of time, there is an x-axis of frequency -- like you are saying. However, it has been pointed out here on this list that while this data is available from libmad, you will get somewhat inaccurate results (that is, mp3s do not store the exact frequencies).
What you probably want to do is a fourier transform on the result of decoding the mp3 (that is a pcm or wav file). A fourier transform takes data in the time domain and brings it to the frequency domain (like you want). Take a look at the fftw library (fastest fourier transform in the west).
My player utilizes this for it's spectrum meter, you can take a look at it's source code at sv.gnu.org, the project name is 'squash'. It's not 1.0 code yet, and there are several thousand lines, but what you want to look in is play_mp3.c (to see how to use libmad to decode things), and also in spectrum.c (to see how to use fftw to transfrom pcm data into a spectrum bitmap).
Hope this helps.
-Adam Luter (Gryn)
On Fri, Aug 01, 2003 at 02:16:26PM -0700, Shiming Dong wrote:
But I found the samplerate for all the frames are the same. And I think for each frame the frequency, which is the X-axis value of visualized mp3 player for each tone will be different. (When you use mp3 player to play a CD, the X-axis displays the frequency and the Y-axis is the volume I think. I want to know the X-axis value for each frame. )How do I get this information?
Thank you!
shiming