annotate Plugins/Input/mpg123/dxhead.c @ 185:05074252a497 trunk

[svn] Fix a gcc issue, I think.
author nenolod
date Sun, 13 Nov 2005 17:59:06 -0800
parents fa848bd484d8
children b5ae09a6c2f1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
2 * Handle Xing vbr header
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
3 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
4 #include "config.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
5 #include "dxhead.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
6 #include <stdlib.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
7 #include <float.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
8 #include <math.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
9 #include <string.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
10 #include <glib.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
11
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
12 #define GET_INT32BE(b) \
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
13 (i = (b[0] << 24) | (b[1] << 16) | b[2] << 8 | b[3], b += 4, i)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
14
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
15 int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
16 mpg123_get_xing_header(xing_header_t * xing, unsigned char *buf)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
17 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
18 int i, head_flags;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
19 int id, mode;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
20
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
21 memset(xing, 0, sizeof(xing_header_t));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
22
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
23 /* get selected MPEG header data */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
24 id = (buf[1] >> 3) & 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
25 mode = (buf[3] >> 6) & 3;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
26 buf += 4;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
27
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
28 /* Skip the sub band data */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
29 if (id) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
30 /* mpeg1 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
31 if (mode != 3)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
32 buf += 32;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
33 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
34 buf += 17;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
35 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
36 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
37 /* mpeg2 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
38 if (mode != 3)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
39 buf += 17;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
40 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
41 buf += 9;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
42 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
43
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
44 if (strncmp((char *) buf, "Xing", 4))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
45 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
46 buf += 4;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
47
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
48 head_flags = GET_INT32BE(buf);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
49
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
50 if (head_flags & FRAMES_FLAG)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
51 xing->frames = GET_INT32BE(buf);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
52 if (xing->frames < 1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
53 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
54 if (head_flags & BYTES_FLAG)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
55 xing->bytes = GET_INT32BE(buf);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
56
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
57 if (head_flags & TOC_FLAG) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
58 for (i = 0; i < 100; i++) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
59 xing->toc[i] = buf[i];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
60 if (i > 0 && xing->toc[i] < xing->toc[i - 1])
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
61 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
62 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
63 if (xing->toc[99] == 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
64 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
65 buf += 100;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
66 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
67 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
68 for (i = 0; i < 100; i++)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
69 xing->toc[i] = (i * 256) / 100;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
70
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
71 #ifdef XING_DEBUG
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
72 for (i = 0; i < 100; i++) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
73 if ((i % 10) == 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
74 fprintf(stderr, "\n");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
75 fprintf(stderr, " %3d", xing->toc[i]);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
76 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
77 #endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
78
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
79 return 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
80 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
81
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
82 int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
83 mpg123_seek_point(xing_header_t * xing, float percent)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
84 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
85 /* interpolate in TOC to get file seek point in bytes */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
86 int a, seekpoint;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
87 float fa, fb, fx;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
88
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
89 percent = CLAMP(percent, 0, 100);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
90 a = MIN(percent, 99);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
91
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
92 fa = xing->toc[a];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
93
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
94 if (a < 99)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
95 fb = xing->toc[a + 1];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
96 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
97 fb = 256;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
98
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
99 fx = fa + (fb - fa) * (percent - a);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
100 seekpoint = (1.0f / 256.0f) * fx * xing->bytes;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
101
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
102 return seekpoint;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
103 }