Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
lDEVinux
GitHub Repository: lDEVinux/eaglercraft
Path: blob/main/src/lwjgl/java/javazoom/jl/decoder/Header.java
8650 views
1
/*
2
* 11/19/04 : 1.0 moved to LGPL.
3
* VBRI header support added, E.B [email protected]
4
*
5
* 12/04/03 : VBR (XING) header support added, E.B [email protected]
6
*
7
* 02/13/99 : Java Conversion by JavaZOOM , E.B [email protected]
8
*
9
* Declarations for MPEG header class
10
* A few layer III, MPEG-2 LSF, and seeking modifications made by Jeff Tsay.
11
* Last modified : 04/19/97
12
*
13
* @(#) header.h 1.7, last edit: 6/15/94 16:55:33
14
* @(#) Copyright (C) 1993, 1994 Tobias Bading ([email protected])
15
* @(#) Berlin University of Technology
16
*-----------------------------------------------------------------------
17
* This program is free software; you can redistribute it and/or modify
18
* it under the terms of the GNU Library General Public License as published
19
* by the Free Software Foundation; either version 2 of the License, or
20
* (at your option) any later version.
21
*
22
* This program is distributed in the hope that it will be useful,
23
* but WITHOUT ANY WARRANTY; without even the implied warranty of
24
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
* GNU Library General Public License for more details.
26
*
27
* You should have received a copy of the GNU Library General Public
28
* License along with this program; if not, write to the Free Software
29
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30
*----------------------------------------------------------------------
31
*/
32
package javazoom.jl.decoder;
33
34
/**
35
* Class for extracting information from a frame header.
36
*/
37
public final class Header
38
{
39
public static final int[][] frequencies =
40
{{22050, 24000, 16000, 1},
41
{44100, 48000, 32000, 1},
42
{11025, 12000, 8000, 1}}; // SZD: MPEG25
43
44
/**
45
* Constant for MPEG-2 LSF version
46
*/
47
public static final int MPEG2_LSF = 0;
48
public static final int MPEG25_LSF = 2; // SZD
49
50
/**
51
* Constant for MPEG-1 version
52
*/
53
public static final int MPEG1 = 1;
54
55
public static final int STEREO = 0;
56
public static final int JOINT_STEREO = 1;
57
public static final int DUAL_CHANNEL = 2;
58
public static final int SINGLE_CHANNEL = 3;
59
public static final int FOURTYFOUR_POINT_ONE = 0;
60
public static final int FOURTYEIGHT=1;
61
public static final int THIRTYTWO=2;
62
63
private int h_layer, h_protection_bit, h_bitrate_index,
64
h_padding_bit, h_mode_extension;
65
private int h_version;
66
private int h_mode;
67
private int h_sample_frequency;
68
private int h_number_of_subbands, h_intensity_stereo_bound;
69
private boolean h_copyright, h_original;
70
// VBR support added by E.B
71
private double[] h_vbr_time_per_frame = {-1, 384, 1152, 1152};
72
private boolean h_vbr;
73
private int h_vbr_frames;
74
private int h_vbr_scale;
75
private int h_vbr_bytes;
76
private byte[] h_vbr_toc;
77
78
private byte syncmode = Bitstream.INITIAL_SYNC;
79
private Crc16 crc;
80
81
public short checksum;
82
public int framesize;
83
public int nSlots;
84
85
private int _headerstring = -1; // E.B
86
87
Header()
88
{
89
}
90
public String toString()
91
{
92
StringBuilder buffer = new StringBuilder(200);
93
buffer.append("Layer ");
94
buffer.append(layer_string());
95
buffer.append(" frame ");
96
buffer.append(mode_string());
97
buffer.append(' ');
98
buffer.append(version_string());
99
if (!checksums())
100
buffer.append(" no");
101
buffer.append(" checksums");
102
buffer.append(' ');
103
buffer.append(sample_frequency_string());
104
buffer.append(',');
105
buffer.append(' ');
106
buffer.append(bitrate_string());
107
108
String s = buffer.toString();
109
return s;
110
}
111
112
/**
113
* Read a 32-bit header from the bitstream.
114
*/
115
void read_header(Bitstream stream, Crc16[] crcp) throws BitstreamException
116
{
117
int headerstring;
118
int channel_bitrate;
119
boolean sync = false;
120
do
121
{
122
headerstring = stream.syncHeader(syncmode);
123
_headerstring = headerstring; // E.B
124
if (syncmode == Bitstream.INITIAL_SYNC)
125
{
126
h_version = ((headerstring >>> 19) & 1);
127
if (((headerstring >>> 20) & 1) == 0) // SZD: MPEG2.5 detection
128
if (h_version == MPEG2_LSF)
129
h_version = MPEG25_LSF;
130
else
131
throw stream.newBitstreamException(Bitstream.UNKNOWN_ERROR);
132
if ((h_sample_frequency = ((headerstring >>> 10) & 3)) == 3)
133
{
134
throw stream.newBitstreamException(Bitstream.UNKNOWN_ERROR);
135
}
136
}
137
h_layer = 4 - (headerstring >>> 17) & 3;
138
h_protection_bit = (headerstring >>> 16) & 1;
139
h_bitrate_index = (headerstring >>> 12) & 0xF;
140
h_padding_bit = (headerstring >>> 9) & 1;
141
h_mode = ((headerstring >>> 6) & 3);
142
h_mode_extension = (headerstring >>> 4) & 3;
143
if (h_mode == JOINT_STEREO)
144
h_intensity_stereo_bound = (h_mode_extension << 2) + 4;
145
else
146
h_intensity_stereo_bound = 0; // should never be used
147
if (((headerstring >>> 3) & 1) == 1)
148
h_copyright = true;
149
if (((headerstring >>> 2) & 1) == 1)
150
h_original = true;
151
// calculate number of subbands:
152
if (h_layer == 1)
153
h_number_of_subbands = 32;
154
else
155
{
156
channel_bitrate = h_bitrate_index;
157
// calculate bitrate per channel:
158
if (h_mode != SINGLE_CHANNEL)
159
if (channel_bitrate == 4)
160
channel_bitrate = 1;
161
else
162
channel_bitrate -= 4;
163
if ((channel_bitrate == 1) || (channel_bitrate == 2))
164
if (h_sample_frequency == THIRTYTWO)
165
h_number_of_subbands = 12;
166
else
167
h_number_of_subbands = 8;
168
else if ((h_sample_frequency == FOURTYEIGHT) || ((channel_bitrate >= 3) && (channel_bitrate <= 5)))
169
h_number_of_subbands = 27;
170
else
171
h_number_of_subbands = 30;
172
}
173
if (h_intensity_stereo_bound > h_number_of_subbands)
174
h_intensity_stereo_bound = h_number_of_subbands;
175
// calculate framesize and nSlots
176
calculate_framesize();
177
// read framedata:
178
int framesizeloaded = stream.read_frame_data(framesize);
179
if ((framesize >=0) && (framesizeloaded != framesize))
180
{
181
// Data loaded does not match to expected framesize,
182
// it might be an ID3v1 TAG. (Fix 11/17/04).
183
throw stream.newBitstreamException(Bitstream.INVALIDFRAME);
184
}
185
if (stream.isSyncCurrentPosition(syncmode))
186
{
187
if (syncmode == Bitstream.INITIAL_SYNC)
188
{
189
syncmode = Bitstream.STRICT_SYNC;
190
stream.set_syncword(headerstring & 0xFFF80CC0);
191
}
192
sync = true;
193
}
194
else
195
{
196
stream.unreadFrame();
197
}
198
}
199
while (!sync);
200
stream.parse_frame();
201
if (h_protection_bit == 0)
202
{
203
// frame contains a crc checksum
204
checksum = (short) stream.get_bits(16);
205
if (crc == null)
206
crc = new Crc16();
207
crc.add_bits(headerstring, 16);
208
crcp[0] = crc;
209
}
210
else
211
crcp[0] = null;
212
if (h_sample_frequency == FOURTYFOUR_POINT_ONE)
213
{
214
/*
215
if (offset == null)
216
{
217
int max = max_number_of_frames(stream);
218
offset = new int[max];
219
for(int i=0; i<max; i++) offset[i] = 0;
220
}
221
// E.B : Investigate more
222
int cf = stream.current_frame();
223
int lf = stream.last_frame();
224
if ((cf > 0) && (cf == lf))
225
{
226
offset[cf] = offset[cf-1] + h_padding_bit;
227
}
228
else
229
{
230
offset[0] = h_padding_bit;
231
}
232
*/
233
}
234
}
235
236
/**
237
* Parse frame to extract optional VBR frame.
238
*
239
* @param firstframe
240
* @author E.B ([email protected])
241
*/
242
void parseVBR(byte[] firstframe) throws BitstreamException
243
{
244
// Trying Xing header.
245
String xing = "Xing";
246
byte tmp[] = new byte[4];
247
int offset = 0;
248
// Compute "Xing" offset depending on MPEG version and channels.
249
if (h_version == MPEG1)
250
{
251
if (h_mode == SINGLE_CHANNEL) offset=21-4;
252
else offset=36-4;
253
}
254
else
255
{
256
if (h_mode == SINGLE_CHANNEL) offset=13-4;
257
else offset = 21-4;
258
}
259
try
260
{
261
System.arraycopy(firstframe, offset, tmp, 0, 4);
262
// Is "Xing" ?
263
if (xing.equals(new String(tmp)))
264
{
265
//Yes.
266
h_vbr = true;
267
h_vbr_frames = -1;
268
h_vbr_bytes = -1;
269
h_vbr_scale = -1;
270
h_vbr_toc = new byte[100];
271
272
int length = 4;
273
// Read flags.
274
byte flags[] = new byte[4];
275
System.arraycopy(firstframe, offset + length, flags, 0, flags.length);
276
length += flags.length;
277
// Read number of frames (if available).
278
if ((flags[3] & (byte) (1 << 0)) != 0)
279
{
280
System.arraycopy(firstframe, offset + length, tmp, 0, tmp.length);
281
h_vbr_frames = (tmp[0] << 24)&0xFF000000 | (tmp[1] << 16)&0x00FF0000 | (tmp[2] << 8)&0x0000FF00 | tmp[3]&0x000000FF;
282
length += 4;
283
}
284
// Read size (if available).
285
if ((flags[3] & (byte) (1 << 1)) != 0)
286
{
287
System.arraycopy(firstframe, offset + length, tmp, 0, tmp.length);
288
h_vbr_bytes = (tmp[0] << 24)&0xFF000000 | (tmp[1] << 16)&0x00FF0000 | (tmp[2] << 8)&0x0000FF00 | tmp[3]&0x000000FF;
289
length += 4;
290
}
291
// Read TOC (if available).
292
if ((flags[3] & (byte) (1 << 2)) != 0)
293
{
294
System.arraycopy(firstframe, offset + length, h_vbr_toc, 0, h_vbr_toc.length);
295
length += h_vbr_toc.length;
296
}
297
// Read scale (if available).
298
if ((flags[3] & (byte) (1 << 3)) != 0)
299
{
300
System.arraycopy(firstframe, offset + length, tmp, 0, tmp.length);
301
h_vbr_scale = (tmp[0] << 24)&0xFF000000 | (tmp[1] << 16)&0x00FF0000 | (tmp[2] << 8)&0x0000FF00 | tmp[3]&0x000000FF;
302
length += 4;
303
}
304
//System.out.println("VBR:"+xing+" Frames:"+ h_vbr_frames +" Size:"+h_vbr_bytes);
305
}
306
}
307
catch (ArrayIndexOutOfBoundsException e)
308
{
309
throw new BitstreamException("XingVBRHeader Corrupted",e);
310
}
311
312
// Trying VBRI header.
313
String vbri = "VBRI";
314
offset = 36-4;
315
try
316
{
317
System.arraycopy(firstframe, offset, tmp, 0, 4);
318
// Is "VBRI" ?
319
if (vbri.equals(new String(tmp)))
320
{
321
//Yes.
322
h_vbr = true;
323
h_vbr_frames = -1;
324
h_vbr_bytes = -1;
325
h_vbr_scale = -1;
326
h_vbr_toc = new byte[100];
327
// Bytes.
328
int length = 4 + 6;
329
System.arraycopy(firstframe, offset + length, tmp, 0, tmp.length);
330
h_vbr_bytes = (tmp[0] << 24)&0xFF000000 | (tmp[1] << 16)&0x00FF0000 | (tmp[2] << 8)&0x0000FF00 | tmp[3]&0x000000FF;
331
length += 4;
332
// Frames.
333
System.arraycopy(firstframe, offset + length, tmp, 0, tmp.length);
334
h_vbr_frames = (tmp[0] << 24)&0xFF000000 | (tmp[1] << 16)&0x00FF0000 | (tmp[2] << 8)&0x0000FF00 | tmp[3]&0x000000FF;
335
length += 4;
336
//System.out.println("VBR:"+vbri+" Frames:"+ h_vbr_frames +" Size:"+h_vbr_bytes);
337
// TOC
338
// TODO
339
}
340
}
341
catch (ArrayIndexOutOfBoundsException e)
342
{
343
throw new BitstreamException("VBRIVBRHeader Corrupted",e);
344
}
345
}
346
347
// Functions to query header contents:
348
/**
349
* Returns version.
350
*/
351
public int version() { return h_version; }
352
353
/**
354
* Returns Layer ID.
355
*/
356
public int layer() { return h_layer; }
357
358
/**
359
* Returns bitrate index.
360
*/
361
public int bitrate_index() { return h_bitrate_index; }
362
363
/**
364
* Returns Sample Frequency.
365
*/
366
public int sample_frequency() { return h_sample_frequency; }
367
368
/**
369
* Returns Frequency.
370
*/
371
public int frequency() {return frequencies[h_version][h_sample_frequency];}
372
373
/**
374
* Returns Mode.
375
*/
376
public int mode() { return h_mode; }
377
378
/**
379
* Returns Protection bit.
380
*/
381
public boolean checksums()
382
{
383
if (h_protection_bit == 0) return true;
384
else return false;
385
}
386
387
/**
388
* Returns Copyright.
389
*/
390
public boolean copyright() { return h_copyright; }
391
392
/**
393
* Returns Original.
394
*/
395
public boolean original() { return h_original; }
396
397
/**
398
* Return VBR.
399
*
400
* @return true if VBR header is found
401
*/
402
public boolean vbr() { return h_vbr; }
403
404
/**
405
* Return VBR scale.
406
*
407
* @return scale of -1 if not available
408
*/
409
public int vbr_scale() { return h_vbr_scale; }
410
411
/**
412
* Return VBR TOC.
413
*
414
* @return vbr toc ot null if not available
415
*/
416
public byte[] vbr_toc() { return h_vbr_toc; }
417
418
/**
419
* Returns Checksum flag.
420
* Compares computed checksum with stream checksum.
421
*/
422
public boolean checksum_ok () { return (checksum == crc.checksum()); }
423
424
// Seeking and layer III stuff
425
/**
426
* Returns Layer III Padding bit.
427
*/
428
public boolean padding()
429
{
430
if (h_padding_bit == 0) return false;
431
else return true;
432
}
433
434
/**
435
* Returns Slots.
436
*/
437
public int slots() { return nSlots; }
438
439
/**
440
* Returns Mode Extension.
441
*/
442
public int mode_extension() { return h_mode_extension; }
443
444
// E.B -> private to public
445
public static final int bitrates[][][] = {
446
{{0 /*free format*/, 32000, 48000, 56000, 64000, 80000, 96000,
447
112000, 128000, 144000, 160000, 176000, 192000 ,224000, 256000, 0},
448
{0 /*free format*/, 8000, 16000, 24000, 32000, 40000, 48000,
449
56000, 64000, 80000, 96000, 112000, 128000, 144000, 160000, 0},
450
{0 /*free format*/, 8000, 16000, 24000, 32000, 40000, 48000,
451
56000, 64000, 80000, 96000, 112000, 128000, 144000, 160000, 0}},
452
453
{{0 /*free format*/, 32000, 64000, 96000, 128000, 160000, 192000,
454
224000, 256000, 288000, 320000, 352000, 384000, 416000, 448000, 0},
455
{0 /*free format*/, 32000, 48000, 56000, 64000, 80000, 96000,
456
112000, 128000, 160000, 192000, 224000, 256000, 320000, 384000, 0},
457
{0 /*free format*/, 32000, 40000, 48000, 56000, 64000, 80000,
458
96000, 112000, 128000, 160000, 192000, 224000, 256000, 320000, 0}},
459
// SZD: MPEG2.5
460
{{0 /*free format*/, 32000, 48000, 56000, 64000, 80000, 96000,
461
112000, 128000, 144000, 160000, 176000, 192000 ,224000, 256000, 0},
462
{0 /*free format*/, 8000, 16000, 24000, 32000, 40000, 48000,
463
56000, 64000, 80000, 96000, 112000, 128000, 144000, 160000, 0},
464
{0 /*free format*/, 8000, 16000, 24000, 32000, 40000, 48000,
465
56000, 64000, 80000, 96000, 112000, 128000, 144000, 160000, 0}},
466
467
};
468
469
// E.B -> private to public
470
/**
471
* Calculate Frame size.
472
*
473
* Calculates framesize in bytes excluding header size.
474
*/
475
public int calculate_framesize()
476
{
477
478
if (h_layer == 1)
479
{
480
framesize = (12 * bitrates[h_version][0][h_bitrate_index]) /
481
frequencies[h_version][h_sample_frequency];
482
if (h_padding_bit != 0 ) framesize++;
483
framesize <<= 2; // one slot is 4 bytes long
484
nSlots = 0;
485
}
486
else
487
{
488
framesize = (144 * bitrates[h_version][h_layer - 1][h_bitrate_index]) /
489
frequencies[h_version][h_sample_frequency];
490
if (h_version == MPEG2_LSF || h_version == MPEG25_LSF) framesize >>= 1; // SZD
491
if (h_padding_bit != 0) framesize++;
492
// Layer III slots
493
if (h_layer == 3)
494
{
495
if (h_version == MPEG1)
496
{
497
nSlots = framesize - ((h_mode == SINGLE_CHANNEL) ? 17 : 32) // side info size
498
- ((h_protection_bit!=0) ? 0 : 2) // CRC size
499
- 4; // header size
500
}
501
else
502
{ // MPEG-2 LSF, SZD: MPEG-2.5 LSF
503
nSlots = framesize - ((h_mode == SINGLE_CHANNEL) ? 9 : 17) // side info size
504
- ((h_protection_bit!=0) ? 0 : 2) // CRC size
505
- 4; // header size
506
}
507
}
508
else
509
{
510
nSlots = 0;
511
}
512
}
513
framesize -= 4; // subtract header size
514
return framesize;
515
}
516
517
/**
518
* Returns the maximum number of frames in the stream.
519
*
520
* @param streamsize
521
* @return number of frames
522
*/
523
public int max_number_of_frames(int streamsize) // E.B
524
{
525
if (h_vbr == true) return h_vbr_frames;
526
else
527
{
528
if ((framesize + 4 - h_padding_bit) == 0) return 0;
529
else return(streamsize / (framesize + 4 - h_padding_bit));
530
}
531
}
532
533
/**
534
* Returns the maximum number of frames in the stream.
535
*
536
* @param streamsize
537
* @return number of frames
538
*/
539
public int min_number_of_frames(int streamsize) // E.B
540
{
541
if (h_vbr == true) return h_vbr_frames;
542
else
543
{
544
if ((framesize + 5 - h_padding_bit) == 0) return 0;
545
else return(streamsize / (framesize + 5 - h_padding_bit));
546
}
547
}
548
549
550
/**
551
* Returns ms/frame.
552
*
553
* @return milliseconds per frame
554
*/
555
public float ms_per_frame() // E.B
556
{
557
if (h_vbr == true)
558
{
559
double tpf = h_vbr_time_per_frame[layer()] / frequency();
560
if ((h_version == MPEG2_LSF) || (h_version == MPEG25_LSF)) tpf /= 2;
561
return ((float) (tpf * 1000));
562
}
563
else
564
{
565
float ms_per_frame_array[][] = {{8.707483f, 8.0f, 12.0f},
566
{26.12245f, 24.0f, 36.0f},
567
{26.12245f, 24.0f, 36.0f}};
568
return(ms_per_frame_array[h_layer-1][h_sample_frequency]);
569
}
570
}
571
572
/**
573
* Returns total ms.
574
*
575
* @param streamsize
576
* @return total milliseconds
577
*/
578
public float total_ms(int streamsize) // E.B
579
{
580
return(max_number_of_frames(streamsize) * ms_per_frame());
581
}
582
583
/**
584
* Returns synchronized header.
585
*/
586
public int getSyncHeader() // E.B
587
{
588
return _headerstring;
589
}
590
591
// functions which return header informations as strings:
592
/**
593
* Return Layer version.
594
*/
595
public String layer_string()
596
{
597
switch (h_layer)
598
{
599
case 1:
600
return "I";
601
case 2:
602
return "II";
603
case 3:
604
return "III";
605
}
606
return null;
607
}
608
609
// E.B -> private to public
610
public static final String bitrate_str[][][] = {
611
{{"free format", "32 kbit/s", "48 kbit/s", "56 kbit/s", "64 kbit/s",
612
"80 kbit/s", "96 kbit/s", "112 kbit/s", "128 kbit/s", "144 kbit/s",
613
"160 kbit/s", "176 kbit/s", "192 kbit/s", "224 kbit/s", "256 kbit/s",
614
"forbidden"},
615
{"free format", "8 kbit/s", "16 kbit/s", "24 kbit/s", "32 kbit/s",
616
"40 kbit/s", "48 kbit/s", "56 kbit/s", "64 kbit/s", "80 kbit/s",
617
"96 kbit/s", "112 kbit/s", "128 kbit/s", "144 kbit/s", "160 kbit/s",
618
"forbidden"},
619
{"free format", "8 kbit/s", "16 kbit/s", "24 kbit/s", "32 kbit/s",
620
"40 kbit/s", "48 kbit/s", "56 kbit/s", "64 kbit/s", "80 kbit/s",
621
"96 kbit/s", "112 kbit/s", "128 kbit/s", "144 kbit/s", "160 kbit/s",
622
"forbidden"}},
623
624
{{"free format", "32 kbit/s", "64 kbit/s", "96 kbit/s", "128 kbit/s",
625
"160 kbit/s", "192 kbit/s", "224 kbit/s", "256 kbit/s", "288 kbit/s",
626
"320 kbit/s", "352 kbit/s", "384 kbit/s", "416 kbit/s", "448 kbit/s",
627
"forbidden"},
628
{"free format", "32 kbit/s", "48 kbit/s", "56 kbit/s", "64 kbit/s",
629
"80 kbit/s", "96 kbit/s", "112 kbit/s", "128 kbit/s", "160 kbit/s",
630
"192 kbit/s", "224 kbit/s", "256 kbit/s", "320 kbit/s", "384 kbit/s",
631
"forbidden"},
632
{"free format", "32 kbit/s", "40 kbit/s", "48 kbit/s", "56 kbit/s",
633
"64 kbit/s", "80 kbit/s" , "96 kbit/s", "112 kbit/s", "128 kbit/s",
634
"160 kbit/s", "192 kbit/s", "224 kbit/s", "256 kbit/s", "320 kbit/s",
635
"forbidden"}},
636
// SZD: MPEG2.5
637
{{"free format", "32 kbit/s", "48 kbit/s", "56 kbit/s", "64 kbit/s",
638
"80 kbit/s", "96 kbit/s", "112 kbit/s", "128 kbit/s", "144 kbit/s",
639
"160 kbit/s", "176 kbit/s", "192 kbit/s", "224 kbit/s", "256 kbit/s",
640
"forbidden"},
641
{"free format", "8 kbit/s", "16 kbit/s", "24 kbit/s", "32 kbit/s",
642
"40 kbit/s", "48 kbit/s", "56 kbit/s", "64 kbit/s", "80 kbit/s",
643
"96 kbit/s", "112 kbit/s", "128 kbit/s", "144 kbit/s", "160 kbit/s",
644
"forbidden"},
645
{"free format", "8 kbit/s", "16 kbit/s", "24 kbit/s", "32 kbit/s",
646
"40 kbit/s", "48 kbit/s", "56 kbit/s", "64 kbit/s", "80 kbit/s",
647
"96 kbit/s", "112 kbit/s", "128 kbit/s", "144 kbit/s", "160 kbit/s",
648
"forbidden"}},
649
};
650
651
/**
652
* Return Bitrate.
653
*
654
* @return bitrate in bps
655
*/
656
public String bitrate_string()
657
{
658
if (h_vbr == true)
659
{
660
return Integer.toString(bitrate()/1000)+" kb/s";
661
}
662
else return bitrate_str[h_version][h_layer - 1][h_bitrate_index];
663
}
664
665
/**
666
* Return Bitrate.
667
*
668
* @return bitrate in bps and average bitrate for VBR header
669
*/
670
public int bitrate()
671
{
672
if (h_vbr == true)
673
{
674
return ((int) ((h_vbr_bytes * 8) / (ms_per_frame() * h_vbr_frames)))*1000;
675
}
676
else return bitrates[h_version][h_layer - 1][h_bitrate_index];
677
}
678
679
/**
680
* Return Instant Bitrate.
681
* Bitrate for VBR is not constant.
682
*
683
* @return bitrate in bps
684
*/
685
public int bitrate_instant()
686
{
687
return bitrates[h_version][h_layer - 1][h_bitrate_index];
688
}
689
690
/**
691
* Returns Frequency
692
*
693
* @return frequency string in kHz
694
*/
695
public String sample_frequency_string()
696
{
697
switch (h_sample_frequency)
698
{
699
case THIRTYTWO:
700
if (h_version == MPEG1)
701
return "32 kHz";
702
else if (h_version == MPEG2_LSF)
703
return "16 kHz";
704
else // SZD
705
return "8 kHz";
706
case FOURTYFOUR_POINT_ONE:
707
if (h_version == MPEG1)
708
return "44.1 kHz";
709
else if (h_version == MPEG2_LSF)
710
return "22.05 kHz";
711
else // SZD
712
return "11.025 kHz";
713
case FOURTYEIGHT:
714
if (h_version == MPEG1)
715
return "48 kHz";
716
else if (h_version == MPEG2_LSF)
717
return "24 kHz";
718
else // SZD
719
return "12 kHz";
720
}
721
return(null);
722
}
723
724
/**
725
* Returns Mode.
726
*/
727
public String mode_string()
728
{
729
switch (h_mode)
730
{
731
case STEREO:
732
return "Stereo";
733
case JOINT_STEREO:
734
return "Joint stereo";
735
case DUAL_CHANNEL:
736
return "Dual channel";
737
case SINGLE_CHANNEL:
738
return "Single channel";
739
}
740
return null;
741
}
742
743
/**
744
* Returns Version.
745
*
746
* @return MPEG-1 or MPEG-2 LSF or MPEG-2.5 LSF
747
*/
748
public String version_string()
749
{
750
switch (h_version)
751
{
752
case MPEG1:
753
return "MPEG-1";
754
case MPEG2_LSF:
755
return "MPEG-2 LSF";
756
case MPEG25_LSF: // SZD
757
return "MPEG-2.5 LSF";
758
}
759
return(null);
760
}
761
762
/**
763
* Returns the number of subbands in the current frame.
764
*
765
* @return number of subbands
766
*/
767
public int number_of_subbands() {return h_number_of_subbands;}
768
769
/**
770
* Returns Intensity Stereo.
771
* (Layer II joint stereo only).
772
* Returns the number of subbands which are in stereo mode,
773
* subbands above that limit are in intensity stereo mode.
774
*
775
* @return intensity
776
*/
777
public int intensity_stereo_bound() {return h_intensity_stereo_bound;}
778
}
779
780