Mercurial > audlegacy-plugins
annotate src/madplug/decoder.c @ 916:a8494c2a87eb trunk
[svn] revise reopen output code for #880. time count would be reset if output was closed. so I took two measures for it.
- 1. time count will be recorded and restored on reopen. this seems to be right way, but it causes a short stoppage of playback.
- 2. introduce a new plugin option "force_reopen_audio". if this is set to FALSE (default), decoder will not reopen output. this is a bit rude, but does not cause any interruption.
| author | yaz |
|---|---|
| date | Thu, 05 Apr 2007 21:12:59 -0700 |
| parents | f0846bdd9de6 |
| children | f931c9d744a5 |
| 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 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
19 * 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
|
20 */ |
|
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 #include <math.h> |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
23 #include <assert.h> |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
24 #include <pthread.h> |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
25 #include <signal.h> |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
26 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
27 #include <audacious/plugin.h> |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
28 #include <audacious/output.h> |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
29 #include <audacious/util.h> |
| 611 | 30 #include <sys/time.h> |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
31 #include "plugin.h" |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
32 #include "input.h" |
|
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 #define BUFFER_SIZE 16*1024 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
35 #define N_AVERAGE_FRAMES 10 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
36 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
37 extern long triangular_dither_noise(int nbits); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
38 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
39 /** |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
40 * Scale PCM data |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
41 */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
42 static inline signed int |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
43 scale(mad_fixed_t sample, struct mad_info_t *file_info) |
|
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 /* replayGain by SamKR */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
46 gdouble scale = -1; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
47 if (audmad_config.replaygain.enable) { |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
48 if (file_info->has_replaygain) { |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
49 scale = file_info->replaygain_track_scale; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
50 if (file_info->replaygain_album_scale != -1 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
51 && (scale == -1 || !audmad_config.replaygain.track_mode)) |
|
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 scale = file_info->replaygain_album_scale; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
54 } |
|
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 (scale == -1) |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
57 scale = audmad_config.replaygain.default_scale; |
|
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 if (scale == -1) |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
60 scale = 1.0; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
61 if (audmad_config.pregain_scale != 1) |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
62 scale = scale * audmad_config.pregain_scale; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
63 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
64 /* hard-limit (clipping-prevention) */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
65 if (audmad_config.hard_limit) { |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
66 /* convert to double before computation, to avoid mad_fixed_t wrapping */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
67 double x = mad_f_todouble(sample) * scale; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
68 static const double k = 0.5; // -6dBFS |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
69 if (x > k) { |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
70 x = tanh((x - k) / (1 - k)) * (1 - k) + k; |
|
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 else if (x < -k) { |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
73 x = tanh((x + k) / (1 - k)) * (1 - k) - k; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
74 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
75 sample = x * (MAD_F_ONE); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
76 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
77 else |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
78 sample *= scale; |
|
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 int n_bits_to_loose = MAD_F_FRACBITS + 1 - 16; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
81 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
82 /* round */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
83 /* add half of the bits_to_loose range to round */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
84 sample += (1L << (n_bits_to_loose - 1)); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
85 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
86 #ifdef DEBUG_DITHER |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
87 mad_fixed_t no_dither = sample; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
88 #endif |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
89 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
90 /* dither one bit of actual output */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
91 if (audmad_config.dither) { |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
92 int dither = triangular_dither_noise(n_bits_to_loose + 1); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
93 sample += dither; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
94 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
95 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
96 /* clip */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
97 /* make sure we are between -1 and 1 */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
98 if (sample >= MAD_F_ONE) { |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
99 sample = MAD_F_ONE - 1; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
100 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
101 else if (sample < -MAD_F_ONE) { |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
102 sample = -MAD_F_ONE; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
103 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
104 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
105 /* quantize */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
106 /* |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
107 * Turn our mad_fixed_t into an integer. |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
108 * Shift all but 16-bits of the fractional part |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
109 * off the right hand side and shift an extra place |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
110 * to get the sign bit. |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
111 */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
112 sample >>= n_bits_to_loose; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
113 #ifdef DEBUG_DITHER |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
114 static int n_zeros = 0; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
115 no_dither >>= n_bits_to_loose; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
116 if (no_dither - sample == 0) |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
117 n_zeros++; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
118 else { |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
119 g_message("dither: %d %d", n_zeros, no_dither - sample); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
120 n_zeros = 0; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
121 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
122 #endif |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
123 return sample; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
124 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
125 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
126 void |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
127 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
|
128 struct mad_header *header) |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
129 { |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
130 unsigned int nsamples; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
131 mad_fixed_t const *left_ch, *right_ch; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
132 char *output; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
133 int olen = 0; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
134 int pos = 0; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
135 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
136 nsamples = pcm->length; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
137 left_ch = pcm->samples[0]; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
138 right_ch = pcm->samples[1]; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
139 olen = nsamples * MAD_NCHANNELS(header) * 2; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
140 output = (char *) g_malloc(olen * sizeof(char)); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
141 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
142 while (nsamples--) { |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
143 signed int sample; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
144 /* output sample(s) in 16-bit signed little-endian PCM */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
145 sample = scale(*left_ch++, info); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
146 output[pos++] = (sample >> 0) & 0xff; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
147 output[pos++] = (sample >> 8) & 0xff; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
148 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
149 if (MAD_NCHANNELS(header) == 2) { |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
150 sample = scale(*right_ch++, info); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
151 output[pos++] = (sample >> 0) & 0xff; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
152 output[pos++] = (sample >> 8) & 0xff; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
153 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
154 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
155 assert(pos == olen); |
| 611 | 156 if (!info->playback->playing) |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
157 return; |
| 611 | 158 produce_audio(info->playback->output->written_time(), |
| 159 FMT_S16_LE, MAD_NCHANNELS(header), olen, output, &(info->playback->playing)); | |
| 160 if (!info->playback->playing) | |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
161 return; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
162 g_free(output); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
163 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
164 |
|
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 * 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
|
167 * @return FALSE if scan failed. |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
168 */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
169 gboolean scan_file(struct mad_info_t * info, gboolean fast) |
|
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 struct mad_stream stream; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
172 struct mad_header header; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
173 int remainder = 0; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
174 int data_used = 0; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
175 int len = 0; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
176 int tagsize = 0; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
177 unsigned char buffer[BUFFER_SIZE]; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
178 struct mad_frame frame; /* to read xing data */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
179 gboolean has_xing = FALSE; |
| 673 | 180 int bitrate_frames = 0; |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
181 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
182 mad_stream_init(&stream); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
183 mad_header_init(&header); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
184 mad_frame_init(&frame); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
185 xing_init(&info->xing); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
186 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
187 info->bitrate = 0; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
188 info->pos = mad_timer_zero; |
| 773 | 189 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
|
190 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
191 #ifdef DEBUG |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
192 g_message("f: scan_file"); |
| 773 | 193 g_message("scan_file frames = %d", info->frames); |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
194 #endif /* DEBUG */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
195 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
196 while (1) { |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
197 remainder = stream.bufend - stream.next_frame; |
| 789 | 198 |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
199 /* |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
200 if (remainder >= BUFFER_SIZE) |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
201 { |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
202 printf("oh dear.. remainder = %d\n", remainder); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
203 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
204 */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
205 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
206 memcpy(buffer, stream.this_frame, remainder); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
207 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
|
208 BUFFER_SIZE - remainder); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
209 |
| 773 | 210 if (len <= 0) { |
| 793 | 211 #ifdef DEBUG |
| 212 g_message("scan_file: len <= 0! len = %d", len); | |
| 213 #endif | |
|
792
2b2313fc1ddc
[svn] - I was noticed vfs_fread check still causes problem. disable for now.
yaz
parents:
789
diff
changeset
|
214 break; |
| 773 | 215 } |
|
610
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 mad_stream_buffer(&stream, buffer, len + remainder); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
218 |
| 674 | 219 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
|
220 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
|
221 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
|
222 break; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
223 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
224 if (!MAD_RECOVERABLE(stream.error)) { |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
225 #ifdef DEBUG |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
226 g_message("(fatal) error decoding header %d: %s", |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
227 info->frames, mad_stream_errorstr(&stream)); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
228 g_message("remainder = %d", remainder); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
229 g_message("len = %d", len); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
230 #endif /* DEBUG */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
231 break; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
232 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
233 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
|
234 /* 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
|
235 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
|
236 stream.bufend - |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
237 stream.this_frame); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
238 if (tagsize > 0) { |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
239 #ifdef DEBUG |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
240 g_message("skipping id3_tag: %d", tagsize); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
241 #endif /* DEBUG */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
242 mad_stream_skip(&stream, tagsize); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
243 continue; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
244 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
245 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
246 #ifdef DEBUG |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
247 g_message("(recovered) error decoding header %d: %s", |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
248 info->frames, mad_stream_errorstr(&stream)); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
249 g_message("remainder = %d", remainder); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
250 g_message("len = %d", len); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
251 #endif /* DEBUG */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
252 continue; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
253 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
254 info->frames++; |
| 674 | 255 |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
256 #ifdef DEBUG |
| 611 | 257 #ifdef DEBUG_INTENSIVELY |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
258 g_message("duration = %lu", |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
259 mad_timer_count(header.duration, |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
260 MAD_UNITS_MILLISECONDS)); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
261 g_message("size = %d", 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
|
262 #endif |
| 611 | 263 #endif |
| 738 | 264 if(info->tuple->length == -1) |
| 265 mad_timer_add(&info->duration, header.duration); | |
| 266 else { | |
| 267 info->duration.seconds = info->tuple->length / 1000; | |
| 268 info->duration.fraction = info->tuple->length % 1000; | |
| 269 } | |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
270 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
|
271 if (info->frames == 1) { |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
272 /* 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
|
273 info->bitrate = header.bitrate; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
274 info->freq = header.samplerate; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
275 info->channels = MAD_NCHANNELS(&header); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
276 info->mpeg_layer = header.layer; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
277 info->mode = header.mode; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
278 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
279 if (audmad_config.use_xing) { |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
280 frame.header = header; |
| 674 | 281 if (mad_frame_decode(&frame, &stream) == -1) { |
| 282 #ifdef DEBUG | |
| 773 | 283 g_message("xing frame decode failed"); |
| 674 | 284 #endif |
| 285 goto no_xing; | |
| 286 } | |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
287 if (xing_parse |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
288 (&info->xing, stream.anc_ptr, |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
289 stream.anc_bitlen) == 0) { |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
290 #ifdef DEBUG |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
291 g_message("found xing header"); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
292 #endif /* DEBUG */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
293 has_xing = TRUE; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
294 info->vbr = TRUE; /* otherwise xing header would have been 'Info' */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
295 info->frames = info->xing.frames; |
| 738 | 296 if(info->tuple->length == -1) |
| 297 mad_timer_multiply(&info->duration, info->frames); | |
| 298 else { | |
| 299 info->duration.seconds = info->tuple->length / 1000; | |
| 300 info->duration.fraction = info->tuple->length % 1000; | |
| 301 } | |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
302 info->bitrate = |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
303 8.0 * info->xing.bytes / |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
304 mad_timer_count(info->duration, |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
305 MAD_UNITS_SECONDS); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
306 break; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
307 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
308 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
309 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
310 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
311 else { |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
312 /* perhaps we have a VRB file */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
313 if (info->bitrate != header.bitrate) |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
314 info->vbr = TRUE; |
| 673 | 315 if (info->vbr) { |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
316 info->bitrate += header.bitrate; |
| 673 | 317 bitrate_frames++; |
| 318 } | |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
319 /* 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
|
320 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
|
321 g_warning("layer varies!!"); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
322 if (info->freq != header.samplerate) |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
323 g_warning("samplerate varies!!"); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
324 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
|
325 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
|
326 } |
| 674 | 327 no_xing: |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
328 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
|
329 float frame_size = ((double) data_used) / N_AVERAGE_FRAMES; |
| 773 | 330 #ifdef DEBUG |
| 331 g_message("info->frames = %d info->size = %d tagsize = %d frame_size = %lf", | |
| 332 info->frames, info->size, tagsize, frame_size); | |
| 333 #endif | |
| 334 if(info->size != 0) | |
| 335 info->frames = (info->size - tagsize) / frame_size; | |
| 336 #ifdef DEBUG | |
| 337 g_message("info->frames = %d", info->frames); | |
| 338 #endif | |
| 738 | 339 if(info->tuple->length == -1) { |
| 340 info->duration.seconds /= N_AVERAGE_FRAMES; | |
| 341 info->duration.fraction /= N_AVERAGE_FRAMES; | |
| 342 mad_timer_multiply(&info->duration, info->frames); | |
| 343 } | |
| 344 else { | |
| 345 info->duration.seconds = info->tuple->length / 1000; | |
| 346 info->duration.fraction = info->tuple->length % 1000; | |
| 347 } | |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
348 #ifdef DEBUG |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
349 g_message("using fast playtime calculation"); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
350 g_message("data used = %d [tagsize=%d framesize=%f]", |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
351 data_used, tagsize, frame_size); |
|
627
8829833d37bc
[svn] Break out of the loop once we know the length. No using spinning around all day.
chainsaw
parents:
619
diff
changeset
|
352 g_message("frames = %d, frequency = %d, channels = %d", |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
353 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
|
354 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
|
355 MAD_UNITS_MILLISECONDS); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
356 g_message("duration = %lu:%lu", millis / 1000 / 60, |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
357 (millis / 1000) % 60); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
358 #endif /* DEBUG */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
359 break; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
360 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
361 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
362 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
|
363 break; |
|
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 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
366 if (info->vbr && !has_xing) |
| 673 | 367 info->bitrate = info->bitrate / bitrate_frames; |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
368 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
369 mad_frame_finish(&frame); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
370 mad_header_finish(&header); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
371 mad_stream_finish(&stream); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
372 xing_finish(&info->xing); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
373 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
374 #ifdef DEBUG |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
375 g_message("e: scan_file"); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
376 #endif /* DEBUG */ |
| 773 | 377 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
|
378 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
379 |
| 896 | 380 // sanity check for audio open parameters |
| 381 static gboolean check_audio_param(struct mad_info_t *info) | |
| 382 { | |
| 383 if(info->fmt < FMT_U8 || info->fmt > FMT_S16_NE) | |
| 384 return FALSE; | |
| 385 if(info->freq < 0) // not sure about maximum frequency. --yaz | |
| 386 return FALSE; | |
| 387 if(info->channels < 1 || info->channels > 2) | |
| 388 return FALSE; | |
| 389 | |
| 390 return TRUE; | |
| 391 } | |
| 392 | |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
393 gpointer decode_loop(gpointer arg) |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
394 { |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
395 unsigned char buffer[BUFFER_SIZE]; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
396 int len; |
| 611 | 397 gboolean seek_skip = FALSE; |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
398 int remainder = 0; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
399 gint tlen; |
| 673 | 400 unsigned int iteration = 0; |
|
610
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 /* mad structs */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
403 struct mad_stream stream; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
404 struct mad_frame frame; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
405 struct mad_synth synth; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
406 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
407 /* 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
|
408 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
|
409 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
410 #ifdef DEBUG |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
411 g_message("f: decode"); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
412 #endif /* DEBUG */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
413 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
414 /* init mad stuff */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
415 mad_frame_init(&frame); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
416 mad_stream_init(&stream); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
417 mad_synth_init(&synth); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
418 |
| 611 | 419 if(!info->playback){ |
| 773 | 420 #ifdef DEBUG |
| 421 g_message("decode: playback == NULL"); | |
| 422 #endif | |
| 611 | 423 return NULL; |
| 424 } | |
| 425 | |
| 773 | 426 #ifdef DEBUG |
| 427 g_message("decode: fmt = %d freq = %d channels = %d", info->fmt, info->freq, info->channels); | |
| 428 #endif | |
| 896 | 429 |
| 430 if(check_audio_param(info) == FALSE) | |
| 793 | 431 return NULL; |
| 896 | 432 |
| 611 | 433 if (!info->playback->output->open_audio(info->fmt, info->freq, info->channels)) { |
| 434 g_mutex_lock(pb_mutex); | |
| 435 info->playback->error = TRUE; | |
| 436 info->playback->eof = 1; | |
| 437 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
|
438 g_message("failed to open audio output: %s", |
| 611 | 439 info->playback->output->description); |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
440 return NULL; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
441 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
442 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
443 /* set mainwin title */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
444 if (info->title) |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
445 g_free(info->title); |
| 619 | 446 info->title = xmms_get_titlestring(audmad_config.title_override == TRUE ? |
| 773 | 447 audmad_config.id3_format : xmms_get_gentitle_format(), info->tuple); |
| 611 | 448 |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
449 tlen = (gint) mad_timer_count(info->duration, MAD_UNITS_MILLISECONDS), |
| 773 | 450 mad_plugin->set_info(info->title, |
|
778
209b08a3eff6
[svn] - hide seek bar for unseekable (info->size = 0) stream.
yaz
parents:
773
diff
changeset
|
451 (tlen == 0 || info->size <= 0) ? -1 : tlen, |
| 773 | 452 info->bitrate, info->freq, info->channels); |
| 453 #ifdef DEBUG | |
|
784
5ddfe9eac8ee
[svn] - fix read_replaygain(). necessary fseek was missing in reuse fd code. closes #843.
yaz
parents:
783
diff
changeset
|
454 g_message("decode: tlen = %d", tlen); |
| 773 | 455 #endif |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
456 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
457 /* main loop */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
458 do { |
| 611 | 459 if (!info->playback->playing) { |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
460 #ifdef DEBUG |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
461 g_message("decode: stop signaled"); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
462 #endif /* DEBUG */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
463 break; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
464 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
465 if (seek_skip) |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
466 remainder = 0; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
467 else { |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
468 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
|
469 memcpy(buffer, stream.this_frame, remainder); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
470 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
471 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
|
472 BUFFER_SIZE - remainder); |
| 773 | 473 |
| 474 input_process_remote_metadata(info); | |
| 475 | |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
476 if (len <= 0) { |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
477 #ifdef DEBUG |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
478 g_message("finished decoding"); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
479 #endif /* DEBUG */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
480 break; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
481 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
482 len += remainder; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
483 if (len < MAD_BUFFER_GUARD) { |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
484 int i; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
485 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
|
486 buffer[i] = 0; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
487 len = MAD_BUFFER_GUARD; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
488 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
489 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
490 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
|
491 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
492 if (seek_skip) { |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
493 #ifdef DEBUG |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
494 g_message("skipping: %d", seek_skip); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
495 #endif |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
496 int skip = 2; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
497 do { |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
498 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
|
499 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
|
500 if (--skip == 0) |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
501 mad_synth_frame(&synth, &frame); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
502 } |
| 611 | 503 else if (!MAD_RECOVERABLE(stream.error)) { |
| 504 g_mutex_lock(pb_mutex); | |
| 505 info->playback->error = TRUE; | |
| 506 info->playback->eof = 1; | |
| 507 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
|
508 break; |
| 611 | 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 while (skip); |
| 611 | 512 seek_skip = FALSE; |
|
610
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 |
| 611 | 515 while (info->playback->playing) { |
|
778
209b08a3eff6
[svn] - hide seek bar for unseekable (info->size = 0) stream.
yaz
parents:
773
diff
changeset
|
516 if (info->seek != -1 && info->size > 0) { |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
517 #ifdef DEBUG |
| 896 | 518 g_message("seeking: %ld", info->seek); |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
519 #endif |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
520 int new_position; |
| 807 | 521 gulong milliseconds = |
| 522 mad_timer_count(info->duration, MAD_UNITS_MILLISECONDS); | |
| 523 if (info->seek >= milliseconds) | |
| 524 info->seek = milliseconds; | |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
525 |
| 807 | 526 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
|
527 new_position = |
| 807 | 528 ((double) info->seek / (double) milliseconds) * info->size; |
| 611 | 529 |
| 530 if(new_position < 0) | |
| 531 new_position = 0; | |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
532 #ifdef DEBUG |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
533 g_message("seeking to: %d bytes", new_position); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
534 #endif |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
535 if (vfs_fseek(info->infile, new_position, SEEK_SET) == -1) |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
536 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
|
537 mad_frame_mute(&frame); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
538 mad_synth_mute(&synth); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
539 stream.error = MAD_ERROR_BUFLEN; |
| 611 | 540 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
|
541 stream.sync = 0; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
542 info->seek = -1; |
| 611 | 543 seek_skip = TRUE; |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
544 break; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
545 } |
|
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 if (mad_header_decode(&frame.header, &stream) == -1) { |
| 611 | 548 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
|
549 break; |
| 611 | 550 } |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
551 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
|
552 /* 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
|
553 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
|
554 stream.bufend - |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
555 stream.this_frame); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
556 if (tagsize > 0) { |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
557 mad_stream_skip(&stream, tagsize); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
558 continue; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
559 } |
|
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 #ifdef DEBUG |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
562 g_message("(recovered) error decoding header %d: %s", |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
563 info->current_frame, |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
564 mad_stream_errorstr(&stream)); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
565 #endif /* DEBUG */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
566 continue; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
567 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
568 |
| 673 | 569 info->bitrate = frame.header.bitrate; |
| 570 | |
|
778
209b08a3eff6
[svn] - hide seek bar for unseekable (info->size = 0) stream.
yaz
parents:
773
diff
changeset
|
571 if (!audmad_config.show_avg_vbr_bitrate && info->vbr && (iteration % 40 == 0)) { |
|
209b08a3eff6
[svn] - hide seek bar for unseekable (info->size = 0) stream.
yaz
parents:
773
diff
changeset
|
572 #ifdef DEBUG |
|
784
5ddfe9eac8ee
[svn] - fix read_replaygain(). necessary fseek was missing in reuse fd code. closes #843.
yaz
parents:
783
diff
changeset
|
573 #ifdef DEBUG_INTENSIVELY |
|
778
209b08a3eff6
[svn] - hide seek bar for unseekable (info->size = 0) stream.
yaz
parents:
773
diff
changeset
|
574 g_message("decode vbr tlen = %d", tlen); |
|
209b08a3eff6
[svn] - hide seek bar for unseekable (info->size = 0) stream.
yaz
parents:
773
diff
changeset
|
575 #endif |
|
784
5ddfe9eac8ee
[svn] - fix read_replaygain(). necessary fseek was missing in reuse fd code. closes #843.
yaz
parents:
783
diff
changeset
|
576 #endif |
| 673 | 577 mad_plugin->set_info(info->title, |
|
778
209b08a3eff6
[svn] - hide seek bar for unseekable (info->size = 0) stream.
yaz
parents:
773
diff
changeset
|
578 (tlen == 0 || info->size <= 0) ? -1 : tlen, |
| 673 | 579 info->bitrate, info->freq, info->channels); |
| 580 } | |
| 581 iteration++; | |
| 582 | |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
583 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
|
584 if (!MAD_RECOVERABLE(stream.error)) |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
585 break; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
586 #ifdef DEBUG |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
587 g_message("(recovered) error decoding frame %d: %s", |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
588 info->current_frame, |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
589 mad_stream_errorstr(&stream)); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
590 #endif /* DEBUG */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
591 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
592 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
593 info->current_frame++; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
594 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
595 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
|
596 || info->channels != |
| 611 | 597 (guint) MAD_NCHANNELS(&frame.header)) { |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
598 #ifdef DEBUG |
|
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
|
599 g_message("change in audio type detected"); |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
600 g_message("old: frequency = %d, channels = %d", info->freq, |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
601 info->channels); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
602 g_message("new: frequency = %d, channels = %d", |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
603 frame.header.samplerate, |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
604 (guint) MAD_NCHANNELS(&frame.header)); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
605 #endif /* DEBUG */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
606 info->freq = frame.header.samplerate; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
607 info->channels = MAD_NCHANNELS(&frame.header); |
| 794 | 608 |
|
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
|
609 if(audmad_config.force_reopen_audio && check_audio_param(info)) { |
|
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
|
610 gint current_time = info->playback->output->output_time(); |
|
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
|
611 #ifdef DEBUG |
|
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
|
612 g_message("re-opening audio due to change in audio type"); |
|
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
|
613 #endif |
|
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
|
614 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
|
615 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
|
616 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
|
617 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
|
618 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
|
619 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
|
620 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
|
621 g_message("failed to re-open audio output: %s", |
| 611 | 622 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
|
623 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
|
624 } |
|
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
|
625 // 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
|
626 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
|
627 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
628 } |
|
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
|
629 |
| 611 | 630 if (!info->playback->playing) |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
631 break; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
632 mad_synth_frame(&synth, &frame); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
633 mad_stream_sync(&stream); |
| 611 | 634 |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
635 write_output(info, &synth.pcm, &frame.header); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
636 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
|
637 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
638 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
639 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
|
640 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
641 /* free mad stuff */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
642 mad_frame_finish(&frame); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
643 mad_stream_finish(&stream); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
644 mad_synth_finish(&synth); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
645 |
| 611 | 646 if (info->playback->playing) { |
| 647 GTimeVal sleeptime; | |
| 648 | |
| 649 info->playback->output->buffer_free(); | |
| 650 info->playback->output->buffer_free(); | |
| 651 while (info->playback->output->buffer_playing()) { | |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
652 #ifdef DEBUG |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
653 g_message("f: buffer_playing=%d", |
| 611 | 654 info->playback->output->buffer_playing()); |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
655 #endif |
| 611 | 656 g_get_current_time(&sleeptime); |
| 807 | 657 g_time_val_add(&sleeptime, 500000); |
| 658 | |
| 611 | 659 g_mutex_lock(mad_mutex); |
| 660 g_cond_timed_wait(mad_cond, mad_mutex, &sleeptime); | |
| 896 | 661 g_mutex_unlock(mad_mutex); |
| 611 | 662 if (!info->playback->playing) { |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
663 break; |
| 611 | 664 } |
| 896 | 665 |
|
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
666 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
667 } |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
668 #ifdef DEBUG |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
669 g_message("e: decode"); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
670 #endif /* DEBUG */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
671 |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
672 bmp_title_input_free(info->tuple); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
673 info->tuple = NULL; |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
674 |
| 611 | 675 info->playback->output->close_audio(); |
| 676 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
|
677 info->playback->playing = 0; |
| 611 | 678 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
|
679 g_thread_exit(0); |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
680 return NULL; /* dummy */ |
|
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
681 } |
