Mercurial > audlegacy-plugins
annotate src/madplug/replaygain.c @ 2476:809736eb47d9
Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
(will be fixed in subsequent commits.)
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 30 Mar 2008 06:29:55 +0300 |
parents | 4ad6e7dfb389 |
children | ed6c81bd9016 |
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 |
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
|
68 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
|
69 { |
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
|
70 /* 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
|
71 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
|
72 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
|
73 |
809736eb47d9
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 (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
|
75 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
|
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 /* 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
|
78 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
|
79 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
|
80 |
809736eb47d9
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 /* 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
|
82 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
|
83 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
|
84 |
809736eb47d9
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 /* 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
|
86 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
|
87 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
|
88 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
|
89 |
809736eb47d9
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 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
|
91 } |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
92 |
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
|
93 // Reads APE v2.0 tag ending at current pos in 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
|
94 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
|
95 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
|
96 { |
809736eb47d9
Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents:
2392
diff
changeset
|
97 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
|
98 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
|
99 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
|
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 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
|
102 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
|
103 |
809736eb47d9
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 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
|
105 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
|
106 |
809736eb47d9
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 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
|
108 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
|
109 |
809736eb47d9
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 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
|
111 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
|
112 |
809736eb47d9
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 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
|
114 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
|
115 return 9; |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
116 } |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1978
diff
changeset
|
117 |
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
|
118 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
|
119 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
|
120 |
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
|
121 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
|
122 |
809736eb47d9
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 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
|
124 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
|
125 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
|
126 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
|
127 |
809736eb47d9
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 /* 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
|
129 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
|
130 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
|
131 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
|
132 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
|
133 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
|
134 |
809736eb47d9
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 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
|
136 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
|
137 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
|
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 |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
140 if (isize > 0 && vsize > 0) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
141 gdouble *scale = NULL; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
142 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
|
143 if (g_ascii_strcasecmp(p, "REPLAYGAIN_ALBUM_GAIN") == 0) { |
611 | 144 scale = &file_info->replaygain_album_scale; |
145 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
|
146 } 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
|
147 if (g_ascii_strcasecmp(p, "REPLAYGAIN_TRACK_GAIN") == 0) { |
611 | 148 scale = &file_info->replaygain_track_scale; |
149 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
|
150 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
151 if (str != NULL) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
152 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
|
153 *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
|
154 *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
|
155 } |
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
|
156 /* 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
|
157 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
|
158 if (g_ascii_strcasecmp(p, "REPLAYGAIN_TRACK_PEAK") == 0) { |
611 | 159 scale = &file_info->replaygain_track_peak; |
160 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
|
161 } 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
|
162 if (g_ascii_strcasecmp(p, "REPLAYGAIN_ALBUM_PEAK") == 0) { |
611 | 163 scale = &file_info->replaygain_album_peak; |
164 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
|
165 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
166 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
|
167 *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
|
168 *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
|
169 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
170 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
171 /* mp3gain additional tags : |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
172 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
|
173 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
|
174 -> 1.501*gain dB |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
175 */ |
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
|
176 if (g_ascii_strcasecmp(p, "MP3GAIN_UNDO") == 0) { |
611 | 177 str = &file_info->mp3gain_undo_str; |
178 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
|
179 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
|
180 *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
|
181 *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
|
182 } 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
|
183 if (g_ascii_strcasecmp(p, "MP3GAIN_MINMAX") == 0) { |
611 | 184 str = &file_info->mp3gain_minmax_str; |
185 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
|
186 *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
|
187 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
|
188 *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
|
189 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
190 } |
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
|
191 |
809736eb47d9
Some code sanitation and cleanups. Fixes some memory-access problems, but certain others still persist
Matti Hamalainen <ccr@tnsp.org>
parents:
2392
diff
changeset
|
192 p = tmp; |
610
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 g_free(buff); |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
196 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
197 return 0; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
198 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
199 |
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
|
200 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
|
201 findOffset(VFSFile * fp) |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
202 { |
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
|
203 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
|
204 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
|
205 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
|
206 |
809736eb47d9
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 (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
|
208 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
|
209 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
|
210 |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
211 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
|
212 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
|
213 ++matched; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
214 else { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
215 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
|
216 matched = 2; // got "APET" + "AP" |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
217 else |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
218 matched = 0; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
219 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
220 if (matched == 8) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
221 last_match = i; |
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 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
225 if (last_match == -1) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
226 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
|
227 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
|
228 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
229 |
1057
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
230 /* 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
|
231 * 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
|
232 */ |
809736eb47d9
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 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
|
234 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
|
235 { |
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
|
236 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
|
237 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
|
238 gchar *value; |
1057
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
239 struct id3_frame *frame; |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
240 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
241 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
|
242 |
1057
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
243 /* tag must be read before! */ |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
244 if (! file_info->tag ) { |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
245 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
|
246 return FALSE; |
1057
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 |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
249 /* 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
|
250 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
|
251 if (frame->nfields < 3) |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
252 continue; |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
253 |
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
|
254 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
|
255 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
|
256 |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
257 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
|
258 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
|
259 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
|
260 } 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
|
261 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
|
262 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
|
263 } 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
|
264 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
|
265 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
|
266 } 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
|
267 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
|
268 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
|
269 } |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
270 |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
271 free(key); |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
272 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
|
273 return TRUE; |
1057
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 |
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
|
276 return FALSE; |
1057
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
277 } |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
278 |
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
|
279 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
|
280 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
|
281 { |
710 | 282 VFSFile *fp; |
283 glong curpos = 0; | |
284 | |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
285 AUDDBG("f: read_replaygain\n"); |
773 | 286 |
2392
4ad6e7dfb389
imported 5298b10777b3 by Eugene Zagidullin.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2391
diff
changeset
|
287 file_info->replaygain_track_peak = 0.0; |
4ad6e7dfb389
imported 5298b10777b3 by Eugene Zagidullin.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2391
diff
changeset
|
288 file_info->replaygain_track_scale = 0.0; |
4ad6e7dfb389
imported 5298b10777b3 by Eugene Zagidullin.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2391
diff
changeset
|
289 file_info->replaygain_album_peak = 0.0; |
4ad6e7dfb389
imported 5298b10777b3 by Eugene Zagidullin.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2391
diff
changeset
|
290 file_info->replaygain_album_scale = 0.0; |
611 | 291 file_info->mp3gain_undo = -77; |
292 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
|
293 |
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
|
294 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
|
295 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
|
296 #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
|
297 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
|
298 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
299 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
|
300 file_info->replaygain_album_scale, |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
301 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
|
302 g_free(tmp); |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
303 #endif |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
304 return; |
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 |
ddb79127d9cf
[svn] - add support for reading id3v2 TXXX replaygain tag. patch by Eugene Zagidullin.
yaz
parents:
799
diff
changeset
|
308 /* APEv2 stuff */ |
706
6bc134eec1f3
[svn] - make use of the new id3_file_vfsopen() function.
nenolod
parents:
611
diff
changeset
|
309 if (file_info->infile) { |
1978 | 310 fp = aud_vfs_dup(file_info->infile); |
311 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
|
312 } |
5ddfe9eac8ee
[svn] - fix read_replaygain(). necessary fseek was missing in reuse fd code. closes #843.
yaz
parents:
773
diff
changeset
|
313 else { |
1978 | 314 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
|
315 return; |
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 |
1978 | 318 if (aud_vfs_fseek(fp, 0L, SEEK_END) != 0) { |
319 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
|
320 return; |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
321 } |
706
6bc134eec1f3
[svn] - make use of the new id3_file_vfsopen() function.
nenolod
parents:
611
diff
changeset
|
322 |
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
|
323 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
|
324 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
|
325 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
|
326 // try skipping an id3 tag |
1978 | 327 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
|
328 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
|
329 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
|
330 ++try_pos; |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
331 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
332 if (res != 0) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
333 // try brute search (don't want to parse all possible kinds of tags..) |
1978 | 334 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
|
335 gint offs = findOffset(fp); |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
336 if (offs <= 0) { // found ! |
1978 | 337 aud_vfs_fseek(fp, pos, SEEK_SET); |
338 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
|
339 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
|
340 if (res != 0) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
341 g_message |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
342 ("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
|
343 offs, res); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
344 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
345 } |
773 | 346 else |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
347 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
|
348 } |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1978
diff
changeset
|
349 #ifdef AUD_DEBUG |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
350 if (res == 0) { // got APE tags, show the result |
799 | 351 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
|
352 AUDDBG("RG album scale= %g, RG track scale = %g, in %s\n", |
773 | 353 file_info->replaygain_album_scale, |
799 | 354 file_info->replaygain_track_scale, tmp); |
355 g_free(tmp); | |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
356 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
357 #endif |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
358 |
713
3b609c9f538e
[svn] - reset position if we were passed a live FD.
nenolod
parents:
711
diff
changeset
|
359 if (file_info->infile) |
1978 | 360 aud_vfs_fseek(fp, curpos, SEEK_SET); |
713
3b609c9f538e
[svn] - reset position if we were passed a live FD.
nenolod
parents:
711
diff
changeset
|
361 |
1978 | 362 aud_vfs_fclose(fp); |
773 | 363 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
364 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
|
365 } |