Mercurial > audlegacy-plugins
annotate src/madplug/decoder.c @ 3085:ac0af6b39272
Introduce new GIO plugin to buildsystem. stdio is now deprecated.
Thoughts:
- getc()/ungetc() should be moved to VFS core now
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Wed, 29 Apr 2009 20:58:36 -0500 |
parents | eb7348ab56d2 |
children |
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 * |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
8 * 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
|
9 * 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
|
10 * 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
|
11 * |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
12 * 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
|
13 * 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
|
14 * 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
|
15 * 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
|
16 * |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
17 * 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
|
18 * along with this program; if not, write to the Free Software |
2835 | 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
20 */ |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
21 |
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:
2340
diff
changeset
|
22 /* #define AUD_DEBUG 1 */ |
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:
2340
diff
changeset
|
23 |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
24 #include <math.h> |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
25 #include <assert.h> |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
26 |
2971
3134a0987162
- changed include path from audacious to audlegacy.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
2835
diff
changeset
|
27 #include <audlegacy/plugin.h> |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
28 #include "plugin.h" |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
29 #include "input.h" |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
30 |
2514
bad05467e8e0
A numeric #define with an expression not enclosed in parentheses is dangerous.
Matti Hamalainen <ccr@tnsp.org>
parents:
2491
diff
changeset
|
31 #define BUFFER_SIZE (16*1024) |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
32 #define N_AVERAGE_FRAMES 10 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
33 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
34 void |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
35 write_output(struct mad_info_t *info, struct mad_pcm *pcm, |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
36 struct mad_header *header) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
37 { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
38 unsigned int nsamples; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
39 mad_fixed_t const *left_ch, *right_ch; |
2390
bd9673d8b7d5
converted to new sound engine scheme.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2344
diff
changeset
|
40 mad_fixed_t *output; |
bd9673d8b7d5
converted to new sound engine scheme.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2344
diff
changeset
|
41 int outlen = 0; |
bd9673d8b7d5
converted to new sound engine scheme.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2344
diff
changeset
|
42 int outbyte = 0; |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
43 int pos = 0; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
44 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
45 nsamples = pcm->length; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
46 left_ch = pcm->samples[0]; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
47 right_ch = pcm->samples[1]; |
2390
bd9673d8b7d5
converted to new sound engine scheme.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2344
diff
changeset
|
48 outlen = nsamples * MAD_NCHANNELS(header); |
bd9673d8b7d5
converted to new sound engine scheme.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2344
diff
changeset
|
49 outbyte = outlen * sizeof(mad_fixed_t); |
bd9673d8b7d5
converted to new sound engine scheme.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2344
diff
changeset
|
50 |
bd9673d8b7d5
converted to new sound engine scheme.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2344
diff
changeset
|
51 output = (mad_fixed_t *) g_malloc(outbyte); |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
52 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
53 while (nsamples--) { |
2390
bd9673d8b7d5
converted to new sound engine scheme.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2344
diff
changeset
|
54 output[pos++] = *left_ch++; |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
55 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
56 if (MAD_NCHANNELS(header) == 2) { |
2390
bd9673d8b7d5
converted to new sound engine scheme.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2344
diff
changeset
|
57 output[pos++] = *right_ch++; |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
58 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
59 } |
2390
bd9673d8b7d5
converted to new sound engine scheme.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2344
diff
changeset
|
60 |
bd9673d8b7d5
converted to new sound engine scheme.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2344
diff
changeset
|
61 assert(pos == outlen); |
2287
2421c87fb855
Fix memory leak in mad plugin when changing songs and writing output. (Bugzilla #82)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
2276
diff
changeset
|
62 if (!info->playback->playing) { |
2421c87fb855
Fix memory leak in mad plugin when changing songs and writing output. (Bugzilla #82)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
2276
diff
changeset
|
63 g_free(output); |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
64 return; |
2287
2421c87fb855
Fix memory leak in mad plugin when changing songs and writing output. (Bugzilla #82)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
2276
diff
changeset
|
65 } |
2390
bd9673d8b7d5
converted to new sound engine scheme.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2344
diff
changeset
|
66 |
1998
8f3188746b64
chase last changeset in aud
William Pitcock <nenolod@atheme.org>
parents:
1985
diff
changeset
|
67 info->playback->pass_audio(info->playback, |
2390
bd9673d8b7d5
converted to new sound engine scheme.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2344
diff
changeset
|
68 info->fmt, MAD_NCHANNELS(header), outbyte, output, |
bd9673d8b7d5
converted to new sound engine scheme.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2344
diff
changeset
|
69 &(info->playback->playing)); |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
70 g_free(output); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
71 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
72 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
73 /** |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
74 * Decode all headers in the file and fill in stats |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
75 * @return FALSE if scan failed. |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
76 */ |
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:
2340
diff
changeset
|
77 gboolean |
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:
2340
diff
changeset
|
78 scan_file(struct mad_info_t * info, gboolean fast) |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
79 { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
80 struct mad_stream stream; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
81 struct mad_header header; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
82 int remainder = 0; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
83 int data_used = 0; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
84 int len = 0; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
85 int tagsize = 0; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
86 unsigned char buffer[BUFFER_SIZE]; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
87 struct mad_frame frame; /* to read xing data */ |
1162
29519d604e8c
[svn] - revise bitrate calculation with xing header. if number of bytes and number of frames are available in xing header, fast play time calculation yields almost appropriate duration upon a vbr file.
yaz
parents:
997
diff
changeset
|
88 guint bitrate_frames = 0; |
29519d604e8c
[svn] - revise bitrate calculation with xing header. if number of bytes and number of frames are available in xing header, fast play time calculation yields almost appropriate duration upon a vbr file.
yaz
parents:
997
diff
changeset
|
89 double xing_bitrate = 0.0; |
980
6ba4a4bfd127
[svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents:
959
diff
changeset
|
90 double accum_bitrate = 0.0; |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
91 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
92 mad_stream_init(&stream); |
980
6ba4a4bfd127
[svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents:
959
diff
changeset
|
93 mad_stream_options(&stream, 0); // check CRC |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
94 mad_header_init(&header); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
95 mad_frame_init(&frame); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
96 xing_init(&info->xing); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
97 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
98 info->bitrate = 0; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
99 info->pos = mad_timer_zero; |
773 | 100 info->duration = mad_timer_zero; // should be cleared before loop, if we use it as break condition. |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
101 |
997
e46b98155d5d
[svn] - fix a bug which counts number of frames twice in handling xing header.
yaz
parents:
980
diff
changeset
|
102 if(info->fileinfo_request == TRUE) { |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1687
diff
changeset
|
103 aud_tuple_associate_int(info->tuple, FIELD_LENGTH, NULL, -1); |
997
e46b98155d5d
[svn] - fix a bug which counts number of frames twice in handling xing header.
yaz
parents:
980
diff
changeset
|
104 info->fileinfo_request = FALSE; |
e46b98155d5d
[svn] - fix a bug which counts number of frames twice in handling xing header.
yaz
parents:
980
diff
changeset
|
105 } |
e46b98155d5d
[svn] - fix a bug which counts number of frames twice in handling xing header.
yaz
parents:
980
diff
changeset
|
106 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
107 AUDDBG("f: scan_file\n"); |
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
108 AUDDBG("scan_file frames = %d\n", info->frames); |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
109 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
110 while (1) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
111 remainder = stream.bufend - stream.next_frame; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
112 |
2415 | 113 if(buffer != stream.this_frame && remainder) |
114 memmove(buffer, stream.this_frame, remainder); | |
115 | |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
116 len = input_get_data(info, buffer + remainder, |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
117 BUFFER_SIZE - remainder); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
118 |
773 | 119 if (len <= 0) { |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
120 AUDDBG("scan_file: len <= 0 len = %d\n", len); |
792
2b2313fc1ddc
[svn] - I was noticed vfs_fread check still causes problem. disable for now.
yaz
parents:
789
diff
changeset
|
121 break; |
773 | 122 } |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
123 |
2415 | 124 mad_stream_buffer(&stream, buffer, remainder + len); |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
125 |
674 | 126 while (!fast || (fast && info->frames < N_AVERAGE_FRAMES)) { |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
127 if (mad_header_decode(&header, &stream) == -1) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
128 if (stream.error == MAD_ERROR_BUFLEN) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
129 break; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
130 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
131 if (!MAD_RECOVERABLE(stream.error)) { |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
132 AUDDBG("(fatal) error decoding header %d: %s\n", |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
133 info->frames, mad_stream_errorstr(&stream)); |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
134 AUDDBG("remainder = %d\n", remainder); |
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
135 AUDDBG("len = %d\n", len); |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
136 break; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
137 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
138 if (stream.error == MAD_ERROR_LOSTSYNC) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
139 /* ignore LOSTSYNC due to ID3 tags */ |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
140 tagsize = id3_tag_query(stream.this_frame, |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
141 stream.bufend - |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
142 stream.this_frame); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
143 if (tagsize > 0) { |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
144 AUDDBG("skipping id3_tag: %d\n", tagsize); |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
145 mad_stream_skip(&stream, tagsize); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
146 continue; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
147 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
148 } |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
149 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
150 AUDDBG("(recovered) error decoding header %d: %s\n", |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
151 info->frames, mad_stream_errorstr(&stream)); |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
152 AUDDBG("remainder = %d\n", remainder); |
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
153 AUDDBG("len = %d\n", len); |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
154 |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
155 continue; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
156 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
157 info->frames++; |
674 | 158 |
611 | 159 #ifdef DEBUG_INTENSIVELY |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
160 AUDDBG("header bitrate = %ld\n", header.bitrate); |
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
161 AUDDBG("duration = %ul\n", |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
162 mad_timer_count(header.duration, |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
163 MAD_UNITS_MILLISECONDS)); |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
164 AUDDBG("size = %d\n", stream.next_frame - stream.this_frame); |
611 | 165 #endif |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1687
diff
changeset
|
166 if(aud_tuple_get_int(info->tuple, FIELD_LENGTH, NULL) == -1) |
738 | 167 mad_timer_add(&info->duration, header.duration); |
168 else { | |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1687
diff
changeset
|
169 gint length = aud_tuple_get_int(info->tuple, FIELD_LENGTH, NULL); |
1428
4993976d7ed0
madplug: tuple API changes
William Pitcock <nenolod@atheme-project.org>
parents:
1344
diff
changeset
|
170 |
4993976d7ed0
madplug: tuple API changes
William Pitcock <nenolod@atheme-project.org>
parents:
1344
diff
changeset
|
171 info->duration.seconds = length / 1000; |
4993976d7ed0
madplug: tuple API changes
William Pitcock <nenolod@atheme-project.org>
parents:
1344
diff
changeset
|
172 info->duration.fraction = length % 1000; |
738 | 173 } |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
174 data_used += stream.next_frame - stream.this_frame; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
175 if (info->frames == 1) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
176 /* most of these *should* remain constant */ |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
177 info->bitrate = header.bitrate; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
178 info->freq = header.samplerate; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
179 info->channels = MAD_NCHANNELS(&header); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
180 info->mpeg_layer = header.layer; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
181 info->mode = header.mode; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
182 |
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:
2340
diff
changeset
|
183 if (audmad_config->use_xing) { |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
184 frame.header = header; |
674 | 185 if (mad_frame_decode(&frame, &stream) == -1) { |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
186 AUDDBG("xing frame decode failed\n"); |
674 | 187 goto no_xing; |
188 } | |
980
6ba4a4bfd127
[svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents:
959
diff
changeset
|
189 if (xing_parse(&info->xing, stream.anc_ptr, stream.anc_bitlen) == 0) { |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
190 AUDDBG("xing header found\n"); |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
191 info->vbr = TRUE; /* otherwise xing header would have been 'Info' */ |
1162
29519d604e8c
[svn] - revise bitrate calculation with xing header. if number of bytes and number of frames are available in xing header, fast play time calculation yields almost appropriate duration upon a vbr file.
yaz
parents:
997
diff
changeset
|
192 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
193 AUDDBG("xing: bytes = %ld frames = %ld\n", info->xing.bytes, info->xing.frames); |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
194 |
1162
29519d604e8c
[svn] - revise bitrate calculation with xing header. if number of bytes and number of frames are available in xing header, fast play time calculation yields almost appropriate duration upon a vbr file.
yaz
parents:
997
diff
changeset
|
195 /* we have enough info to calculate bitrate and duration */ |
29519d604e8c
[svn] - revise bitrate calculation with xing header. if number of bytes and number of frames are available in xing header, fast play time calculation yields almost appropriate duration upon a vbr file.
yaz
parents:
997
diff
changeset
|
196 if(info->xing.bytes && info->xing.frames) { |
29519d604e8c
[svn] - revise bitrate calculation with xing header. if number of bytes and number of frames are available in xing header, fast play time calculation yields almost appropriate duration upon a vbr file.
yaz
parents:
997
diff
changeset
|
197 xing_bitrate = 8 * (double)info->xing.bytes * 38 / (double)info->xing.frames; //38fps in MPEG1. |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
198 #ifdef AUD_DEBUG |
1162
29519d604e8c
[svn] - revise bitrate calculation with xing header. if number of bytes and number of frames are available in xing header, fast play time calculation yields almost appropriate duration upon a vbr file.
yaz
parents:
997
diff
changeset
|
199 { |
29519d604e8c
[svn] - revise bitrate calculation with xing header. if number of bytes and number of frames are available in xing header, fast play time calculation yields almost appropriate duration upon a vbr file.
yaz
parents:
997
diff
changeset
|
200 gint tmp = (gint)(info->xing.bytes * 8 / xing_bitrate); |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
201 AUDDBG("xing: bitrate = %4.1f kbps\n", xing_bitrate / 1000); |
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
202 AUDDBG("xing: duration = %d:%02d\n", tmp / 60, tmp % 60); |
1162
29519d604e8c
[svn] - revise bitrate calculation with xing header. if number of bytes and number of frames are available in xing header, fast play time calculation yields almost appropriate duration upon a vbr file.
yaz
parents:
997
diff
changeset
|
203 } |
29519d604e8c
[svn] - revise bitrate calculation with xing header. if number of bytes and number of frames are available in xing header, fast play time calculation yields almost appropriate duration upon a vbr file.
yaz
parents:
997
diff
changeset
|
204 #endif |
738 | 205 } |
959 | 206 continue; |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
207 } |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
208 #ifdef AUD_DEBUG |
980
6ba4a4bfd127
[svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents:
959
diff
changeset
|
209 else { |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
210 AUDDBG("no usable xing header\n"); |
980
6ba4a4bfd127
[svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents:
959
diff
changeset
|
211 continue; |
6ba4a4bfd127
[svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents:
959
diff
changeset
|
212 } |
6ba4a4bfd127
[svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents:
959
diff
changeset
|
213 #endif |
6ba4a4bfd127
[svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents:
959
diff
changeset
|
214 } /* xing */ |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
215 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
216 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
217 else { |
980
6ba4a4bfd127
[svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents:
959
diff
changeset
|
218 /* perhaps we have a VBR file */ |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
219 if (info->bitrate != header.bitrate) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
220 info->vbr = TRUE; |
673 | 221 if (info->vbr) { |
980
6ba4a4bfd127
[svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents:
959
diff
changeset
|
222 accum_bitrate += (double)header.bitrate; |
673 | 223 bitrate_frames++; |
224 } | |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
225 /* check for changin layer/samplerate/channels */ |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
226 if (info->mpeg_layer != header.layer) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
227 g_warning("layer varies!!"); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
228 if (info->freq != header.samplerate) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
229 g_warning("samplerate varies!!"); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
230 if (info->channels != MAD_NCHANNELS(&header)) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
231 g_warning("number of channels varies!!"); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
232 } |
674 | 233 no_xing: |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
234 if (fast && info->frames >= N_AVERAGE_FRAMES) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
235 float frame_size = ((double) data_used) / N_AVERAGE_FRAMES; |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
236 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
237 AUDDBG("bitrate = %ld samplerate = %d\n", header.bitrate, header.samplerate); |
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
238 AUDDBG("data_used = %d info->frames = %d info->size = %d tagsize = %d frame_size = %lf\n", |
980
6ba4a4bfd127
[svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents:
959
diff
changeset
|
239 data_used, info->frames, info->size, tagsize, frame_size); |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
240 |
773 | 241 if(info->size != 0) |
242 info->frames = (info->size - tagsize) / frame_size; | |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
243 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
244 AUDDBG("info->frames = %d\n", info->frames); |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
245 |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1687
diff
changeset
|
246 if(aud_tuple_get_int(info->tuple, FIELD_LENGTH, NULL) == -1) { |
1162
29519d604e8c
[svn] - revise bitrate calculation with xing header. if number of bytes and number of frames are available in xing header, fast play time calculation yields almost appropriate duration upon a vbr file.
yaz
parents:
997
diff
changeset
|
247 if(xing_bitrate > 0.0) { |
29519d604e8c
[svn] - revise bitrate calculation with xing header. if number of bytes and number of frames are available in xing header, fast play time calculation yields almost appropriate duration upon a vbr file.
yaz
parents:
997
diff
changeset
|
248 /* calc duration with xing info */ |
29519d604e8c
[svn] - revise bitrate calculation with xing header. if number of bytes and number of frames are available in xing header, fast play time calculation yields almost appropriate duration upon a vbr file.
yaz
parents:
997
diff
changeset
|
249 double tmp = 8 * (double)info->xing.bytes * 1000 / xing_bitrate; |
29519d604e8c
[svn] - revise bitrate calculation with xing header. if number of bytes and number of frames are available in xing header, fast play time calculation yields almost appropriate duration upon a vbr file.
yaz
parents:
997
diff
changeset
|
250 info->duration.seconds = (guint)(tmp / 1000); |
29519d604e8c
[svn] - revise bitrate calculation with xing header. if number of bytes and number of frames are available in xing header, fast play time calculation yields almost appropriate duration upon a vbr file.
yaz
parents:
997
diff
changeset
|
251 info->duration.fraction = (guint)(tmp - info->duration.seconds * 1000); |
29519d604e8c
[svn] - revise bitrate calculation with xing header. if number of bytes and number of frames are available in xing header, fast play time calculation yields almost appropriate duration upon a vbr file.
yaz
parents:
997
diff
changeset
|
252 } |
29519d604e8c
[svn] - revise bitrate calculation with xing header. if number of bytes and number of frames are available in xing header, fast play time calculation yields almost appropriate duration upon a vbr file.
yaz
parents:
997
diff
changeset
|
253 else { |
29519d604e8c
[svn] - revise bitrate calculation with xing header. if number of bytes and number of frames are available in xing header, fast play time calculation yields almost appropriate duration upon a vbr file.
yaz
parents:
997
diff
changeset
|
254 info->duration.seconds /= N_AVERAGE_FRAMES; |
29519d604e8c
[svn] - revise bitrate calculation with xing header. if number of bytes and number of frames are available in xing header, fast play time calculation yields almost appropriate duration upon a vbr file.
yaz
parents:
997
diff
changeset
|
255 info->duration.fraction /= N_AVERAGE_FRAMES; |
29519d604e8c
[svn] - revise bitrate calculation with xing header. if number of bytes and number of frames are available in xing header, fast play time calculation yields almost appropriate duration upon a vbr file.
yaz
parents:
997
diff
changeset
|
256 mad_timer_multiply(&info->duration, info->frames); |
29519d604e8c
[svn] - revise bitrate calculation with xing header. if number of bytes and number of frames are available in xing header, fast play time calculation yields almost appropriate duration upon a vbr file.
yaz
parents:
997
diff
changeset
|
257 } |
738 | 258 } |
259 else { | |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1687
diff
changeset
|
260 gint length = aud_tuple_get_int(info->tuple, FIELD_LENGTH, NULL); |
1428
4993976d7ed0
madplug: tuple API changes
William Pitcock <nenolod@atheme-project.org>
parents:
1344
diff
changeset
|
261 |
4993976d7ed0
madplug: tuple API changes
William Pitcock <nenolod@atheme-project.org>
parents:
1344
diff
changeset
|
262 info->duration.seconds = length / 1000; |
4993976d7ed0
madplug: tuple API changes
William Pitcock <nenolod@atheme-project.org>
parents:
1344
diff
changeset
|
263 info->duration.fraction = length % 1000; |
738 | 264 } |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
265 #ifdef AUD_DEBUG |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
266 AUDDBG("using fast playtime calculation\n"); |
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
267 AUDDBG("data used = %d [tagsize=%d framesize=%f]\n", |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
268 data_used, tagsize, frame_size); |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
269 AUDDBG("frames = %d, frequency = %d, channels = %d\n", |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
270 info->frames, info->freq, info->channels); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
271 long millis = mad_timer_count(info->duration, |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
272 MAD_UNITS_MILLISECONDS); |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
273 AUDDBG("duration = %ld:%02ld\n", millis / 1000 / 60, (millis / 1000) % 60); |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
274 #endif /* DEBUG */ |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
275 break; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
276 } |
980
6ba4a4bfd127
[svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents:
959
diff
changeset
|
277 } /* while */ |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
278 if (stream.error != MAD_ERROR_BUFLEN) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
279 break; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
280 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
281 |
997
e46b98155d5d
[svn] - fix a bug which counts number of frames twice in handling xing header.
yaz
parents:
980
diff
changeset
|
282 if (info->xing.frames) |
e46b98155d5d
[svn] - fix a bug which counts number of frames twice in handling xing header.
yaz
parents:
980
diff
changeset
|
283 info->frames = info->xing.frames; |
e46b98155d5d
[svn] - fix a bug which counts number of frames twice in handling xing header.
yaz
parents:
980
diff
changeset
|
284 |
980
6ba4a4bfd127
[svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents:
959
diff
changeset
|
285 if (info->vbr && xing_bitrate != 0) { |
1162
29519d604e8c
[svn] - revise bitrate calculation with xing header. if number of bytes and number of frames are available in xing header, fast play time calculation yields almost appropriate duration upon a vbr file.
yaz
parents:
997
diff
changeset
|
286 info->bitrate = (guint)xing_bitrate; |
980
6ba4a4bfd127
[svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents:
959
diff
changeset
|
287 } |
6ba4a4bfd127
[svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents:
959
diff
changeset
|
288 else if (info->vbr && xing_bitrate == 0 && bitrate_frames != 0) { |
6ba4a4bfd127
[svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents:
959
diff
changeset
|
289 info->bitrate = accum_bitrate / bitrate_frames; |
959 | 290 } |
2340
47d7a45b26a0
fixed ${bitrate} in title string
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2287
diff
changeset
|
291 |
47d7a45b26a0
fixed ${bitrate} in title string
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2287
diff
changeset
|
292 aud_tuple_associate_int(info->tuple, FIELD_BITRATE, NULL, info->bitrate / 1000); |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
293 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
294 mad_frame_finish(&frame); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
295 mad_header_finish(&header); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
296 mad_stream_finish(&stream); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
297 xing_finish(&info->xing); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
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("scan_file: info->frames = %d\n", info->frames); |
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
300 AUDDBG("e: scan_file\n"); |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
301 |
773 | 302 return (info->frames != 0 || info->remote == TRUE); |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
303 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
304 |
980
6ba4a4bfd127
[svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents:
959
diff
changeset
|
305 /* sanity check for audio open parameters */ |
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:
2340
diff
changeset
|
306 static gboolean |
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:
2340
diff
changeset
|
307 check_audio_param(struct mad_info_t *info) |
896 | 308 { |
2390
bd9673d8b7d5
converted to new sound engine scheme.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2344
diff
changeset
|
309 if(info->fmt != FMT_FIXED32 && (info->fmt < FMT_U8 || info->fmt > FMT_S16_NE)) |
896 | 310 return FALSE; |
311 if(info->freq < 0) // not sure about maximum frequency. --yaz | |
312 return FALSE; | |
313 if(info->channels < 1 || info->channels > 2) | |
314 return FALSE; | |
315 | |
316 return TRUE; | |
317 } | |
318 | |
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:
2340
diff
changeset
|
319 gpointer |
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:
2340
diff
changeset
|
320 decode_loop(gpointer arg) |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
321 { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
322 unsigned char buffer[BUFFER_SIZE]; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
323 int len; |
611 | 324 gboolean seek_skip = FALSE; |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
325 int remainder = 0; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
326 gint tlen; |
673 | 327 unsigned int iteration = 0; |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
328 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
329 /* mad structs */ |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
330 struct mad_stream stream; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
331 struct mad_frame frame; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
332 struct mad_synth synth; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
333 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
334 /* track info is passed in as thread argument */ |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
335 struct mad_info_t *info = (struct mad_info_t *) arg; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
336 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
337 AUDDBG("f: decode\n"); |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
338 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
339 /* init mad stuff */ |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
340 mad_frame_init(&frame); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
341 mad_stream_init(&stream); |
925 | 342 mad_stream_options(&stream, MAD_OPTION_IGNORECRC); |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
343 mad_synth_init(&synth); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
344 |
611 | 345 if(!info->playback){ |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
346 AUDDBG("decode: playback == NULL\n"); |
611 | 347 return NULL; |
348 } | |
349 | |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
350 AUDDBG("decode: fmt = %d freq = %d channels = %d\n", info->fmt, info->freq, info->channels); |
896 | 351 |
352 if(check_audio_param(info) == FALSE) | |
793 | 353 return NULL; |
896 | 354 |
611 | 355 if (!info->playback->output->open_audio(info->fmt, info->freq, info->channels)) { |
356 g_mutex_lock(pb_mutex); | |
357 info->playback->error = TRUE; | |
358 info->playback->eof = 1; | |
359 g_mutex_unlock(pb_mutex); | |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
360 g_message("failed to open audio output: %s", |
611 | 361 info->playback->output->description); |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
362 return NULL; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
363 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
364 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
365 /* set mainwin title */ |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
366 if (info->title) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
367 g_free(info->title); |
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:
2340
diff
changeset
|
368 info->title = aud_tuple_formatter_make_title_string(info->tuple, audmad_config->title_override == TRUE ? |
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:
2340
diff
changeset
|
369 audmad_config->id3_format : aud_get_gentitle_format()); |
1428
4993976d7ed0
madplug: tuple API changes
William Pitcock <nenolod@atheme-project.org>
parents:
1344
diff
changeset
|
370 |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
371 tlen = (gint) mad_timer_count(info->duration, MAD_UNITS_MILLISECONDS), |
1985
a260bd1beef0
use set_params() in madplug
William Pitcock <nenolod@atheme.org>
parents:
1978
diff
changeset
|
372 info->playback->set_params(info->playback, info->title, |
778
209b08a3eff6
[svn] - hide seek bar for unseekable (info->size = 0) stream.
yaz
parents:
773
diff
changeset
|
373 (tlen == 0 || info->size <= 0) ? -1 : tlen, |
773 | 374 info->bitrate, info->freq, info->channels); |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
375 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
376 AUDDBG("decode: tlen = %d\n", tlen); |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
377 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
378 /* main loop */ |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
379 do { |
611 | 380 if (!info->playback->playing) { |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
381 AUDDBG("decode: stop signaled\n"); |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
382 break; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
383 } |
2415 | 384 |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
385 if (seek_skip) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
386 remainder = 0; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
387 else { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
388 remainder = stream.bufend - stream.next_frame; |
2415 | 389 if(buffer != stream.this_frame && remainder) |
390 memmove(buffer, stream.this_frame, remainder); | |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
391 } |
2415 | 392 |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
393 len = input_get_data(info, buffer + remainder, |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
394 BUFFER_SIZE - remainder); |
773 | 395 |
396 input_process_remote_metadata(info); | |
397 | |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
398 if (len <= 0) { |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
399 AUDDBG("finished decoding\n"); |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
400 break; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
401 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
402 len += remainder; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
403 if (len < MAD_BUFFER_GUARD) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
404 int i; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
405 for (i = len; i < MAD_BUFFER_GUARD; i++) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
406 buffer[i] = 0; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
407 len = MAD_BUFFER_GUARD; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
408 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
409 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
410 mad_stream_buffer(&stream, buffer, len); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
411 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
412 if (seek_skip) { |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
413 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
414 AUDDBG("skipping: %d\n", seek_skip); |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
415 |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
416 int skip = 2; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
417 do { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
418 if (mad_frame_decode(&frame, &stream) == 0) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
419 mad_timer_add(&info->pos, frame.header.duration); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
420 if (--skip == 0) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
421 mad_synth_frame(&synth, &frame); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
422 } |
611 | 423 else if (!MAD_RECOVERABLE(stream.error)) { |
424 g_mutex_lock(pb_mutex); | |
425 info->playback->error = TRUE; | |
426 info->playback->eof = 1; | |
427 g_mutex_unlock(pb_mutex); | |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
428 break; |
611 | 429 } |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
430 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
431 while (skip); |
611 | 432 seek_skip = FALSE; |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
433 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
434 |
611 | 435 while (info->playback->playing) { |
778
209b08a3eff6
[svn] - hide seek bar for unseekable (info->size = 0) stream.
yaz
parents:
773
diff
changeset
|
436 if (info->seek != -1 && info->size > 0) { |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
437 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
438 AUDDBG("seeking: %ld\n", info->seek); |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
439 |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
440 int new_position; |
807 | 441 gulong milliseconds = |
442 mad_timer_count(info->duration, MAD_UNITS_MILLISECONDS); | |
443 if (info->seek >= milliseconds) | |
444 info->seek = milliseconds; | |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
445 |
807 | 446 mad_timer_set(&info->pos, 0, info->seek, 1000); // in millisecond |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
447 new_position = |
807 | 448 ((double) info->seek / (double) milliseconds) * info->size; |
611 | 449 |
450 if(new_position < 0) | |
451 new_position = 0; | |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
452 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
453 AUDDBG("seeking to: %d bytes\n", new_position); |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
454 |
1978 | 455 if (aud_vfs_fseek(info->infile, new_position, SEEK_SET) == -1) |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
456 audmad_error("failed to seek to: %d", new_position); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
457 mad_frame_mute(&frame); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
458 mad_synth_mute(&synth); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
459 stream.error = MAD_ERROR_BUFLEN; |
611 | 460 info->playback->output->flush(mad_timer_count(info->pos, MAD_UNITS_MILLISECONDS)); |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
461 stream.sync = 0; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
462 info->seek = -1; |
611 | 463 seek_skip = TRUE; |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
464 break; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
465 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
466 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
467 if (mad_header_decode(&frame.header, &stream) == -1) { |
611 | 468 if (!MAD_RECOVERABLE(stream.error)) { |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
469 break; |
611 | 470 } |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
471 if (stream.error == MAD_ERROR_LOSTSYNC) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
472 /* ignore LOSTSYNC due to ID3 tags */ |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
473 int tagsize = id3_tag_query(stream.this_frame, |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
474 stream.bufend - |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
475 stream.this_frame); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
476 if (tagsize > 0) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
477 mad_stream_skip(&stream, tagsize); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
478 continue; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
479 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
480 } |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
481 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
482 AUDDBG("(recovered) error decoding header %d: %s\n", |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
483 info->current_frame, |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
484 mad_stream_errorstr(&stream)); |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
485 |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
486 continue; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
487 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
488 |
673 | 489 info->bitrate = frame.header.bitrate; |
490 | |
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:
2340
diff
changeset
|
491 if (!audmad_config->show_avg_vbr_bitrate && info->vbr && (iteration % 40 == 0)) { |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
492 |
784
5ddfe9eac8ee
[svn] - fix read_replaygain(). necessary fseek was missing in reuse fd code. closes #843.
yaz
parents:
783
diff
changeset
|
493 #ifdef DEBUG_INTENSIVELY |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
494 AUDDBG("decode vbr tlen = %d\n", tlen); |
784
5ddfe9eac8ee
[svn] - fix read_replaygain(). necessary fseek was missing in reuse fd code. closes #843.
yaz
parents:
783
diff
changeset
|
495 #endif |
1985
a260bd1beef0
use set_params() in madplug
William Pitcock <nenolod@atheme.org>
parents:
1978
diff
changeset
|
496 info->playback->set_params(info->playback, info->title, |
778
209b08a3eff6
[svn] - hide seek bar for unseekable (info->size = 0) stream.
yaz
parents:
773
diff
changeset
|
497 (tlen == 0 || info->size <= 0) ? -1 : tlen, |
673 | 498 info->bitrate, info->freq, info->channels); |
499 } | |
500 iteration++; | |
501 | |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
502 if (mad_frame_decode(&frame, &stream) == -1) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
503 if (!MAD_RECOVERABLE(stream.error)) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
504 break; |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
505 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
506 AUDDBG("(recovered) error decoding frame %d: %s\n", |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
507 info->current_frame, |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
508 mad_stream_errorstr(&stream)); |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
509 |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
510 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
511 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
512 info->current_frame++; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
513 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
514 if (info->freq != frame.header.samplerate |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
515 || info->channels != |
611 | 516 (guint) MAD_NCHANNELS(&frame.header)) { |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
517 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
518 AUDDBG("change in audio type detected\n"); |
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
519 AUDDBG("old: frequency = %d, channels = %d\n", info->freq, |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
520 info->channels); |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
521 AUDDBG("new: frequency = %d, channels = %d\n", |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
522 frame.header.samplerate, |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
523 (guint) MAD_NCHANNELS(&frame.header)); |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
524 |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
525 info->freq = frame.header.samplerate; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
526 info->channels = MAD_NCHANNELS(&frame.header); |
794 | 527 |
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:
2340
diff
changeset
|
528 if(audmad_config->force_reopen_audio && check_audio_param(info)) { |
916
a8494c2a87eb
[svn] revise reopen output code for #880. time count would be reset if output was closed. so I took two measures for it.
yaz
parents:
896
diff
changeset
|
529 gint current_time = info->playback->output->output_time(); |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
530 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
531 AUDDBG("re-opening audio due to change in audio type\n"); |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
532 |
916
a8494c2a87eb
[svn] revise reopen output code for #880. time count would be reset if output was closed. so I took two measures for it.
yaz
parents:
896
diff
changeset
|
533 info->playback->output->close_audio(); |
a8494c2a87eb
[svn] revise reopen output code for #880. time count would be reset if output was closed. so I took two measures for it.
yaz
parents:
896
diff
changeset
|
534 if (!info->playback->output->open_audio(info->fmt, info->freq, |
a8494c2a87eb
[svn] revise reopen output code for #880. time count would be reset if output was closed. so I took two measures for it.
yaz
parents:
896
diff
changeset
|
535 info->channels)) { |
a8494c2a87eb
[svn] revise reopen output code for #880. time count would be reset if output was closed. so I took two measures for it.
yaz
parents:
896
diff
changeset
|
536 g_mutex_lock(pb_mutex); |
a8494c2a87eb
[svn] revise reopen output code for #880. time count would be reset if output was closed. so I took two measures for it.
yaz
parents:
896
diff
changeset
|
537 info->playback->error = TRUE; |
a8494c2a87eb
[svn] revise reopen output code for #880. time count would be reset if output was closed. so I took two measures for it.
yaz
parents:
896
diff
changeset
|
538 info->playback->eof = 1; |
a8494c2a87eb
[svn] revise reopen output code for #880. time count would be reset if output was closed. so I took two measures for it.
yaz
parents:
896
diff
changeset
|
539 g_mutex_unlock(pb_mutex); |
a8494c2a87eb
[svn] revise reopen output code for #880. time count would be reset if output was closed. so I took two measures for it.
yaz
parents:
896
diff
changeset
|
540 g_message("failed to re-open audio output: %s", |
611 | 541 info->playback->output->description); |
916
a8494c2a87eb
[svn] revise reopen output code for #880. time count would be reset if output was closed. so I took two measures for it.
yaz
parents:
896
diff
changeset
|
542 return NULL; |
a8494c2a87eb
[svn] revise reopen output code for #880. time count would be reset if output was closed. so I took two measures for it.
yaz
parents:
896
diff
changeset
|
543 } |
a8494c2a87eb
[svn] revise reopen output code for #880. time count would be reset if output was closed. so I took two measures for it.
yaz
parents:
896
diff
changeset
|
544 // restore time and advance 0.5sec |
a8494c2a87eb
[svn] revise reopen output code for #880. time count would be reset if output was closed. so I took two measures for it.
yaz
parents:
896
diff
changeset
|
545 info->seek = current_time + 500; |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
546 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
547 } |
916
a8494c2a87eb
[svn] revise reopen output code for #880. time count would be reset if output was closed. so I took two measures for it.
yaz
parents:
896
diff
changeset
|
548 |
611 | 549 if (!info->playback->playing) |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
550 break; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
551 mad_synth_frame(&synth, &frame); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
552 mad_stream_sync(&stream); |
611 | 553 |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
554 write_output(info, &synth.pcm, &frame.header); |
2390
bd9673d8b7d5
converted to new sound engine scheme.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2344
diff
changeset
|
555 |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
556 mad_timer_add(&info->pos, frame.header.duration); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
557 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
558 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
559 while (stream.error == MAD_ERROR_BUFLEN); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
560 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
561 /* free mad stuff */ |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
562 mad_frame_finish(&frame); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
563 mad_stream_finish(&stream); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
564 mad_synth_finish(&synth); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
565 |
611 | 566 if (info->playback->playing) { |
567 GTimeVal sleeptime; | |
568 | |
569 info->playback->output->buffer_free(); | |
570 info->playback->output->buffer_free(); | |
571 while (info->playback->output->buffer_playing()) { | |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
572 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
573 AUDDBG("f: buffer_playing=%d\n", info->playback->output->buffer_playing()); |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
574 |
611 | 575 g_get_current_time(&sleeptime); |
807 | 576 g_time_val_add(&sleeptime, 500000); |
577 | |
611 | 578 g_mutex_lock(mad_mutex); |
579 g_cond_timed_wait(mad_cond, mad_mutex, &sleeptime); | |
896 | 580 g_mutex_unlock(mad_mutex); |
611 | 581 if (!info->playback->playing) { |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
582 break; |
611 | 583 } |
896 | 584 |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
585 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
586 } |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
587 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
588 AUDDBG("e: decode\n"); |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
589 |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1687
diff
changeset
|
590 aud_tuple_free(info->tuple); |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
591 info->tuple = NULL; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
592 |
611 | 593 info->playback->output->close_audio(); |
594 g_mutex_lock(mad_mutex); | |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
595 info->playback->playing = 0; |
611 | 596 g_mutex_unlock(mad_mutex); |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
597 return NULL; /* dummy */ |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
598 } |