annotate src/madplug/replaygain.c @ 2475:a5f1c47cee0c

Use Glib endianess macros.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 30 Mar 2008 01:25:40 +0200
parents 4ad6e7dfb389
children 809736eb47d9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
1 /*
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
2 * mad plugin for audacious
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
3 * Copyright (C) 2005-2007 William Pitcock, Yoshiki Yazawa
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
4 *
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
5 * Portions derived from xmms-mad:
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
6 * Copyright (C) 2001-2002 Sam Clegg - See COPYING
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
7 * Copyright (C) 2001-2007 Samuel Krempp
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
8 *
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
9 * This program is free software; you can redistribute it and/or modify
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
11 * the Free Software Foundation; under version 2 of the License.
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
12 *
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
16 * GNU General Public License for more details.
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
17 *
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
21 */
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
22
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
23 #include "plugin.h"
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
24 #include <stdlib.h>
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
25 #include <math.h>
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
26 #include <ctype.h>
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
27 #include <assert.h>
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
28 #include "replaygain.h"
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
29
2341
59addab003d7 - reworked replaygain to use individual pre-gain for the files with RG info and the rest.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2276
diff changeset
30 static unsigned long
59addab003d7 - reworked replaygain to use individual pre-gain for the files with RG info and the rest.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2276
diff changeset
31 Read_LE_Uint32(const unsigned char *p)
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
32 {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
33 return ((unsigned long) p[0] << 0) |
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
34 ((unsigned long) p[1] << 8) |
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
35 ((unsigned long) p[2] << 16) | ((unsigned long) p[3] << 24);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
36 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
37
2341
59addab003d7 - reworked replaygain to use individual pre-gain for the files with RG info and the rest.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2276
diff changeset
38 static int
59addab003d7 - reworked replaygain to use individual pre-gain for the files with RG info and the rest.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2276
diff changeset
39 uncase_strcmp(const char *s1, const char *s2)
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
40 {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
41 int l1 = strlen(s1);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
42 int l2 = strlen(s2);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
43 int i;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
44 for (i = 0; i < l1 && i < l2; ++i) {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
45 if (toupper(s1[i]) < toupper(s2[i]))
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
46 return -1;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
47 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
48 if (l1 == l2)
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
49 return 0;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
50 return (l1 < l2) ? -1 : +1;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
51 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
52
2341
59addab003d7 - reworked replaygain to use individual pre-gain for the files with RG info and the rest.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2276
diff changeset
53 static gdouble
59addab003d7 - reworked replaygain to use individual pre-gain for the files with RG info and the rest.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2276
diff changeset
54 strgain2double(gchar * s, int len)
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
55 {
2391
7d1411f80023 imported 2b561aa49580 by Eugene Zagidullin.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2341
diff changeset
56 gchar *strval = g_strndup(s, len);
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
57 gdouble res = g_strtod(s, NULL); // gain, in dB.
2391
7d1411f80023 imported 2b561aa49580 by Eugene Zagidullin.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2341
diff changeset
58 g_free(strval);
7d1411f80023 imported 2b561aa49580 by Eugene Zagidullin.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2341
diff changeset
59 return res;
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
60 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
61
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
62 // Reads APE v2.0 tag ending at current pos in fp
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
63
2341
59addab003d7 - reworked replaygain to use individual pre-gain for the files with RG info and the rest.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2276
diff changeset
64 static int
59addab003d7 - reworked replaygain to use individual pre-gain for the files with RG info and the rest.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2276
diff changeset
65 ReadAPE2Tag(VFSFile * fp, struct mad_info_t *file_info)
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
66 {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
67 unsigned long vsize;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
68 unsigned long isize;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
69 unsigned long flags;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
70 char *buff;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
71 char *p;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
72 char *end;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
73 struct APETagFooterStruct T, *tp;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
74 unsigned long TagLen;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
75 unsigned long TagCount;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
76
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
77 tp = &T;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
78
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
79 if (aud_vfs_fseek(fp, -sizeof(T), SEEK_CUR) != 0)
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
80 return 18;
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
81 if (aud_vfs_fread(tp, 1, sizeof(T), fp) != sizeof T)
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
82 return 2;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
83 if (memcmp(tp->ID, "APETAGEX", sizeof(tp->ID)) != 0)
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
84 return 3;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
85 if (Read_LE_Uint32(tp->Version) != 2000)
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
86 return 4;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
87 TagLen = Read_LE_Uint32(tp->Length);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
88 if (TagLen < sizeof(T))
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
89 return 5;
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
90 if (aud_vfs_fseek(fp, -TagLen, SEEK_CUR) != 0)
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
91 return 6;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
92 if ((buff = (char *) malloc(TagLen)) == NULL) {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
93 return 7;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
94 }
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
95 if (aud_vfs_fread(buff, 1, TagLen - sizeof(T), fp) != TagLen - sizeof(T)) {
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
96 free(buff);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
97 return 8;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
98 }
2214
9a869d4bb0d3 make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1978
diff changeset
99
9a869d4bb0d3 make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1978
diff changeset
100 AUDDBG("ver = %ld\n", Read_LE_Uint32(tp->Version));
9a869d4bb0d3 make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1978
diff changeset
101 AUDDBG("taglen = %ld\n", TagLen);
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
102
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
103 TagCount = Read_LE_Uint32(tp->TagCount);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
104 end = buff + TagLen - sizeof(T);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
105 for (p = buff; p < end && TagCount--;) {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
106 vsize = Read_LE_Uint32((unsigned char *)p);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
107 p += 4;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
108 flags = Read_LE_Uint32((unsigned char *)p);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
109 p += 4;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
110 isize = strlen((char *) p);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
111
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
112 if (isize > 0 && vsize > 0) {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
113 gdouble *scale = NULL;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
114 gchar **str = NULL;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
115 if (uncase_strcmp(p, "REPLAYGAIN_ALBUM_GAIN") == 0) {
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
116 scale = &file_info->replaygain_album_scale;
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
117 str = &file_info->replaygain_album_str;
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
118 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
119 if (uncase_strcmp(p, "REPLAYGAIN_TRACK_GAIN") == 0) {
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
120 scale = &file_info->replaygain_track_scale;
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
121 str = &file_info->replaygain_track_str;
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
122 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
123 if (str != NULL) {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
124 assert(scale != NULL);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
125 *scale = strgain2double(p + isize + 1, vsize);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
126 *str = g_strndup(p + isize + 1, vsize);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
127 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
128 //* case of peak info tags : */
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
129 str = NULL;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
130 if (uncase_strcmp(p, "REPLAYGAIN_TRACK_PEAK") == 0) {
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
131 scale = &file_info->replaygain_track_peak;
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
132 str = &file_info->replaygain_track_peak_str;
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
133 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
134 if (uncase_strcmp(p, "REPLAYGAIN_ALBUM_PEAK") == 0) {
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
135 scale = &file_info->replaygain_album_peak;
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
136 str = &file_info->replaygain_album_peak_str;
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
137 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
138 if (str != NULL) {
2391
7d1411f80023 imported 2b561aa49580 by Eugene Zagidullin.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2341
diff changeset
139 *scale = strgain2double(p + isize + 1, vsize);
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
140 *str = g_strndup(p + isize + 1, vsize);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
141 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
142
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
143 /* mp3gain additional tags :
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
144 the gain tag translates to scale = 2^(gain/4),
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
145 i.e., in dB : 20*log(2)/log(10)*gain/4
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
146 -> 1.501*gain dB
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
147 */
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
148 if (uncase_strcmp(p, "MP3GAIN_UNDO") == 0) {
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
149 str = &file_info->mp3gain_undo_str;
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
150 scale = &file_info->mp3gain_undo;
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
151 assert(4 < vsize); /* this tag is +left,+right */
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
152 *str = g_strndup(p + isize + 1, vsize);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
153 *scale = 1.50515 * atoi(*str);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
154 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
155 if (uncase_strcmp(p, "MP3GAIN_MINMAX") == 0) {
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
156 str = &file_info->mp3gain_minmax_str;
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
157 scale = &file_info->mp3gain_minmax;
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
158 *str = g_strndup(p + isize + 1, vsize);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
159 assert(4 < vsize); /* this tag is min,max */
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
160 *scale = 1.50515 * (atoi((*str) + 4) - atoi(*str));
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
161 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
162 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
163 p += isize + 1 + vsize;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
164 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
165
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
166 free(buff);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
167
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
168 return 0;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
169 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
170
2341
59addab003d7 - reworked replaygain to use individual pre-gain for the files with RG info and the rest.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2276
diff changeset
171 static int
59addab003d7 - reworked replaygain to use individual pre-gain for the files with RG info and the rest.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2276
diff changeset
172 find_offset(VFSFile * fp)
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
173 {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
174 static const char *key = "APETAGEX";
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
175 char buff[20000];
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
176 int N = 0;
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
177 if (aud_vfs_fseek(fp, -20000, SEEK_CUR) != 0);
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
178 if ((N = aud_vfs_fread(buff, 1, 20000, fp)) < 16)
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
179 return 1;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
180 int matched = 0;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
181 int i, last_match = -1;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
182 for (i = 0; i < N; ++i) {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
183 if (buff[i] == key[matched])
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
184 ++matched;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
185 else {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
186 if (matched == 5 && buff[i] == 'P')
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
187 matched = 2; // got "APET" + "AP"
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
188 else
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
189 matched = 0;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
190 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
191 if (matched == 8) {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
192 last_match = i;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
193 matched = 0;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
194 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
195 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
196 if (last_match == -1)
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
197 return 1;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
198 return last_match + 1 - 8 + sizeof(struct APETagFooterStruct) - N;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
199 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
200
1057
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
201 /* Eugene Zagidullin:
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
202 * Read ReplayGain info from foobar2000-style id3v2 frames */
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
203
2341
59addab003d7 - reworked replaygain to use individual pre-gain for the files with RG info and the rest.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2276
diff changeset
204 static int
59addab003d7 - reworked replaygain to use individual pre-gain for the files with RG info and the rest.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2276
diff changeset
205 ReadId3v2TXXX(struct mad_info_t *file_info)
1057
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
206 {
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
207 int i;
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
208 char *key;
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
209 char *value;
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
210 struct id3_frame *frame;
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
211
2276
d25cd7e7eddb append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2214
diff changeset
212 AUDDBG("f: ReadId3v2TXXX\n");
2214
9a869d4bb0d3 make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1978
diff changeset
213
1057
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
214 /* tag must be read before! */
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
215 if (! file_info->tag ) {
2276
d25cd7e7eddb append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2214
diff changeset
216 AUDDBG("id3v2 not found\n");
1057
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
217 return 0;
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
218 }
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
219
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
220 /* Partially based on code from MPD (http://www.musicpd.org/) */
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
221 for (i = 0; (frame = id3_tag_findframe(file_info->tag, "TXXX", i)); i++) {
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
222 if (frame->nfields < 3)
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
223 continue;
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
224
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
225 key = (char *)
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
226 id3_ucs4_latin1duplicate(id3_field_getstring
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
227 (&frame->fields[1]));
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
228 value = (char *)
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
229 id3_ucs4_latin1duplicate(id3_field_getstring
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
230 (&frame->fields[2]));
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
231
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
232 if (strcasecmp(key, "replaygain_track_gain") == 0) {
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
233 file_info->replaygain_track_scale = strgain2double(value, strlen(value));
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
234 file_info->replaygain_track_str = g_strdup(value);
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
235 } else if (strcasecmp(key, "replaygain_album_gain") == 0) {
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
236 file_info->replaygain_album_scale = strgain2double(value, strlen(value));
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
237 file_info->replaygain_album_str = g_strdup(value);
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
238 } else if (strcasecmp(key, "replaygain_track_peak") == 0) {
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
239 file_info->replaygain_track_peak = g_strtod(value, NULL);
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
240 file_info->replaygain_track_peak_str = g_strdup(value);
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
241 } else if (strcasecmp(key, "replaygain_album_peak") == 0) {
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
242 file_info->replaygain_album_peak = g_strtod(value, NULL);
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
243 file_info->replaygain_album_peak_str = g_strdup(value);
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
244 }
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
245
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
246 free(key);
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
247 free(value);
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
248 }
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
249
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
250 return 0;
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
251 }
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
252
2341
59addab003d7 - reworked replaygain to use individual pre-gain for the files with RG info and the rest.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2276
diff changeset
253 void
59addab003d7 - reworked replaygain to use individual pre-gain for the files with RG info and the rest.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2276
diff changeset
254 read_replaygain(struct mad_info_t *file_info)
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
255 {
710
c75c2b332bce [svn] - C99 style enforcement
nenolod
parents: 709
diff changeset
256 VFSFile *fp;
c75c2b332bce [svn] - C99 style enforcement
nenolod
parents: 709
diff changeset
257 glong curpos = 0;
c75c2b332bce [svn] - C99 style enforcement
nenolod
parents: 709
diff changeset
258
2276
d25cd7e7eddb append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2214
diff changeset
259 AUDDBG("f: read_replaygain\n");
773
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 713
diff changeset
260
2392
4ad6e7dfb389 imported 5298b10777b3 by Eugene Zagidullin.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2391
diff changeset
261 file_info->replaygain_track_peak = 0.0;
4ad6e7dfb389 imported 5298b10777b3 by Eugene Zagidullin.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2391
diff changeset
262 file_info->replaygain_track_scale = 0.0;
4ad6e7dfb389 imported 5298b10777b3 by Eugene Zagidullin.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2391
diff changeset
263 file_info->replaygain_album_peak = 0.0;
4ad6e7dfb389 imported 5298b10777b3 by Eugene Zagidullin.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2391
diff changeset
264 file_info->replaygain_album_scale = 0.0;
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
265 file_info->mp3gain_undo = -77;
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
266 file_info->mp3gain_minmax = -77;
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
267
1057
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
268 if (ReadId3v2TXXX(file_info)) {
2341
59addab003d7 - reworked replaygain to use individual pre-gain for the files with RG info and the rest.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2276
diff changeset
269 AUDDBG("found ReplayGain info in id3v2 tag\n");
2214
9a869d4bb0d3 make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1978
diff changeset
270 #ifdef AUD_DEBUG
2341
59addab003d7 - reworked replaygain to use individual pre-gain for the files with RG info and the rest.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2276
diff changeset
271 gchar *tmp = g_filename_to_utf8(file_info->filename, -1, NULL, NULL, NULL);
1057
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
272
2276
d25cd7e7eddb append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2214
diff changeset
273 AUDDBG("RG album scale= %g, RG track scale = %g, in %s\n",
1057
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
274 file_info->replaygain_album_scale,
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
275 file_info->replaygain_track_scale, tmp);
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
276 g_free(tmp);
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
277 #endif
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
278 return;
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
279 }
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
280
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
281
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
282 /* APEv2 stuff */
706
6bc134eec1f3 [svn] - make use of the new id3_file_vfsopen() function.
nenolod
parents: 611
diff changeset
283 if (file_info->infile) {
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
284 fp = aud_vfs_dup(file_info->infile);
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
285 curpos = aud_vfs_ftell(fp);
784
5ddfe9eac8ee [svn] - fix read_replaygain(). necessary fseek was missing in reuse fd code. closes #843.
yaz
parents: 773
diff changeset
286 }
5ddfe9eac8ee [svn] - fix read_replaygain(). necessary fseek was missing in reuse fd code. closes #843.
yaz
parents: 773
diff changeset
287 else {
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
288 if ((fp = aud_vfs_fopen(file_info->filename, "rb")) == NULL)
706
6bc134eec1f3 [svn] - make use of the new id3_file_vfsopen() function.
nenolod
parents: 611
diff changeset
289 return;
784
5ddfe9eac8ee [svn] - fix read_replaygain(). necessary fseek was missing in reuse fd code. closes #843.
yaz
parents: 773
diff changeset
290 }
5ddfe9eac8ee [svn] - fix read_replaygain(). necessary fseek was missing in reuse fd code. closes #843.
yaz
parents: 773
diff changeset
291
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
292 if (aud_vfs_fseek(fp, 0L, SEEK_END) != 0) {
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
293 aud_vfs_fclose(fp);
784
5ddfe9eac8ee [svn] - fix read_replaygain(). necessary fseek was missing in reuse fd code. closes #843.
yaz
parents: 773
diff changeset
294 return;
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
295 }
706
6bc134eec1f3 [svn] - make use of the new id3_file_vfsopen() function.
nenolod
parents: 611
diff changeset
296
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
297 long pos = aud_vfs_ftell(fp);
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
298 int res = -1;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
299 int try = 0;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
300 while (res != 0 && try < 10) {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
301 // try skipping an id3 tag
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
302 aud_vfs_fseek(fp, pos, SEEK_SET);
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
303 aud_vfs_fseek(fp, try * -128, SEEK_CUR);
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
304 res = ReadAPE2Tag(fp, file_info);
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
305 ++try;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
306 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
307 if (res != 0) {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
308 // try brute search (don't want to parse all possible kinds of tags..)
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
309 aud_vfs_fseek(fp, pos, SEEK_SET);
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
310 int offs = find_offset(fp);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
311 if (offs <= 0) { // found !
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
312 aud_vfs_fseek(fp, pos, SEEK_SET);
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
313 aud_vfs_fseek(fp, offs, SEEK_CUR);
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
314 res = ReadAPE2Tag(fp, file_info);
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
315 if (res != 0) {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
316 g_message
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
317 ("hmpf, was supposed to find a tag.. offs=%d, res=%d",
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
318 offs, res);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
319 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
320 }
773
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 713
diff changeset
321 else
2276
d25cd7e7eddb append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2214
diff changeset
322 AUDDBG("replaygain: not found\n");
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
323 }
2214
9a869d4bb0d3 make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1978
diff changeset
324 #ifdef AUD_DEBUG
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
325 if (res == 0) { // got APE tags, show the result
799
d200de50a1fc [svn] - convert filename into utf8 in debug messages.
yaz
parents: 784
diff changeset
326 gchar *tmp = g_filename_to_utf8(file_info->filename, -1, NULL, NULL, NULL);
2276
d25cd7e7eddb append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2214
diff changeset
327 AUDDBG("RG album scale= %g, RG track scale = %g, in %s\n",
773
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 713
diff changeset
328 file_info->replaygain_album_scale,
799
d200de50a1fc [svn] - convert filename into utf8 in debug messages.
yaz
parents: 784
diff changeset
329 file_info->replaygain_track_scale, tmp);
d200de50a1fc [svn] - convert filename into utf8 in debug messages.
yaz
parents: 784
diff changeset
330 g_free(tmp);
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
331 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
332 #endif
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
333
713
3b609c9f538e [svn] - reset position if we were passed a live FD.
nenolod
parents: 711
diff changeset
334 if (file_info->infile)
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
335 aud_vfs_fseek(fp, curpos, SEEK_SET);
713
3b609c9f538e [svn] - reset position if we were passed a live FD.
nenolod
parents: 711
diff changeset
336
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
337 aud_vfs_fclose(fp);
773
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 713
diff changeset
338
2276
d25cd7e7eddb append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2214
diff changeset
339 AUDDBG("e: read_replaygain\n");
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
340 }