HydrogenAudio

Lossy Audio Compression => Other Lossy Codecs => Topic started by: alonsag on 2005-09-14 15:40:39

Title: help in mp2 gain (scalefactor)!
Post by: alonsag on 2005-09-14 15:40:39
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
Title: help in mp2 gain (scalefactor)!
Post by: timcupery on 2005-09-14 16:42:45
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.
Title: help in mp2 gain (scalefactor)!
Post by: Sunhillow on 2005-09-14 20:10:05
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 (http://www.hydrogenaudio.org/forums/index.php?showtopic=35930)
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 
Title: help in mp2 gain (scalefactor)!
Post by: alonsag on 2005-09-15 09:29:30
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
Title: help in mp2 gain (scalefactor)!
Post by: Sunhillow on 2005-09-15 11:24:37
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        */
Title: help in mp2 gain (scalefactor)!
Post by: smack on 2005-09-15 14:19:01
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.