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: MPEG Audio Layer 2 (Read 4041 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

MPEG Audio Layer 2

I´m trying to code a tool which is able to remove one channel from a stereo file without reencoding. The output file should be an joint-stereo file at the same bitrate. My idea is to remove one channel, couple as much subbands as possible (0-16) and copy all left data. Unfortunately the ISO specs are very confusing, same as the dist10 code, but that´s what I could find out:

header (32 Bit)
bit allocation - channel/subband (?)
scfsi - channel/subband (2 Bit each)
scalefactor - channel/subband (6 Bit each)
samples - channel/subband (?)

allocation table:
MPEG-1:
0 = samplerate = 48 and bitrate/ch >= 56 (sblimit 27)
or bitrate/ch >= 56 and <= 80
1 = samplerate not 48 and bitrate/ch >= 96 (sblimit 30)
2 = samplerate not 32 and bitrate/ch <= 48 (sblimit 8)
else 3 (sblimit 12)

MPEG-2:
always 4 (sblimit 30)

My question are:
-Bit allocation: this part contains information how the subbands are compressed, right? The size is different for each subband and can be read somehow from the allocation tables, right? It is stored channel[0]/subband[0], channel[0]/subband[1] .... channel[1]/subband[sblimit]. How is it stored for joint-stereo? The first channel normal and then only not-coupled subbands, or the the couples at the beginning and then the first channel, second channel? Also how to interpret the values? It can be that some subbands are not stored, so I now have to work with a new sblimit for each channel, right?
-scfsi: This values are fixed to 2 bits, how they stored with joint stereo (same question as for bit allocation). I now have to work with new sblimit?
-scalefac: Same questions as for scfsi
-samples: This is most difficult part, I don´t anything about that. I need to know how many values are stored, how and at what size.

Is there already something wrong in what I found out? can someone please help me? Thank you very much!

MPEG Audio Layer 2

Reply #1
Because editing long posts doesn´t work correctly, I post my additions in a new one:
I found out:
One frame contains 3x 12 samples (1 sample = 32 PCM samples), 3*12*32=1152
The 12-sample-blocks can have the same scalefactor or different, this can be read from scfsi (how?).
Bit reservoir can also be used in Layer 2 I found out, I also need information how that exactly works.

Edit:

What I read was wrong, Layer 2 has no bit reservoir.

scfsi (one part = 12 samples):
00 - 3 scalefactors, for each part one.
01 - 2 scalefactors, first for part 1 and 2, second for 3
10 - 1 scalefactor for all parts
11 - 2 scalefactors, first for part 1, second for 2 and 3.

Also I read differnet things now, with intensity stereo are the lower subbands coupled or the higher? Also I know the scfsi/scalefactors can be differnt, also the subbands are coupled, so scfsi/scalefactors are stored completly for all channels/subbands up to sblimit, but bit-allocation is not.

Can I download the source of mp2gain (part of besplit) somewhere? I think these sources contain a mp2 data parser and could help me very much.

MPEG Audio Layer 2

Reply #2
S_O contacted me via PM and paid my attention to his idea, so i decided to add this feature to BeSplit.

warning : i really don't have the time to debug these days, as so i only tested my work with a single mp2 file (dual channel, 224kbps, no error protection), but it seems to work OK.

commandline :
BeSplit -core( -input [infile.mp2] -prefix [outfile] -logfile [BeSplit.txt] -type mp2 -demux )

this will create two files :
outfile-L.mp2
outfile-R.mp2


Dg.



edit : typo

 

MPEG Audio Layer 2

Reply #3
I also have coded my tool:
Can extract one channel from dual-channel, stereo and joint-stereo files. It outputs a mono file at the same bitrate when source is joint-stereo/stereo, so it only works if both bitrate/channel have the same allocation table. This works on  bitrates like 192kbps, but not on 224kbps (because 224kbps mono is not allowed). At 32/44,1 kHz only 192kbps is supported, at 48kHz 128-192kbps is supported.
At mpeg-2 all bitrates should be supported. With dual-channel input bitrate get reduced to the next higher bitrate after half (exactly the half is not enough, because the header still takes 4 byte).

Im going to improve my tool:
-Support vbr output finished
-Support cbr output at lowest possible bitrate (2-pass)
-Support fake-stereo output (for 224kbps "mono" output) finished
-Reallocation: table B is 100% compatible to A for example, so it is possible to output B, also A is input. This should add support for other bitrates. finished

Download 0.13 beta here (45KB): mp2chext_013.zip

@DSPguru: I´ve tested your tool, but for my test file it doesn´t work. Both output files are not playable in wmp and in madplay reports lot´s of sync errors, most frames are skipped.
Possible explanation: The half bitrate is not enough, the frames are incomplete.
Possible explanation 2: Padding is not read/written correctly, the framesize is different from the indicated.

Edit: Updated version