annotate src/madplug/replaygain.c @ 2284:d19b53359b24

cleaned up the sndfile wav plugin, currently limiting it ONLY TO WAV PLAYBACK. if somebody is more experienced with it and wants to restore the other formats, go ahead (maybe change the name of the plugin too?).
author mf0102 <0102@gmx.at>
date Wed, 09 Jan 2008 15:41:22 +0100
parents d25cd7e7eddb
children 59addab003d7
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
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
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
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
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
75 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
76 return 18;
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
77 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
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;
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
86 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
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 }
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
91 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
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 }
2214
9a869d4bb0d3 make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1978
diff changeset
95
9a869d4bb0d3 make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1978
diff changeset
96 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
97 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
98
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
99 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
100 end = buff + TagLen - sizeof(T);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
101 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
102 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
103 p += 4;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
104 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
105 p += 4;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
106 isize = strlen((char *) p);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
107
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
108 if (isize > 0 && vsize > 0) {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
109 gdouble *scale = NULL;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
110 gchar **str = NULL;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
111 if (uncase_strcmp(p, "REPLAYGAIN_ALBUM_GAIN") == 0) {
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
112 scale = &file_info->replaygain_album_scale;
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
113 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
114 }
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_TRACK_GAIN") == 0) {
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
116 scale = &file_info->replaygain_track_scale;
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
117 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
118 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
119 if (str != NULL) {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
120 assert(scale != NULL);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
121 *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
122 *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
123 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
124 //* case of peak info tags : */
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
125 str = NULL;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
126 if (uncase_strcmp(p, "REPLAYGAIN_TRACK_PEAK") == 0) {
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
127 scale = &file_info->replaygain_track_peak;
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
128 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
129 }
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_ALBUM_PEAK") == 0) {
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
131 scale = &file_info->replaygain_album_peak;
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
132 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
133 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
134 if (str != NULL) {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
135 *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
136 *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
137 }
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 /* mp3gain additional tags :
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
140 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
141 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
142 -> 1.501*gain dB
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
143 */
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
144 if (uncase_strcmp(p, "MP3GAIN_UNDO") == 0) {
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
145 str = &file_info->mp3gain_undo_str;
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
146 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
147 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
148 *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
149 *scale = 1.50515 * atoi(*str);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
150 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
151 if (uncase_strcmp(p, "MP3GAIN_MINMAX") == 0) {
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
152 str = &file_info->mp3gain_minmax_str;
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
153 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
154 *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
155 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
156 *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
157 }
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 p += isize + 1 + vsize;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
160 }
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 free(buff);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
163
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
164 return 0;
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
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
167 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
168 {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
169 static const char *key = "APETAGEX";
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
170 char buff[20000];
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
171 int N = 0;
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
172 if (aud_vfs_fseek(fp, -20000, SEEK_CUR) != 0);
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
173 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
174 return 1;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
175 int matched = 0;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
176 int i, last_match = -1;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
177 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
178 if (buff[i] == key[matched])
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
179 ++matched;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
180 else {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
181 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
182 matched = 2; // got "APET" + "AP"
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
183 else
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
184 matched = 0;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
185 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
186 if (matched == 8) {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
187 last_match = i;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
188 matched = 0;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
189 }
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 (last_match == -1)
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
192 return 1;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
193 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
194 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
195
1057
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
196 /* Eugene Zagidullin:
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
197 * 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
198
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
199 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
200 {
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
201 int i;
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
202 char *key;
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
203 char *value;
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
204 struct id3_frame *frame;
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
205
2276
d25cd7e7eddb append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2214
diff changeset
206 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
207
1057
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
208 /* tag must be read before! */
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
209 if (! file_info->tag ) {
2276
d25cd7e7eddb append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2214
diff changeset
210 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
211 return 0;
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
212 }
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
213
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
214 /* 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
215 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
216 if (frame->nfields < 3)
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
217 continue;
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 key = (char *)
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
220 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
221 (&frame->fields[1]));
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
222 value = (char *)
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
223 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
224 (&frame->fields[2]));
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
225
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
226 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
227 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
228 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
229 } 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
230 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
231 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
232 } 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
233 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
234 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
235 } 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
236 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
237 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
238 }
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
239
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
240 free(key);
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
241 free(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 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
245 {
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
246 file_info->has_replaygain = TRUE;
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
247 return 1;
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
773
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 713
diff changeset
253 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
254 {
710
c75c2b332bce [svn] - C99 style enforcement
nenolod
parents: 709
diff changeset
255 VFSFile *fp;
c75c2b332bce [svn] - C99 style enforcement
nenolod
parents: 709
diff changeset
256 glong curpos = 0;
c75c2b332bce [svn] - C99 style enforcement
nenolod
parents: 709
diff changeset
257
2276
d25cd7e7eddb append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2214
diff changeset
258 AUDDBG("f: read_replaygain\n");
773
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 713
diff changeset
259
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
260 file_info->has_replaygain = FALSE;
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
261 file_info->replaygain_album_scale = -1;
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
262 file_info->replaygain_track_scale = -1;
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
263 file_info->mp3gain_undo = -77;
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
264 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
265
1057
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
266 if (ReadId3v2TXXX(file_info)) {
2214
9a869d4bb0d3 make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1978
diff changeset
267 #ifdef AUD_DEBUG
2276
d25cd7e7eddb append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2214
diff changeset
268 AUDDBG("found ReplayGain info in id3v2 tag\n");
1057
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
269
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
270 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
271 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
272 file_info->replaygain_album_scale,
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
273 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
274 g_free(tmp);
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
275 #endif
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
276 return;
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
277 }
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
278
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 /* APEv2 stuff */
706
6bc134eec1f3 [svn] - make use of the new id3_file_vfsopen() function.
nenolod
parents: 611
diff changeset
281 if (file_info->infile) {
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
282 fp = aud_vfs_dup(file_info->infile);
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
283 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
284 }
5ddfe9eac8ee [svn] - fix read_replaygain(). necessary fseek was missing in reuse fd code. closes #843.
yaz
parents: 773
diff changeset
285 else {
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
286 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
287 return;
784
5ddfe9eac8ee [svn] - fix read_replaygain(). necessary fseek was missing in reuse fd code. closes #843.
yaz
parents: 773
diff changeset
288 }
5ddfe9eac8ee [svn] - fix read_replaygain(). necessary fseek was missing in reuse fd code. closes #843.
yaz
parents: 773
diff changeset
289
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
290 if (aud_vfs_fseek(fp, 0L, SEEK_END) != 0) {
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
291 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
292 return;
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
293 }
706
6bc134eec1f3 [svn] - make use of the new id3_file_vfsopen() function.
nenolod
parents: 611
diff changeset
294
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
295 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
296 int res = -1;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
297 int try = 0;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
298 while (res != 0 && try < 10) {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
299 // try skipping an id3 tag
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
300 aud_vfs_fseek(fp, pos, SEEK_SET);
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
301 aud_vfs_fseek(fp, try * -128, SEEK_CUR);
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
302 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
303 ++try;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
304 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
305 if (res != 0) {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
306 // 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
307 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
308 int offs = find_offset(fp);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
309 if (offs <= 0) { // found !
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
310 aud_vfs_fseek(fp, pos, SEEK_SET);
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
311 aud_vfs_fseek(fp, offs, SEEK_CUR);
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
312 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
313 if (res != 0) {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
314 g_message
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
315 ("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
316 offs, res);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
317 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
318 }
2214
9a869d4bb0d3 make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1978
diff changeset
319 #ifdef AUD_DEBUG
773
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 713
diff changeset
320 else
2276
d25cd7e7eddb append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2214
diff changeset
321 AUDDBG("replaygain: not found\n");
773
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 713
diff changeset
322 #endif
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
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
334 if (file_info->replaygain_album_scale != -1
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
335 || file_info->replaygain_track_scale != -1)
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
336 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
337
713
3b609c9f538e [svn] - reset position if we were passed a live FD.
nenolod
parents: 711
diff changeset
338 if (file_info->infile)
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
339 aud_vfs_fseek(fp, curpos, SEEK_SET);
713
3b609c9f538e [svn] - reset position if we were passed a live FD.
nenolod
parents: 711
diff changeset
340
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
341 aud_vfs_fclose(fp);
773
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 713
diff changeset
342
2276
d25cd7e7eddb append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2214
diff changeset
343 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
344 }