Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: help in mp2 gain (scalefactor)! (Read 4159 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

help in mp2 gain (scalefactor)!

Hey
How r u?
I'm trying to change the volume to mpeg 1 layer 2 file in transport stream format
I need some code that helps me change the scale factor of each sub band.
so please if you can send me the formula or code to review.
(The main problem is to understand how to change the scale factor in bits from the iso table)
Thank you.

alon

help in mp2 gain (scalefactor)!

Reply #1
If I remember correctly, I've never been able to change the volume of an mp2 file with any mp3 utilities. (With mp1 files, you can change the volume using mp3gain and other programs if you "trick" the program by changing the extension to .mp3, then altering the volume, then change the extension back to mp1.)

What I do with thew few mp2 files I have is write replaygain tags using foobar, and then just play them in an mp3gain-compatible player (e.g., foobar).

But if there's a good answer to your question, I'd like to know it.
God kills a kitten every time you encode with CBR 320

help in mp2 gain (scalefactor)!

Reply #2
You could ask DSPguru if he gives his code to you. Otherwise you will have to read the Layer II section of ISO11172-3.

see here
Edit: ouch! this is a thread started by you!

I also have very old code that reads MP2 and decodes it down until the scalefactors. It is for IBM C for OS/2, written 1993 so I will not give you any help (because everything is forgotten now!). It is not optimized in any way and comments are in german 

help in mp2 gain (scalefactor)!

Reply #3
I asked DSPguru but did not get any reply from him.

I read the ISO file but did not understand how 6 bit can contain the numbers that the

ISO11172-3. table of scalefactor have .

Please help!!!

Alon

help in mp2 gain (scalefactor)!

Reply #4
Quote
I read the ISO file but did not understand how 6 bit can contain the numbers that the
ISO11172-3. table of scalefactor have .
[a href=\"index.php?act=findpost&pid=326973\"][{POST_SNAPBACK}][/a]

Hi!

you have to calculate the values.

Here is how I did it:
Code: [Select]
double  Tbl_ScalFact[63];       /* Skalenfaktoren Layer I und II                        */

void init_ScalFact()
  {
  int          i;
  double        Wurzel;

  Wurzel = pow (2.0, (1.0/3.0));  /* die dritte Wurzel aus zwei (1.2599210 usw. ) */
  Tbl_ScalFact[0] = 2.0;
  for (i=1; i<63; i++)
    {
    Tbl_ScalFact[i] = Tbl_ScalFact[i-1] / Wurzel;
    }

  }    /* init_Scalfact        */

help in mp2 gain (scalefactor)!

Reply #5
Quote
I read the ISO file but did not understand how 6 bit can contain the numbers that the ISO11172-3. table of scalefactor have .

The answer is:
Quote
Scalefactor decoding
For every subband with a nonzero bit allocation the coded scalefactor for that subband are read from the bitstream. The number of coded scalefactors and the part of the subband samples they refer to is defined by scfsi[sb]. The 6 bits of a coded scalefactor should be interpreted as an unsigned integer index to 3-Annex B, Table 3-B.1 "LAYER I, II SCALEFACTORS". This table gives the scalefactor by which the relevant subband samples should be multiplied after requantization.

So, if you write a program that modifies the coded (6bit) scalefactors in the bitstream you have to keep in mind that table of scalefactors which is part of the decoder.

The conclusions for your program are:

-all scalefactors of a frame must be modified (added or subtracted) by the same amount
-to increase the volume of the decoded samples, you have to decrease the coded (6bit) scalefactors (and vice versa)
-the changes can be applied in discrete steps only (integer n), which result in a factor of 2^(-n/3)

-example: add n=1  ->  factor=2^(-1/3)=0,7937  (volume decrease)
-example: add n=-1  ->  factor=2^(1/3)=1,2599  (volume increase)
-example: add n=-4  ->  factor=2^(4/3)=2,5198  (volume increase)

Hope this helps a bit.