Mercurial > audlegacy-plugins
annotate src/madplug/replaygain.c @ 1263:458d46e65a86
wav-sndfile: in is_our_file, ensure that filename is not NULL before passing it to sf_open
author | Giacomo Lozito <james@develia.org> |
---|---|
date | Fri, 13 Jul 2007 20:55:42 +0200 |
parents | ddb79127d9cf |
children | fa9f85cebade |
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 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
30 static unsigned long Read_LE_Uint32(const unsigned char *p) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
31 { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
32 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
|
33 ((unsigned long) p[1] << 8) | |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
34 ((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
|
35 } |
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 static int uncase_strcmp(const char *s1, const char *s2) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
38 { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
39 int l1 = strlen(s1); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
40 int l2 = strlen(s2); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
41 int i; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
42 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
|
43 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
|
44 return -1; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
45 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
46 if (l1 == l2) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
47 return 0; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
48 return (l1 < l2) ? -1 : +1; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
49 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
50 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
51 static gdouble strgain2double(gchar * s, int len) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
52 { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
53 gdouble res = g_strtod(s, NULL); // gain, in dB. |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
54 if (res == 0) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
55 return 1; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
56 return pow(10, res / 20); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
57 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
58 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
59 // 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
|
60 |
611 | 61 static int 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
|
62 { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
63 unsigned long vsize; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
64 unsigned long isize; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
65 unsigned long flags; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
66 char *buff; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
67 char *p; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
68 char *end; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
69 struct APETagFooterStruct T, *tp; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
70 unsigned long TagLen; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
71 unsigned long TagCount; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
72 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
73 tp = &T; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
74 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
75 if (vfs_fseek(fp, -sizeof(T), SEEK_CUR) != 0) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
76 return 18; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
77 if (vfs_fread(tp, 1, sizeof(T), fp) != sizeof T) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
78 return 2; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
79 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
|
80 return 3; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
81 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
|
82 return 4; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
83 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
|
84 if (TagLen < sizeof(T)) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
85 return 5; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
86 if (vfs_fseek(fp, -TagLen, SEEK_CUR) != 0) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
87 return 6; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
88 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
|
89 return 7; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
90 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
91 if (vfs_fread(buff, 1, TagLen - sizeof(T), fp) != TagLen - sizeof(T)) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
92 free(buff); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
93 return 8; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
94 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
95 #ifdef DEBUG |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
96 printf("ver = %ld\n", Read_LE_Uint32(tp->Version)); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
97 printf("taglen = %ld\n", TagLen); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
98 #endif |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
99 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
100 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
|
101 end = buff + TagLen - sizeof(T); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
102 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
|
103 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
|
104 p += 4; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
105 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
|
106 p += 4; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
107 isize = strlen((char *) p); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
108 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
109 if (isize > 0 && vsize > 0) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
110 gdouble *scale = NULL; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
111 gchar **str = NULL; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
112 if (uncase_strcmp(p, "REPLAYGAIN_ALBUM_GAIN") == 0) { |
611 | 113 scale = &file_info->replaygain_album_scale; |
114 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
|
115 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
116 if (uncase_strcmp(p, "REPLAYGAIN_TRACK_GAIN") == 0) { |
611 | 117 scale = &file_info->replaygain_track_scale; |
118 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
|
119 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
120 if (str != NULL) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
121 assert(scale != NULL); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
122 *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
|
123 *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
|
124 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
125 //* case of peak info tags : */ |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
126 str = NULL; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
127 if (uncase_strcmp(p, "REPLAYGAIN_TRACK_PEAK") == 0) { |
611 | 128 scale = &file_info->replaygain_track_peak; |
129 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
|
130 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
131 if (uncase_strcmp(p, "REPLAYGAIN_ALBUM_PEAK") == 0) { |
611 | 132 scale = &file_info->replaygain_album_peak; |
133 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
|
134 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
135 if (str != NULL) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
136 *scale = g_strtod(p + isize + 1, NULL); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
137 *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
|
138 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
139 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
140 /* mp3gain additional tags : |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
141 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
|
142 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
|
143 -> 1.501*gain dB |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
144 */ |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
145 if (uncase_strcmp(p, "MP3GAIN_UNDO") == 0) { |
611 | 146 str = &file_info->mp3gain_undo_str; |
147 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
|
148 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
|
149 *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
|
150 *scale = 1.50515 * atoi(*str); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
151 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
152 if (uncase_strcmp(p, "MP3GAIN_MINMAX") == 0) { |
611 | 153 str = &file_info->mp3gain_minmax_str; |
154 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
|
155 *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
|
156 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
|
157 *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
|
158 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
159 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
160 p += isize + 1 + vsize; |
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 free(buff); |
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 return 0; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
166 } |
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 static int find_offset(VFSFile * fp) |
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 static const char *key = "APETAGEX"; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
171 char buff[20000]; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
172 int N = 0; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
173 if (vfs_fseek(fp, -20000, SEEK_CUR) != 0); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
174 if ((N = vfs_fread(buff, 1, 20000, fp)) < 16) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
175 return 1; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
176 int matched = 0; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
177 int i, last_match = -1; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
178 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
|
179 if (buff[i] == key[matched]) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
180 ++matched; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
181 else { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
182 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
|
183 matched = 2; // got "APET" + "AP" |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
184 else |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
185 matched = 0; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
186 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
187 if (matched == 8) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
188 last_match = i; |
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 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
192 if (last_match == -1) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
193 return 1; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
194 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
|
195 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
196 |
1057
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
197 /* Eugene Zagidullin: |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
198 * 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
|
199 |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
200 static int ReadId3v2TXXX(struct mad_info_t *file_info) |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
201 { |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
202 int i; |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
203 char *key; |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
204 char *value; |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
205 struct id3_frame *frame; |
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 #ifdef DEBUG |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
208 g_message("f: ReadId3v2TXXX"); |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
209 #endif |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
210 /* tag must be read before! */ |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
211 if (! file_info->tag ) { |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
212 #ifdef DEBUG |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
213 g_message("id3v2 not found"); |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
214 #endif |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
215 return 0; |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
216 } |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
217 |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
218 /* 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
|
219 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
|
220 if (frame->nfields < 3) |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
221 continue; |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
222 |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
223 key = (char *) |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
224 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
|
225 (&frame->fields[1])); |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
226 value = (char *) |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
227 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
|
228 (&frame->fields[2])); |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
229 |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
230 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
|
231 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
|
232 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
|
233 } 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
|
234 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
|
235 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
|
236 } 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
|
237 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
|
238 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
|
239 } 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
|
240 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
|
241 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
|
242 } |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
243 |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
244 free(key); |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
245 free(value); |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
246 } |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
247 |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
248 if (file_info->replaygain_track_scale != -1 || file_info->replaygain_album_scale != -1) |
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 file_info->has_replaygain = TRUE; |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
251 return 1; |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
252 } |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
253 |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
254 return 0; |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
255 } |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
256 |
773 | 257 void 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
|
258 { |
710 | 259 VFSFile *fp; |
260 glong curpos = 0; | |
261 | |
773 | 262 #ifdef DEBUG |
263 g_message("f: read_replaygain"); | |
264 #endif | |
265 | |
611 | 266 file_info->has_replaygain = FALSE; |
267 file_info->replaygain_album_scale = -1; | |
268 file_info->replaygain_track_scale = -1; | |
269 file_info->mp3gain_undo = -77; | |
270 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
|
271 |
1057
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
272 if (ReadId3v2TXXX(file_info)) { |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
273 #ifdef DEBUG |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
274 g_message("found ReplayGain info in id3v2 tag"); |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
275 |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
276 gchar *tmp = g_filename_to_utf8(file_info->filename, -1, NULL, NULL, NULL); |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
277 g_message("RG album scale= %g, RG track scale = %g, in %s", |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
278 file_info->replaygain_album_scale, |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
279 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
|
280 g_free(tmp); |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
281 #endif |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
282 return; |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
283 } |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
284 |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
285 |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
286 /* APEv2 stuff */ |
706
6bc134eec1f3
[svn] - make use of the new id3_file_vfsopen() function.
nenolod
parents:
611
diff
changeset
|
287 if (file_info->infile) { |
709
90d02e8da818
[svn] - ensure that we only operate on a duplicated fd if our source is
nenolod
parents:
706
diff
changeset
|
288 fp = vfs_dup(file_info->infile); |
706
6bc134eec1f3
[svn] - make use of the new id3_file_vfsopen() function.
nenolod
parents:
611
diff
changeset
|
289 curpos = vfs_ftell(fp); |
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 else { |
706
6bc134eec1f3
[svn] - make use of the new id3_file_vfsopen() function.
nenolod
parents:
611
diff
changeset
|
292 if ((fp = vfs_fopen(file_info->filename, "rb")) == NULL) |
6bc134eec1f3
[svn] - make use of the new id3_file_vfsopen() function.
nenolod
parents:
611
diff
changeset
|
293 return; |
784
5ddfe9eac8ee
[svn] - fix read_replaygain(). necessary fseek was missing in reuse fd code. closes #843.
yaz
parents:
773
diff
changeset
|
294 } |
5ddfe9eac8ee
[svn] - fix read_replaygain(). necessary fseek was missing in reuse fd code. closes #843.
yaz
parents:
773
diff
changeset
|
295 |
5ddfe9eac8ee
[svn] - fix read_replaygain(). necessary fseek was missing in reuse fd code. closes #843.
yaz
parents:
773
diff
changeset
|
296 if (vfs_fseek(fp, 0L, SEEK_END) != 0) { |
5ddfe9eac8ee
[svn] - fix read_replaygain(). necessary fseek was missing in reuse fd code. closes #843.
yaz
parents:
773
diff
changeset
|
297 vfs_fclose(fp); |
5ddfe9eac8ee
[svn] - fix read_replaygain(). necessary fseek was missing in reuse fd code. closes #843.
yaz
parents:
773
diff
changeset
|
298 return; |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
299 } |
706
6bc134eec1f3
[svn] - make use of the new id3_file_vfsopen() function.
nenolod
parents:
611
diff
changeset
|
300 |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
301 long pos = vfs_ftell(fp); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
302 int res = -1; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
303 int try = 0; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
304 while (res != 0 && try < 10) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
305 // try skipping an id3 tag |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
306 vfs_fseek(fp, pos, SEEK_SET); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
307 vfs_fseek(fp, try * -128, SEEK_CUR); |
611 | 308 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
|
309 ++try; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
310 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
311 if (res != 0) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
312 // try brute search (don't want to parse all possible kinds of tags..) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
313 vfs_fseek(fp, pos, SEEK_SET); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
314 int offs = find_offset(fp); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
315 if (offs <= 0) { // found ! |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
316 vfs_fseek(fp, pos, SEEK_SET); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
317 vfs_fseek(fp, offs, SEEK_CUR); |
611 | 318 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
|
319 if (res != 0) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
320 g_message |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
321 ("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
|
322 offs, res); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
323 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
324 } |
773 | 325 #ifdef DEBUG |
326 else | |
327 g_message("replaygain: not found"); | |
328 #endif | |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
329 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
330 #ifdef DEBUG |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
331 if (res == 0) { // got APE tags, show the result |
799 | 332 gchar *tmp = g_filename_to_utf8(file_info->filename, -1, NULL, NULL, NULL); |
773 | 333 g_message("RG album scale= %g, RG track scale = %g, in %s", |
334 file_info->replaygain_album_scale, | |
799 | 335 file_info->replaygain_track_scale, tmp); |
336 g_free(tmp); | |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
337 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
338 #endif |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
339 |
611 | 340 if (file_info->replaygain_album_scale != -1 |
341 || file_info->replaygain_track_scale != -1) | |
342 file_info->has_replaygain = TRUE; | |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
343 |
713
3b609c9f538e
[svn] - reset position if we were passed a live FD.
nenolod
parents:
711
diff
changeset
|
344 if (file_info->infile) |
3b609c9f538e
[svn] - reset position if we were passed a live FD.
nenolod
parents:
711
diff
changeset
|
345 vfs_fseek(fp, curpos, SEEK_SET); |
3b609c9f538e
[svn] - reset position if we were passed a live FD.
nenolod
parents:
711
diff
changeset
|
346 |
773 | 347 vfs_fclose(fp); |
348 | |
349 #ifdef DEBUG | |
350 g_message("e: read_replaygain"); | |
351 #endif | |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
352 } |