Get an MP3 stream.

Jul 26, 2011 at 5:34 PM

Hi,

I want to do a Vu metre.
For that I need the value of each point of the MP3 stream.

My problem is, I don't find how I can get these value. When I read my stream it always the WAV value.

Do you know how I have to do to get the MP3 values ?

Thanks,
Golvet.

Jul 27, 2011 at 8:36 AM
Edited Jul 27, 2011 at 8:38 AM

To add more details :

At work, people used SoundForge to see if the conversion WAV => MP3 have been done correctly.

If the gain of the MP3 file is upper than -6dB the file is bad.

The problem is the WAV file have data between 0 and 255. thats not the case of the MP3 file. (the curve don't have an amplitude of 1).
When I read the MP3 file I obtain the WAV stream and not the MP3 one.

I need to analyse directly the MP3 data, can I get it ?

 

 

Sorry to insist... I'm on this code since more than one week... (and I haven't do anything useful...)

Coordinator
Jul 27, 2011 at 8:48 AM

MP3 is a compressed format. You need to convert to 16 bit PCM samples to measure the amplitude

Jul 27, 2011 at 9:10 AM

the problem is,
when I read the stream, the value are between 0 and 255. And so the gain is from -Inf to 0dB.
The stream don't care about the gain written in the tag of MP3 file.

 

A part of my code :

            NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(namefile));
            stream = new NAudio.Wave.BlockAlignReductionStream(pcm);
            

            ifin = (int)stream.Length;

            Array.Resize(ref musique, 256);

            while (stream.Position <= stream.Length)
            {
                i = stream.Position;
                musique[stream.ReadByte()+1]++;

            }

            for (int i = 0; i < 260; i++)
                Console.WriteLine("{0} \t {1}", (i-1), musique[i]);

Coordinator
Jul 27, 2011 at 9:12 AM

You cannot get the gain by looking at individual bytes. This is simply not how digital audio works.

Jul 27, 2011 at 9:21 AM

Oops... :s


How can I have It ?
(I try to have the amplitude of each point because when I open soundforge the gain is upper than -6 dB when the curve have a big amplitude)

I have seen a Vu metre on one of Naudio sample. (but I don't find where he is in the source code)

Thanks for the answer.

Coordinator
Jul 28, 2011 at 9:16 AM

The way the volume meter works is by examining the value of each sample. Look in the NAudio sample code for the SampleAggregator class to see how it works.

Mark