Mercurial > audlegacy-plugins
annotate src/madplug/replaygain.c @ 2499:4d6045c20cc5
Include cleanups, part #4.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 31 Mar 2008 15:18:05 +0300 |
parents | ed6c81bd9016 |
children | 9fd51b549097 |
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 |
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 |
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
|
139 fprintf(stderr, "wtf: vsize=%x, flags=%x, s=%s\n", vsize, flags, p); |
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
|
140 if (vsize > end - tmp + 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
|
141 fprintf(stderr, "vsize > end - tmp + 1: %d > %d\n", vsize, end - tmp + 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
|
142 } |
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
|
143 |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
144 if (isize > 0 && vsize > 0) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
145 gdouble *scale = NULL; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
146 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
|
147 if (g_ascii_strcasecmp(p, "REPLAYGAIN_ALBUM_GAIN") == 0) { |
611 | 148 scale = &file_info->replaygain_album_scale; |
149 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
|
150 } 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
|
151 if (g_ascii_strcasecmp(p, "REPLAYGAIN_TRACK_GAIN") == 0) { |
611 | 152 scale = &file_info->replaygain_track_scale; |
153 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
|
154 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
155 if (str != NULL) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
156 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
|
157 *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
|
158 *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
|
159 } |
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 /* 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
|
161 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
|
162 if (g_ascii_strcasecmp(p, "REPLAYGAIN_TRACK_PEAK") == 0) { |
611 | 163 scale = &file_info->replaygain_track_peak; |
164 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
|
165 } 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
|
166 if (g_ascii_strcasecmp(p, "REPLAYGAIN_ALBUM_PEAK") == 0) { |
611 | 167 scale = &file_info->replaygain_album_peak; |
168 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
|
169 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
170 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
|
171 *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
|
172 *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
|
173 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
174 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
175 /* mp3gain additional tags : |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
176 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
|
177 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
|
178 -> 1.501*gain dB |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
179 */ |
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
|
180 if (g_ascii_strcasecmp(p, "MP3GAIN_UNDO") == 0) { |
611 | 181 str = &file_info->mp3gain_undo_str; |
182 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
|
183 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
|
184 *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
|
185 *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
|
186 } 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
|
187 if (g_ascii_strcasecmp(p, "MP3GAIN_MINMAX") == 0) { |
611 | 188 str = &file_info->mp3gain_minmax_str; |
189 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
|
190 *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
|
191 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
|
192 *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
|
193 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
194 } |
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
|
195 |
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
|
196 p = tmp; |
610
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 g_free(buff); |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
200 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
201 return 0; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
202 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
203 |
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
|
204 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
|
205 findOffset(VFSFile * fp) |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
206 { |
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
|
207 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
|
208 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
|
209 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
|
210 |
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 (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
|
212 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
|
213 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
|
214 |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
215 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
|
216 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
|
217 ++matched; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
218 else { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
219 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
|
220 matched = 2; // got "APET" + "AP" |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
221 else |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
222 matched = 0; |
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 (matched == 8) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
225 last_match = i; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
226 matched = 0; |
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 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
229 if (last_match == -1) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
230 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
|
231 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
|
232 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
233 |
1057
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
234 /* 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
|
235 * 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
|
236 */ |
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 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
|
238 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
|
239 { |
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
|
240 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
|
241 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
|
242 gchar *value; |
1057
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
243 struct id3_frame *frame; |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
244 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
245 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
|
246 |
1057
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
247 /* tag must be read before! */ |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
248 if (! file_info->tag ) { |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
249 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
|
250 return FALSE; |
1057
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 |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
253 /* 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
|
254 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
|
255 if (frame->nfields < 3) |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
256 continue; |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
257 |
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
|
258 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
|
259 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
|
260 |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
261 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
|
262 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
|
263 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
|
264 } 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
|
265 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
|
266 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
|
267 } 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
|
268 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
|
269 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
|
270 } 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
|
271 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
|
272 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
|
273 } |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
274 |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
275 free(key); |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
276 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
|
277 return TRUE; |
1057
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 |
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
|
280 return FALSE; |
1057
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
281 } |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
282 |
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
|
283 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
|
284 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
|
285 { |
710 | 286 VFSFile *fp; |
287 glong curpos = 0; | |
288 | |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
289 AUDDBG("f: read_replaygain\n"); |
773 | 290 |
2392
4ad6e7dfb389
imported 5298b10777b3 by Eugene Zagidullin.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2391
diff
changeset
|
291 file_info->replaygain_track_peak = 0.0; |
4ad6e7dfb389
imported 5298b10777b3 by Eugene Zagidullin.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2391
diff
changeset
|
292 file_info->replaygain_track_scale = 0.0; |
4ad6e7dfb389
imported 5298b10777b3 by Eugene Zagidullin.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2391
diff
changeset
|
293 file_info->replaygain_album_peak = 0.0; |
4ad6e7dfb389
imported 5298b10777b3 by Eugene Zagidullin.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2391
diff
changeset
|
294 file_info->replaygain_album_scale = 0.0; |
611 | 295 file_info->mp3gain_undo = -77; |
296 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
|
297 |
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
|
298 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
|
299 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
|
300 #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
|
301 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
|
302 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
303 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
|
304 file_info->replaygain_album_scale, |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
305 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
|
306 g_free(tmp); |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
307 #endif |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
308 return; |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
309 } |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
310 |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
311 |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
312 /* APEv2 stuff */ |
706
6bc134eec1f3
[svn] - make use of the new id3_file_vfsopen() function.
nenolod
parents:
611
diff
changeset
|
313 if (file_info->infile) { |
1978 | 314 fp = aud_vfs_dup(file_info->infile); |
315 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
|
316 } |
5ddfe9eac8ee
[svn] - fix read_replaygain(). necessary fseek was missing in reuse fd code. closes #843.
yaz
parents:
773
diff
changeset
|
317 else { |
1978 | 318 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
|
319 return; |
784
5ddfe9eac8ee
[svn] - fix read_replaygain(). necessary fseek was missing in reuse fd code. closes #843.
yaz
parents:
773
diff
changeset
|
320 } |
5ddfe9eac8ee
[svn] - fix read_replaygain(). necessary fseek was missing in reuse fd code. closes #843.
yaz
parents:
773
diff
changeset
|
321 |
1978 | 322 if (aud_vfs_fseek(fp, 0L, SEEK_END) != 0) { |
323 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
|
324 return; |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
325 } |
706
6bc134eec1f3
[svn] - make use of the new id3_file_vfsopen() function.
nenolod
parents:
611
diff
changeset
|
326 |
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 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
|
328 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
|
329 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
|
330 // try skipping an id3 tag |
1978 | 331 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
|
332 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
|
333 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
|
334 ++try_pos; |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
335 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
336 if (res != 0) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
337 // try brute search (don't want to parse all possible kinds of tags..) |
1978 | 338 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
|
339 gint offs = findOffset(fp); |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
340 if (offs <= 0) { // found ! |
1978 | 341 aud_vfs_fseek(fp, pos, SEEK_SET); |
342 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
|
343 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
|
344 if (res != 0) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
345 g_message |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
346 ("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
|
347 offs, res); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
348 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
349 } |
773 | 350 else |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
351 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
|
352 } |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1978
diff
changeset
|
353 #ifdef AUD_DEBUG |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
354 if (res == 0) { // got APE tags, show the result |
799 | 355 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
|
356 AUDDBG("RG album scale= %g, RG track scale = %g, in %s\n", |
773 | 357 file_info->replaygain_album_scale, |
799 | 358 file_info->replaygain_track_scale, tmp); |
359 g_free(tmp); | |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
360 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
361 #endif |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
362 |
713
3b609c9f538e
[svn] - reset position if we were passed a live FD.
nenolod
parents:
711
diff
changeset
|
363 if (file_info->infile) |
1978 | 364 aud_vfs_fseek(fp, curpos, SEEK_SET); |
713
3b609c9f538e
[svn] - reset position if we were passed a live FD.
nenolod
parents:
711
diff
changeset
|
365 |
1978 | 366 aud_vfs_fclose(fp); |
773 | 367 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
368 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
|
369 } |