summaryrefslogtreecommitdiff
path: root/songdbj/javazoom/jl/decoder/Header.java
diff options
context:
space:
mode:
authorMichiel Van Der Kolk <not.valid@email.address>2005-07-11 15:42:37 +0000
committerMichiel Van Der Kolk <not.valid@email.address>2005-07-11 15:42:37 +0000
commit9fee0ec4ca0c5b7a334cc29dbb58e76c7a4c736e (patch)
tree4c304cd4151020bd5494d279ee68a105ae3a5a3a /songdbj/javazoom/jl/decoder/Header.java
parentdfa8ecbe609ca8ea194d08560a44fb9a92e94b4b (diff)
downloadrockbox-9fee0ec4ca0c5b7a334cc29dbb58e76c7a4c736e.tar.gz
rockbox-9fee0ec4ca0c5b7a334cc29dbb58e76c7a4c736e.zip
Songdb java version, source. only 1.5 compatible
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7101 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'songdbj/javazoom/jl/decoder/Header.java')
-rw-r--r--songdbj/javazoom/jl/decoder/Header.java762
1 files changed, 762 insertions, 0 deletions
diff --git a/songdbj/javazoom/jl/decoder/Header.java b/songdbj/javazoom/jl/decoder/Header.java
new file mode 100644
index 0000000000..e85fe19f64
--- /dev/null
+++ b/songdbj/javazoom/jl/decoder/Header.java
@@ -0,0 +1,762 @@
1/*
2 * 11/19/04 : 1.0 moved to LGPL.
3 * VBRI header support added, E.B javalayer@javazoom.net
4 *
5 * 12/04/03 : VBR (XING) header support added, E.B javalayer@javazoom.net
6 *
7 * 02/13/99 : Java Conversion by JavaZOOM , E.B javalayer@javazoom.net
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 (bading@cs.tu-berlin.de)
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 */
32package javazoom.jl.decoder;
33
34/**
35 * Class for extracting information from a frame header.
36 */
37public 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 StringBuffer buffer = new StringBuffer(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 optionnal VBR frame.
238 * @param firstframe
239 * @author E.B (javalayer@javazoom.net)
240 */
241 void parseVBR(byte[] firstframe) throws BitstreamException
242 {
243 // Trying Xing header.
244 String xing = "Xing";
245 byte tmp[] = new byte[4];
246 int offset = 0;
247 // Compute "Xing" offset depending on MPEG version and channels.
248 if (h_version == MPEG1)
249 {
250 if (h_mode == SINGLE_CHANNEL) offset=21-4;
251 else offset=36-4;
252 }
253 else
254 {
255 if (h_mode == SINGLE_CHANNEL) offset=13-4;
256 else offset = 21-4;
257 }
258 try
259 {
260 System.arraycopy(firstframe, offset, tmp, 0, 4);
261 // Is "Xing" ?
262 if (xing.equals(new String(tmp)))
263 {
264 //Yes.
265 h_vbr = true;
266 h_vbr_frames = -1;
267 h_vbr_bytes = -1;
268 h_vbr_scale = -1;
269 h_vbr_toc = new byte[100];
270
271 int length = 4;
272 // Read flags.
273 byte flags[] = new byte[4];
274 System.arraycopy(firstframe, offset + length, flags, 0, flags.length);
275 length += flags.length;
276 // Read number of frames (if available).
277 if ((flags[3] & (byte) (1 << 0)) != 0)
278 {
279 System.arraycopy(firstframe, offset + length, tmp, 0, tmp.length);
280 h_vbr_frames = (tmp[0] << 24)&0xFF000000 | (tmp[1] << 16)&0x00FF0000 | (tmp[2] << 8)&0x0000FF00 | tmp[3]&0x000000FF;
281 length += 4;
282 }
283 // Read size (if available).
284 if ((flags[3] & (byte) (1 << 1)) != 0)
285 {
286 System.arraycopy(firstframe, offset + length, tmp, 0, tmp.length);
287 h_vbr_bytes = (tmp[0] << 24)&0xFF000000 | (tmp[1] << 16)&0x00FF0000 | (tmp[2] << 8)&0x0000FF00 | tmp[3]&0x000000FF;
288 length += 4;
289 }
290 // Read TOC (if available).
291 if ((flags[3] & (byte) (1 << 2)) != 0)
292 {
293 System.arraycopy(firstframe, offset + length, h_vbr_toc, 0, h_vbr_toc.length);
294 length += h_vbr_toc.length;
295 }
296 // Read scale (if available).
297 if ((flags[3] & (byte) (1 << 3)) != 0)
298 {
299 System.arraycopy(firstframe, offset + length, tmp, 0, tmp.length);
300 h_vbr_scale = (tmp[0] << 24)&0xFF000000 | (tmp[1] << 16)&0x00FF0000 | (tmp[2] << 8)&0x0000FF00 | tmp[3]&0x000000FF;
301 length += 4;
302 }
303 //System.out.println("VBR:"+xing+" Frames:"+ h_vbr_frames +" Size:"+h_vbr_bytes);
304 }
305 }
306 catch (ArrayIndexOutOfBoundsException e)
307 {
308 throw new BitstreamException("XingVBRHeader Corrupted",e);
309 }
310
311 // Trying VBRI header.
312 String vbri = "VBRI";
313 offset = 36-4;
314 try
315 {
316 System.arraycopy(firstframe, offset, tmp, 0, 4);
317 // Is "VBRI" ?
318 if (vbri.equals(new String(tmp)))
319 {
320 //Yes.
321 h_vbr = true;
322 h_vbr_frames = -1;
323 h_vbr_bytes = -1;
324 h_vbr_scale = -1;
325 h_vbr_toc = new byte[100];
326 // Bytes.
327 int length = 4 + 6;
328 System.arraycopy(firstframe, offset + length, tmp, 0, tmp.length);
329 h_vbr_bytes = (tmp[0] << 24)&0xFF000000 | (tmp[1] << 16)&0x00FF0000 | (tmp[2] << 8)&0x0000FF00 | tmp[3]&0x000000FF;
330 length += 4;
331 // Frames.
332 System.arraycopy(firstframe, offset + length, tmp, 0, tmp.length);
333 h_vbr_frames = (tmp[0] << 24)&0xFF000000 | (tmp[1] << 16)&0x00FF0000 | (tmp[2] << 8)&0x0000FF00 | tmp[3]&0x000000FF;
334 length += 4;
335 //System.out.println("VBR:"+vbri+" Frames:"+ h_vbr_frames +" Size:"+h_vbr_bytes);
336 // TOC
337 // TODO
338 }
339 }
340 catch (ArrayIndexOutOfBoundsException e)
341 {
342 throw new BitstreamException("VBRIVBRHeader Corrupted",e);
343 }
344 }
345
346 // Functions to query header contents:
347 /**
348 * Returns version.
349 */
350 public int version() { return h_version; }
351
352 /**
353 * Returns Layer ID.
354 */
355 public int layer() { return h_layer; }
356
357 /**
358 * Returns bitrate index.
359 */
360 public int bitrate_index() { return h_bitrate_index; }
361
362 /**
363 * Returns Sample Frequency.
364 */
365 public int sample_frequency() { return h_sample_frequency; }
366
367 /**
368 * Returns Frequency.
369 */
370 public int frequency() {return frequencies[h_version][h_sample_frequency];}
371
372 /**
373 * Returns Mode.
374 */
375 public int mode() { return h_mode; }
376
377 /**
378 * Returns Protection bit.
379 */
380 public boolean checksums()
381 {
382 if (h_protection_bit == 0) return true;
383 else return false;
384 }
385
386 /**
387 * Returns Copyright.
388 */
389 public boolean copyright() { return h_copyright; }
390
391 /**
392 * Returns Original.
393 */
394 public boolean original() { return h_original; }
395
396 /**
397 * Return VBR.
398 * @return true if VBR header is found
399 */
400 public boolean vbr() { return h_vbr; }
401
402 /**
403 * Return VBR scale.
404 * @return scale of -1 if not available
405 */
406 public int vbr_scale() { return h_vbr_scale; }
407
408 /**
409 * Return VBR TOC.
410 * @return vbr toc ot null if not available
411 */
412 public byte[] vbr_toc() { return h_vbr_toc; }
413
414 /**
415 * Returns Checksum flag.
416 * Compares computed checksum with stream checksum.
417 */
418 public boolean checksum_ok () { return (checksum == crc.checksum()); }
419
420 // Seeking and layer III stuff
421 /**
422 * Returns Layer III Padding bit.
423 */
424 public boolean padding()
425 {
426 if (h_padding_bit == 0) return false;
427 else return true;
428 }
429
430 /**
431 * Returns Slots.
432 */
433 public int slots() { return nSlots; }
434
435 /**
436 * Returns Mode Extension.
437 */
438 public int mode_extension() { return h_mode_extension; }
439
440 // E.B -> private to public
441 public static final int bitrates[][][] = {
442 {{0 /*free format*/, 32000, 48000, 56000, 64000, 80000, 96000,
443 112000, 128000, 144000, 160000, 176000, 192000 ,224000, 256000, 0},
444 {0 /*free format*/, 8000, 16000, 24000, 32000, 40000, 48000,
445 56000, 64000, 80000, 96000, 112000, 128000, 144000, 160000, 0},
446 {0 /*free format*/, 8000, 16000, 24000, 32000, 40000, 48000,
447 56000, 64000, 80000, 96000, 112000, 128000, 144000, 160000, 0}},
448
449 {{0 /*free format*/, 32000, 64000, 96000, 128000, 160000, 192000,
450 224000, 256000, 288000, 320000, 352000, 384000, 416000, 448000, 0},
451 {0 /*free format*/, 32000, 48000, 56000, 64000, 80000, 96000,
452 112000, 128000, 160000, 192000, 224000, 256000, 320000, 384000, 0},
453 {0 /*free format*/, 32000, 40000, 48000, 56000, 64000, 80000,
454 96000, 112000, 128000, 160000, 192000, 224000, 256000, 320000, 0}},
455 // SZD: MPEG2.5
456 {{0 /*free format*/, 32000, 48000, 56000, 64000, 80000, 96000,
457 112000, 128000, 144000, 160000, 176000, 192000 ,224000, 256000, 0},
458 {0 /*free format*/, 8000, 16000, 24000, 32000, 40000, 48000,
459 56000, 64000, 80000, 96000, 112000, 128000, 144000, 160000, 0},
460 {0 /*free format*/, 8000, 16000, 24000, 32000, 40000, 48000,
461 56000, 64000, 80000, 96000, 112000, 128000, 144000, 160000, 0}},
462
463 };
464
465 // E.B -> private to public
466 /**
467 * Calculate Frame size.
468 * Calculates framesize in bytes excluding header size.
469 */
470 public int calculate_framesize()
471 {
472
473 if (h_layer == 1)
474 {
475 framesize = (12 * bitrates[h_version][0][h_bitrate_index]) /
476 frequencies[h_version][h_sample_frequency];
477 if (h_padding_bit != 0 ) framesize++;
478 framesize <<= 2; // one slot is 4 bytes long
479 nSlots = 0;
480 }
481 else
482 {
483 framesize = (144 * bitrates[h_version][h_layer - 1][h_bitrate_index]) /
484 frequencies[h_version][h_sample_frequency];
485 if (h_version == MPEG2_LSF || h_version == MPEG25_LSF) framesize >>= 1; // SZD
486 if (h_padding_bit != 0) framesize++;
487 // Layer III slots
488 if (h_layer == 3)
489 {
490 if (h_version == MPEG1)
491 {
492 nSlots = framesize - ((h_mode == SINGLE_CHANNEL) ? 17 : 32) // side info size
493 - ((h_protection_bit!=0) ? 0 : 2) // CRC size
494 - 4; // header size
495 }
496 else
497 { // MPEG-2 LSF, SZD: MPEG-2.5 LSF
498 nSlots = framesize - ((h_mode == SINGLE_CHANNEL) ? 9 : 17) // side info size
499 - ((h_protection_bit!=0) ? 0 : 2) // CRC size
500 - 4; // header size
501 }
502 }
503 else
504 {
505 nSlots = 0;
506 }
507 }
508 framesize -= 4; // subtract header size
509 return framesize;
510 }
511
512 /**
513 * Returns the maximum number of frames in the stream.
514 * @param streamsize
515 * @return number of frames
516 */
517 public int max_number_of_frames(int streamsize) // E.B
518 {
519 if (h_vbr == true) return h_vbr_frames;
520 else
521 {
522 if ((framesize + 4 - h_padding_bit) == 0) return 0;
523 else return(streamsize / (framesize + 4 - h_padding_bit));
524 }
525 }
526
527 /**
528 * Returns the maximum number of frames in the stream.
529 * @param streamsize
530 * @return number of frames
531 */
532 public int min_number_of_frames(int streamsize) // E.B
533 {
534 if (h_vbr == true) return h_vbr_frames;
535 else
536 {
537 if ((framesize + 5 - h_padding_bit) == 0) return 0;
538 else return(streamsize / (framesize + 5 - h_padding_bit));
539 }
540 }
541
542
543 /**
544 * Returns ms/frame.
545 * @return milliseconds per frame
546 */
547 public float ms_per_frame() // E.B
548 {
549 if (h_vbr == true)
550 {
551 double tpf = h_vbr_time_per_frame[layer()] / frequency();
552 if ((h_version == MPEG2_LSF) || (h_version == MPEG25_LSF)) tpf /= 2;
553 return ((float) (tpf * 1000));
554 }
555 else
556 {
557 float ms_per_frame_array[][] = {{8.707483f, 8.0f, 12.0f},
558 {26.12245f, 24.0f, 36.0f},
559 {26.12245f, 24.0f, 36.0f}};
560 return(ms_per_frame_array[h_layer-1][h_sample_frequency]);
561 }
562 }
563
564 /**
565 * Returns total ms.
566 * @param streamsize
567 * @return total milliseconds
568 */
569 public float total_ms(int streamsize) // E.B
570 {
571 return(max_number_of_frames(streamsize) * ms_per_frame());
572 }
573
574 /**
575 * Returns synchronized header.
576 */
577 public int getSyncHeader() // E.B
578 {
579 return _headerstring;
580 }
581
582 // functions which return header informations as strings:
583 /**
584 * Return Layer version.
585 */
586 public String layer_string()
587 {
588 switch (h_layer)
589 {
590 case 1:
591 return "I";
592 case 2:
593 return "II";
594 case 3:
595 return "III";
596 }
597 return null;
598 }
599
600 // E.B -> private to public
601 public static final String bitrate_str[][][] = {
602 {{"free format", "32 kbit/s", "48 kbit/s", "56 kbit/s", "64 kbit/s",
603 "80 kbit/s", "96 kbit/s", "112 kbit/s", "128 kbit/s", "144 kbit/s",
604 "160 kbit/s", "176 kbit/s", "192 kbit/s", "224 kbit/s", "256 kbit/s",
605 "forbidden"},
606 {"free format", "8 kbit/s", "16 kbit/s", "24 kbit/s", "32 kbit/s",
607 "40 kbit/s", "48 kbit/s", "56 kbit/s", "64 kbit/s", "80 kbit/s",
608 "96 kbit/s", "112 kbit/s", "128 kbit/s", "144 kbit/s", "160 kbit/s",
609 "forbidden"},
610 {"free format", "8 kbit/s", "16 kbit/s", "24 kbit/s", "32 kbit/s",
611 "40 kbit/s", "48 kbit/s", "56 kbit/s", "64 kbit/s", "80 kbit/s",
612 "96 kbit/s", "112 kbit/s", "128 kbit/s", "144 kbit/s", "160 kbit/s",
613 "forbidden"}},
614
615 {{"free format", "32 kbit/s", "64 kbit/s", "96 kbit/s", "128 kbit/s",
616 "160 kbit/s", "192 kbit/s", "224 kbit/s", "256 kbit/s", "288 kbit/s",
617 "320 kbit/s", "352 kbit/s", "384 kbit/s", "416 kbit/s", "448 kbit/s",
618 "forbidden"},
619 {"free format", "32 kbit/s", "48 kbit/s", "56 kbit/s", "64 kbit/s",
620 "80 kbit/s", "96 kbit/s", "112 kbit/s", "128 kbit/s", "160 kbit/s",
621 "192 kbit/s", "224 kbit/s", "256 kbit/s", "320 kbit/s", "384 kbit/s",
622 "forbidden"},
623 {"free format", "32 kbit/s", "40 kbit/s", "48 kbit/s", "56 kbit/s",
624 "64 kbit/s", "80 kbit/s" , "96 kbit/s", "112 kbit/s", "128 kbit/s",
625 "160 kbit/s", "192 kbit/s", "224 kbit/s", "256 kbit/s", "320 kbit/s",
626 "forbidden"}},
627 // SZD: MPEG2.5
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", "144 kbit/s",
630 "160 kbit/s", "176 kbit/s", "192 kbit/s", "224 kbit/s", "256 kbit/s",
631 "forbidden"},
632 {"free format", "8 kbit/s", "16 kbit/s", "24 kbit/s", "32 kbit/s",
633 "40 kbit/s", "48 kbit/s", "56 kbit/s", "64 kbit/s", "80 kbit/s",
634 "96 kbit/s", "112 kbit/s", "128 kbit/s", "144 kbit/s", "160 kbit/s",
635 "forbidden"},
636 {"free format", "8 kbit/s", "16 kbit/s", "24 kbit/s", "32 kbit/s",
637 "40 kbit/s", "48 kbit/s", "56 kbit/s", "64 kbit/s", "80 kbit/s",
638 "96 kbit/s", "112 kbit/s", "128 kbit/s", "144 kbit/s", "160 kbit/s",
639 "forbidden"}},
640 };
641
642 /**
643 * Return Bitrate.
644 * @return bitrate in bps
645 */
646 public String bitrate_string()
647 {
648 if (h_vbr == true)
649 {
650 return Integer.toString(bitrate()/1000)+" kb/s";
651 }
652 else return bitrate_str[h_version][h_layer - 1][h_bitrate_index];
653 }
654
655 /**
656 * Return Bitrate.
657 * @return bitrate in bps and average bitrate for VBR header
658 */
659 public int bitrate()
660 {
661 if (h_vbr == true)
662 {
663 return ((int) ((h_vbr_bytes * 8) / (ms_per_frame() * h_vbr_frames)))*1000;
664 }
665 else return bitrates[h_version][h_layer - 1][h_bitrate_index];
666 }
667
668 /**
669 * Return Instant Bitrate.
670 * Bitrate for VBR is not constant.
671 * @return bitrate in bps
672 */
673 public int bitrate_instant()
674 {
675 return bitrates[h_version][h_layer - 1][h_bitrate_index];
676 }
677
678 /**
679 * Returns Frequency
680 * @return frequency string in kHz
681 */
682 public String sample_frequency_string()
683 {
684 switch (h_sample_frequency)
685 {
686 case THIRTYTWO:
687 if (h_version == MPEG1)
688 return "32 kHz";
689 else if (h_version == MPEG2_LSF)
690 return "16 kHz";
691 else // SZD
692 return "8 kHz";
693 case FOURTYFOUR_POINT_ONE:
694 if (h_version == MPEG1)
695 return "44.1 kHz";
696 else if (h_version == MPEG2_LSF)
697 return "22.05 kHz";
698 else // SZD
699 return "11.025 kHz";
700 case FOURTYEIGHT:
701 if (h_version == MPEG1)
702 return "48 kHz";
703 else if (h_version == MPEG2_LSF)
704 return "24 kHz";
705 else // SZD
706 return "12 kHz";
707 }
708 return(null);
709 }
710
711 /**
712 * Returns Mode.
713 */
714 public String mode_string()
715 {
716 switch (h_mode)
717 {
718 case STEREO:
719 return "Stereo";
720 case JOINT_STEREO:
721 return "Joint stereo";
722 case DUAL_CHANNEL:
723 return "Dual channel";
724 case SINGLE_CHANNEL:
725 return "Single channel";
726 }
727 return null;
728 }
729
730 /**
731 * Returns Version.
732 * @return MPEG-1 or MPEG-2 LSF or MPEG-2.5 LSF
733 */
734 public String version_string()
735 {
736 switch (h_version)
737 {
738 case MPEG1:
739 return "MPEG-1";
740 case MPEG2_LSF:
741 return "MPEG-2 LSF";
742 case MPEG25_LSF: // SZD
743 return "MPEG-2.5 LSF";
744 }
745 return(null);
746 }
747
748 /**
749 * Returns the number of subbands in the current frame.
750 * @return number of subbands
751 */
752 public int number_of_subbands() {return h_number_of_subbands;}
753
754 /**
755 * Returns Intensity Stereo.
756 * (Layer II joint stereo only).
757 * Returns the number of subbands which are in stereo mode,
758 * subbands above that limit are in intensity stereo mode.
759 * @return intensity
760 */
761 public int intensity_stereo_bound() {return h_intensity_stereo_bound;}
762}