annotate src/madplug/replaygain.c @ 3085:ac0af6b39272

Introduce new GIO plugin to buildsystem. stdio is now deprecated. Thoughts: - getc()/ungetc() should be moved to VFS core now
author William Pitcock <nenolod@atheme.org>
date Wed, 29 Apr 2009 20:58:36 -0500
parents f1b6f1b2cdb3
children bdfc90a5a183
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
2835
f1b6f1b2cdb3 fixed FSF address
Andrew O. Shadoura <bugzilla@tut.by>
parents: 2508
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
610
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
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
30 #define APE_MATCH_BUF (20000)
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
31 #define APE_HEADER_SIZE (32)
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
32 static const gchar *ape_header_magic_id = "APETAGEX";
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
33
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
34 typedef struct {
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
35 guchar id[8];
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
36 guint32 version;
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
37 guint32 length;
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
38 guint32 tagCount;
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
39 guint32 flags;
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
40 guchar reserved[8];
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
41 } ape_header_t;
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
42
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
43
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
44 static gboolean
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
45 fetchLE32(guint32 *res, gchar **ptr, const gchar *end)
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
46 {
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
47 if (*ptr + sizeof(guint32) > end)
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
48 return FALSE;
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
49 else {
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
50 *res = ((guint32) (*ptr)[0] ) |
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
51 ((guint32) (*ptr)[1] << 8) |
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
52 ((guint32) (*ptr)[2] << 16) |
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
53 ((guint32) (*ptr)[3] << 24);
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
54 (*ptr) += sizeof(guint32);
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
55 return TRUE;
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
56 }
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
2341
59addab003d7 - reworked replaygain to use individual pre-gain for the files with RG info and the rest.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2276
diff changeset
59 static gdouble
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
60 strgain2double(const gchar * s, const size_t len)
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
61 {
2391
7d1411f80023 imported 2b561aa49580 by Eugene Zagidullin.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2341
diff changeset
62 gchar *strval = g_strndup(s, len);
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
63 gdouble res = g_strtod(s, NULL); // gain, in dB.
2391
7d1411f80023 imported 2b561aa49580 by Eugene Zagidullin.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2341
diff changeset
64 g_free(strval);
7d1411f80023 imported 2b561aa49580 by Eugene Zagidullin.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2341
diff changeset
65 return res;
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
66 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
67
2497
ed6c81bd9016 Include cleanups, part #2.
Matti Hamalainen <ccr@tnsp.org>
parents: 2476
diff changeset
68 /* Check for APE tag header in current file position, and read
ed6c81bd9016 Include cleanups, part #2.
Matti Hamalainen <ccr@tnsp.org>
parents: 2476
diff changeset
69 * header data into given structure. Return 0 if OK.
ed6c81bd9016 Include cleanups, part #2.
Matti Hamalainen <ccr@tnsp.org>
parents: 2476
diff changeset
70 */
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
71 static gint checkAPEHeader(VFSFile * fp, ape_header_t *hdr)
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
72 {
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
73 /* Get magic id and check it */
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
74 if (aud_vfs_fread(&hdr->id, sizeof(hdr->id), 1, fp) != 1)
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
75 return 2;
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
76
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
77 if (memcmp(hdr->id, ape_header_magic_id, sizeof(hdr->id)) != 0)
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
78 return 3;
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
79
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
80 /* Currently we only support APEv2 */
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
81 if (!aud_vfs_fget_le32(&hdr->version, fp) || hdr->version != 2000)
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
82 return 4;
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
83
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
84 /* Validate header length */
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
85 if (!aud_vfs_fget_le32(&hdr->length, fp) || hdr->length < APE_HEADER_SIZE)
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
86 return 5;
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
87
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
88 /* Get other data */
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
89 if (!aud_vfs_fget_le32(&hdr->tagCount, fp) || !aud_vfs_fget_le32(&hdr->flags, fp) ||
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
90 aud_vfs_fread(&hdr->reserved, sizeof(hdr->reserved), 1, fp) != 1)
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
91 return 6;
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
92
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
93 return 0;
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
94 }
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
95
2497
ed6c81bd9016 Include cleanups, part #2.
Matti Hamalainen <ccr@tnsp.org>
parents: 2476
diff changeset
96 /* Reads APE v2.0 tag ending at current pos in fp
ed6c81bd9016 Include cleanups, part #2.
Matti Hamalainen <ccr@tnsp.org>
parents: 2476
diff changeset
97 */
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
98 static gint
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
99 readAPE2Tag(VFSFile * fp, struct mad_info_t *file_info)
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
100 {
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
101 gchar *buff, *p, *end;
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
102 gint res;
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
103 ape_header_t hdr;
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
104
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
105 if (aud_vfs_fseek(fp, -APE_HEADER_SIZE, SEEK_CUR) != 0)
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
106 return 18;
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
107
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
108 if ((res = checkAPEHeader(fp, &hdr)) != 0)
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
109 return res;
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
110
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
111 if (aud_vfs_fseek(fp, -hdr.length, SEEK_CUR) != 0)
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
112 return 7;
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
113
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
114 if ((buff = (gchar *) g_malloc(hdr.length)) == NULL)
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
115 return 8;
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
116
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
117 if (aud_vfs_fread(buff, hdr.length - APE_HEADER_SIZE, 1, fp) != 1) {
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
118 g_free(buff);
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
119 return 9;
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
120 }
2214
9a869d4bb0d3 make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1978
diff changeset
121
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
122 AUDDBG("ver = %ld\n", hdr.version);
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
123 AUDDBG("taglen = %ld\n", hdr.length);
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
124
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
125 end = buff + hdr.length - APE_HEADER_SIZE;
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
126
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
127 for (p = buff; p < end && hdr.tagCount--;) {
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
128 guint32 vsize, flags;
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
129 size_t isize;
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
130 gchar *tmp;
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
131
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
132 /* Get and check size and string */
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
133 if (!fetchLE32(&vsize, &p, end)) break;
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
134 if (!fetchLE32(&flags, &p, end)) break;
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
135 for (tmp = p, isize = 0; tmp < end && *tmp != 0; isize++, tmp++);
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
136 if (*tmp != 0) break;
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
137 tmp++;
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
138
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
139 if (isize > 0 && vsize > 0) {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
140 gdouble *scale = NULL;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
141 gchar **str = NULL;
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
142 if (g_ascii_strcasecmp(p, "REPLAYGAIN_ALBUM_GAIN") == 0) {
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
143 scale = &file_info->replaygain_album_scale;
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
144 str = &file_info->replaygain_album_str;
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
145 } else
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
146 if (g_ascii_strcasecmp(p, "REPLAYGAIN_TRACK_GAIN") == 0) {
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
147 scale = &file_info->replaygain_track_scale;
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
148 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
149 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
150 if (str != NULL) {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
151 assert(scale != NULL);
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
152 *scale = strgain2double(tmp, vsize);
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
153 *str = g_strndup(tmp, vsize);
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
154 }
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
155 /* case of peak info tags : */
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
156 str = NULL;
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
157 if (g_ascii_strcasecmp(p, "REPLAYGAIN_TRACK_PEAK") == 0) {
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
158 scale = &file_info->replaygain_track_peak;
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
159 str = &file_info->replaygain_track_peak_str;
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
160 } else
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
161 if (g_ascii_strcasecmp(p, "REPLAYGAIN_ALBUM_PEAK") == 0) {
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
162 scale = &file_info->replaygain_album_peak;
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
163 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
164 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
165 if (str != NULL) {
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
166 *scale = strgain2double(tmp, vsize);
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
167 *str = g_strndup(tmp, vsize);
610
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
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
170 /* mp3gain additional tags :
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
171 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
172 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
173 -> 1.501*gain dB
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
174 */
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
175 if (g_ascii_strcasecmp(p, "MP3GAIN_UNDO") == 0) {
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
176 str = &file_info->mp3gain_undo_str;
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
177 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
178 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
179 *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
180 *scale = 1.50515 * atoi(*str);
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
181 } else
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
182 if (g_ascii_strcasecmp(p, "MP3GAIN_MINMAX") == 0) {
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
183 str = &file_info->mp3gain_minmax_str;
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
184 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
185 *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
186 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
187 *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
188 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
189 }
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
190
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
191 p = tmp;
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
192 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
193
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
194 g_free(buff);
610
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 return 0;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
197 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
198
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
199 static gint
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
200 findOffset(VFSFile * fp)
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
201 {
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
202 gchar buff[APE_MATCH_BUF];
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
203 gint matched = 0, last_match = -1;
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
204 size_t N = 0, i;
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
205
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
206 if (aud_vfs_fseek(fp, - APE_MATCH_BUF, SEEK_CUR) != 0);
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
207 if ((N = aud_vfs_fread(buff, sizeof(gchar), APE_MATCH_BUF, fp)) < 16)
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
208 return 1;
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
209
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
210 for (i = 0; i < N; ++i) {
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
211 if (buff[i] == ape_header_magic_id[matched])
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
212 ++matched;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
213 else {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
214 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
215 matched = 2; // got "APET" + "AP"
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
216 else
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
217 matched = 0;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
218 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
219 if (matched == 8) {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
220 last_match = i;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
221 matched = 0;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
222 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
223 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
224 if (last_match == -1)
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
225 return 1;
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
226 return last_match + 1 - 8 + APE_HEADER_SIZE - N;
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
227 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
228
1057
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
229 /* Eugene Zagidullin:
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
230 * Read ReplayGain info from foobar2000-style id3v2 frames.
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
231 */
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
232 static gint
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
233 readId3v2TXXX(struct mad_info_t *file_info)
1057
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
234 {
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
235 gint i;
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
236 gchar *key;
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
237 gchar *value;
1057
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
238 struct id3_frame *frame;
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
239
2276
d25cd7e7eddb append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2214
diff changeset
240 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
241
1057
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
242 /* tag must be read before! */
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
243 if (! file_info->tag ) {
2276
d25cd7e7eddb append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2214
diff changeset
244 AUDDBG("id3v2 not found\n");
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
245 return FALSE;
1057
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 /* 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
249 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
250 if (frame->nfields < 3)
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
251 continue;
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
252
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
253 key = (gchar *) id3_ucs4_latin1duplicate(id3_field_getstring(&frame->fields[1]));
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
254 value = (gchar *) id3_ucs4_latin1duplicate(id3_field_getstring(&frame->fields[2]));
1057
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 if (strcasecmp(key, "replaygain_track_gain") == 0) {
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
257 file_info->replaygain_track_scale = g_strtod(value, NULL);
1057
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
258 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
259 } else if (strcasecmp(key, "replaygain_album_gain") == 0) {
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
260 file_info->replaygain_album_scale = g_strtod(value, NULL);
1057
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
261 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
262 } 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
263 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
264 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
265 } 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
266 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
267 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
268 }
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 free(key);
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
271 free(value);
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
272 return TRUE;
1057
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
273 }
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
274
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
275 return FALSE;
1057
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
276 }
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
277
2341
59addab003d7 - reworked replaygain to use individual pre-gain for the files with RG info and the rest.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2276
diff changeset
278 void
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
279 audmad_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
280 {
710
c75c2b332bce [svn] - C99 style enforcement
nenolod
parents: 709
diff changeset
281 VFSFile *fp;
c75c2b332bce [svn] - C99 style enforcement
nenolod
parents: 709
diff changeset
282 glong curpos = 0;
c75c2b332bce [svn] - C99 style enforcement
nenolod
parents: 709
diff changeset
283
2276
d25cd7e7eddb append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2214
diff changeset
284 AUDDBG("f: read_replaygain\n");
773
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 713
diff changeset
285
2392
4ad6e7dfb389 imported 5298b10777b3 by Eugene Zagidullin.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2391
diff changeset
286 file_info->replaygain_track_peak = 0.0;
4ad6e7dfb389 imported 5298b10777b3 by Eugene Zagidullin.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2391
diff changeset
287 file_info->replaygain_track_scale = 0.0;
4ad6e7dfb389 imported 5298b10777b3 by Eugene Zagidullin.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2391
diff changeset
288 file_info->replaygain_album_peak = 0.0;
4ad6e7dfb389 imported 5298b10777b3 by Eugene Zagidullin.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2391
diff changeset
289 file_info->replaygain_album_scale = 0.0;
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
290 file_info->mp3gain_undo = -77;
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
291 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
292
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
293 if (readId3v2TXXX(file_info)) {
2341
59addab003d7 - reworked replaygain to use individual pre-gain for the files with RG info and the rest.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2276
diff changeset
294 AUDDBG("found ReplayGain info in id3v2 tag\n");
2214
9a869d4bb0d3 make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1978
diff changeset
295 #ifdef AUD_DEBUG
2341
59addab003d7 - reworked replaygain to use individual pre-gain for the files with RG info and the rest.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2276
diff changeset
296 gchar *tmp = g_filename_to_utf8(file_info->filename, -1, NULL, NULL, NULL);
1057
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
297
2276
d25cd7e7eddb append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2214
diff changeset
298 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
299 file_info->replaygain_album_scale,
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
300 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
301 g_free(tmp);
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
302 #endif
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
303 return;
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
304 }
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
305
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
306
ddb79127d9cf [svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents: 799
diff changeset
307 /* APEv2 stuff */
706
6bc134eec1f3 [svn] - make use of the new id3_file_vfsopen() function.
nenolod
parents: 611
diff changeset
308 if (file_info->infile) {
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
309 fp = aud_vfs_dup(file_info->infile);
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
310 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
311 }
5ddfe9eac8ee [svn] - fix read_replaygain(). necessary fseek was missing in reuse fd code. closes #843.
yaz
parents: 773
diff changeset
312 else {
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
313 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
314 return;
784
5ddfe9eac8ee [svn] - fix read_replaygain(). necessary fseek was missing in reuse fd code. closes #843.
yaz
parents: 773
diff changeset
315 }
5ddfe9eac8ee [svn] - fix read_replaygain(). necessary fseek was missing in reuse fd code. closes #843.
yaz
parents: 773
diff changeset
316
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
317 if (aud_vfs_fseek(fp, 0L, SEEK_END) != 0) {
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
318 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
319 return;
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
320 }
706
6bc134eec1f3 [svn] - make use of the new id3_file_vfsopen() function.
nenolod
parents: 611
diff changeset
321
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
322 glong pos = aud_vfs_ftell(fp);
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
323 gint res = -1, try_pos = 0;
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
324 while (res != 0 && try_pos < 10) {
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
325 // try skipping an id3 tag
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
326 aud_vfs_fseek(fp, pos, SEEK_SET);
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
327 aud_vfs_fseek(fp, try_pos * -128, SEEK_CUR);
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
328 res = readAPE2Tag(fp, file_info);
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
329 ++try_pos;
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
330 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
331 if (res != 0) {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
332 // 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
333 aud_vfs_fseek(fp, pos, SEEK_SET);
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
334 gint offs = findOffset(fp);
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
335 if (offs <= 0) { // found !
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
336 aud_vfs_fseek(fp, pos, SEEK_SET);
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
337 aud_vfs_fseek(fp, offs, SEEK_CUR);
2476
809736eb47d9 Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
338 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
339 if (res != 0) {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
340 g_message
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
341 ("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
342 offs, res);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
343 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
344 }
773
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 713
diff changeset
345 else
2276
d25cd7e7eddb append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2214
diff changeset
346 AUDDBG("replaygain: not found\n");
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
347 }
2214
9a869d4bb0d3 make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1978
diff changeset
348 #ifdef AUD_DEBUG
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
349 if (res == 0) { // got APE tags, show the result
799
d200de50a1fc [svn] - convert filename into utf8 in debug messages.
yaz
parents: 784
diff changeset
350 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
351 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
352 file_info->replaygain_album_scale,
799
d200de50a1fc [svn] - convert filename into utf8 in debug messages.
yaz
parents: 784
diff changeset
353 file_info->replaygain_track_scale, tmp);
d200de50a1fc [svn] - convert filename into utf8 in debug messages.
yaz
parents: 784
diff changeset
354 g_free(tmp);
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
355 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
356 #endif
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
357
713
3b609c9f538e [svn] - reset position if we were passed a live FD.
nenolod
parents: 711
diff changeset
358 if (file_info->infile)
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
359 aud_vfs_fseek(fp, curpos, SEEK_SET);
713
3b609c9f538e [svn] - reset position if we were passed a live FD.
nenolod
parents: 711
diff changeset
360
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1057
diff changeset
361 aud_vfs_fclose(fp);
773
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 713
diff changeset
362
2276
d25cd7e7eddb append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2214
diff changeset
363 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
364 }