Mercurial > audlegacy-plugins
annotate src/madplug/decoder.c @ 2284:d19b53359b24
cleaned up the sndfile wav plugin, currently limiting it ONLY TO WAV
PLAYBACK. if somebody is more experienced with it and wants to restore
the other formats, go ahead (maybe change the name of the plugin too?).
author | mf0102 <0102@gmx.at> |
---|---|
date | Wed, 09 Jan 2008 15:41:22 +0100 |
parents | d25cd7e7eddb |
children | 2421c87fb855 |
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 |
924 | 37 extern int triangular_dither_noise(int nbits); |
610
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; |
1998
8f3188746b64
chase last changeset in aud
William Pitcock <nenolod@atheme.org>
parents:
1985
diff
changeset
|
158 info->playback->pass_audio(info->playback, |
611 | 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; |
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
|
180 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
|
181 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
|
182 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
|
183 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
184 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
|
185 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
|
186 mad_header_init(&header); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
187 mad_frame_init(&frame); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
188 xing_init(&info->xing); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
189 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
190 info->bitrate = 0; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
191 info->pos = mad_timer_zero; |
773 | 192 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
|
193 |
997
e46b98155d5d
[svn] - fix a bug which counts number of frames twice in handling xing header.
yaz
parents:
980
diff
changeset
|
194 if(info->fileinfo_request == TRUE) { |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1687
diff
changeset
|
195 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
|
196 info->fileinfo_request = FALSE; |
e46b98155d5d
[svn] - fix a bug which counts number of frames twice in handling xing header.
yaz
parents:
980
diff
changeset
|
197 } |
e46b98155d5d
[svn] - fix a bug which counts number of frames twice in handling xing header.
yaz
parents:
980
diff
changeset
|
198 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
199 AUDDBG("f: scan_file\n"); |
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
200 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
|
201 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
202 while (1) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
203 remainder = stream.bufend - stream.next_frame; |
789 | 204 |
610
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 if (remainder >= BUFFER_SIZE) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
207 { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
208 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
|
209 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
210 */ |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
211 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
212 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
|
213 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
|
214 BUFFER_SIZE - remainder); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
215 |
773 | 216 if (len <= 0) { |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
217 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
|
218 break; |
773 | 219 } |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
220 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
221 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
|
222 |
674 | 223 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
|
224 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
|
225 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
|
226 break; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
227 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
228 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
|
229 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
|
230 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
|
231 AUDDBG("remainder = %d\n", remainder); |
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
232 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
|
233 break; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
234 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
235 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
|
236 /* 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
|
237 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
|
238 stream.bufend - |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
239 stream.this_frame); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
240 if (tagsize > 0) { |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
241 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
|
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 } |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
246 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
247 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
|
248 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
|
249 AUDDBG("remainder = %d\n", remainder); |
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
250 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
|
251 |
610
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 |
611 | 256 #ifdef DEBUG_INTENSIVELY |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
257 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
|
258 AUDDBG("duration = %ul\n", |
610
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)); |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
261 AUDDBG("size = %d\n", stream.next_frame - stream.this_frame); |
611 | 262 #endif |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1687
diff
changeset
|
263 if(aud_tuple_get_int(info->tuple, FIELD_LENGTH, NULL) == -1) |
738 | 264 mad_timer_add(&info->duration, header.duration); |
265 else { | |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1687
diff
changeset
|
266 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
|
267 |
4993976d7ed0
madplug: tuple API changes
William Pitcock <nenolod@atheme-project.org>
parents:
1344
diff
changeset
|
268 info->duration.seconds = length / 1000; |
4993976d7ed0
madplug: tuple API changes
William Pitcock <nenolod@atheme-project.org>
parents:
1344
diff
changeset
|
269 info->duration.fraction = length % 1000; |
738 | 270 } |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
271 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
|
272 if (info->frames == 1) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
273 /* 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
|
274 info->bitrate = header.bitrate; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
275 info->freq = header.samplerate; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
276 info->channels = MAD_NCHANNELS(&header); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
277 info->mpeg_layer = header.layer; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
278 info->mode = header.mode; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
279 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
280 if (audmad_config.use_xing) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
281 frame.header = header; |
674 | 282 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
|
283 AUDDBG("xing frame decode failed\n"); |
674 | 284 goto no_xing; |
285 } | |
980
6ba4a4bfd127
[svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents:
959
diff
changeset
|
286 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
|
287 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
|
288 has_xing = TRUE; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
289 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
|
290 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
291 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
|
292 |
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
|
293 /* 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
|
294 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
|
295 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
|
296 #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
|
297 { |
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
|
298 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
|
299 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
|
300 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
|
301 } |
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
|
302 #endif |
738 | 303 } |
959 | 304 continue; |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
305 } |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
306 #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
|
307 else { |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
308 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
|
309 continue; |
6ba4a4bfd127
[svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents:
959
diff
changeset
|
310 } |
6ba4a4bfd127
[svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents:
959
diff
changeset
|
311 #endif |
6ba4a4bfd127
[svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents:
959
diff
changeset
|
312 } /* xing */ |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
313 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
314 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
315 else { |
980
6ba4a4bfd127
[svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents:
959
diff
changeset
|
316 /* 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
|
317 if (info->bitrate != header.bitrate) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
318 info->vbr = TRUE; |
673 | 319 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
|
320 accum_bitrate += (double)header.bitrate; |
673 | 321 bitrate_frames++; |
322 } | |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
323 /* 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
|
324 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
|
325 g_warning("layer varies!!"); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
326 if (info->freq != header.samplerate) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
327 g_warning("samplerate varies!!"); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
328 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
|
329 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
|
330 } |
674 | 331 no_xing: |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
332 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
|
333 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
|
334 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
335 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
|
336 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
|
337 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
|
338 |
773 | 339 if(info->size != 0) |
340 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
|
341 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
342 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
|
343 |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1687
diff
changeset
|
344 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
|
345 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
|
346 /* 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
|
347 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
|
348 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
|
349 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
|
350 } |
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
|
351 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
|
352 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
|
353 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
|
354 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
|
355 } |
738 | 356 } |
357 else { | |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1687
diff
changeset
|
358 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
|
359 |
4993976d7ed0
madplug: tuple API changes
William Pitcock <nenolod@atheme-project.org>
parents:
1344
diff
changeset
|
360 info->duration.seconds = length / 1000; |
4993976d7ed0
madplug: tuple API changes
William Pitcock <nenolod@atheme-project.org>
parents:
1344
diff
changeset
|
361 info->duration.fraction = length % 1000; |
738 | 362 } |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
363 #ifdef AUD_DEBUG |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
364 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
|
365 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
|
366 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
|
367 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
|
368 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
|
369 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
|
370 MAD_UNITS_MILLISECONDS); |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
371 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
|
372 #endif /* DEBUG */ |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
373 break; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
374 } |
980
6ba4a4bfd127
[svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents:
959
diff
changeset
|
375 } /* while */ |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
376 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
|
377 break; |
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 |
997
e46b98155d5d
[svn] - fix a bug which counts number of frames twice in handling xing header.
yaz
parents:
980
diff
changeset
|
380 if (info->xing.frames) |
e46b98155d5d
[svn] - fix a bug which counts number of frames twice in handling xing header.
yaz
parents:
980
diff
changeset
|
381 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
|
382 |
980
6ba4a4bfd127
[svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents:
959
diff
changeset
|
383 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
|
384 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
|
385 } |
6ba4a4bfd127
[svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents:
959
diff
changeset
|
386 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
|
387 info->bitrate = accum_bitrate / bitrate_frames; |
959 | 388 } |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
389 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
390 mad_frame_finish(&frame); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
391 mad_header_finish(&header); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
392 mad_stream_finish(&stream); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
393 xing_finish(&info->xing); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
394 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
395 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
|
396 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
|
397 |
773 | 398 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
|
399 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
400 |
980
6ba4a4bfd127
[svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents:
959
diff
changeset
|
401 /* sanity check for audio open parameters */ |
896 | 402 static gboolean check_audio_param(struct mad_info_t *info) |
403 { | |
404 if(info->fmt < FMT_U8 || info->fmt > FMT_S16_NE) | |
405 return FALSE; | |
406 if(info->freq < 0) // not sure about maximum frequency. --yaz | |
407 return FALSE; | |
408 if(info->channels < 1 || info->channels > 2) | |
409 return FALSE; | |
410 | |
411 return TRUE; | |
412 } | |
413 | |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
414 gpointer decode_loop(gpointer arg) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
415 { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
416 unsigned char buffer[BUFFER_SIZE]; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
417 int len; |
611 | 418 gboolean seek_skip = FALSE; |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
419 int remainder = 0; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
420 gint tlen; |
673 | 421 unsigned int iteration = 0; |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
422 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
423 /* mad structs */ |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
424 struct mad_stream stream; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
425 struct mad_frame frame; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
426 struct mad_synth synth; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
427 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
428 /* 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
|
429 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
|
430 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
431 AUDDBG("f: decode\n"); |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
432 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
433 /* init mad stuff */ |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
434 mad_frame_init(&frame); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
435 mad_stream_init(&stream); |
925 | 436 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
|
437 mad_synth_init(&synth); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
438 |
611 | 439 if(!info->playback){ |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
440 AUDDBG("decode: playback == NULL\n"); |
611 | 441 return NULL; |
442 } | |
443 | |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
444 AUDDBG("decode: fmt = %d freq = %d channels = %d\n", info->fmt, info->freq, info->channels); |
896 | 445 |
446 if(check_audio_param(info) == FALSE) | |
793 | 447 return NULL; |
896 | 448 |
611 | 449 if (!info->playback->output->open_audio(info->fmt, info->freq, info->channels)) { |
450 g_mutex_lock(pb_mutex); | |
451 info->playback->error = TRUE; | |
452 info->playback->eof = 1; | |
453 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
|
454 g_message("failed to open audio output: %s", |
611 | 455 info->playback->output->description); |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
456 return NULL; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
457 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
458 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
459 /* set mainwin title */ |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
460 if (info->title) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
461 g_free(info->title); |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1687
diff
changeset
|
462 info->title = aud_tuple_formatter_make_title_string(info->tuple, audmad_config.title_override == TRUE ? |
2055 | 463 audmad_config.id3_format : aud_get_gentitle_format()); |
1428
4993976d7ed0
madplug: tuple API changes
William Pitcock <nenolod@atheme-project.org>
parents:
1344
diff
changeset
|
464 |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
465 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
|
466 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
|
467 (tlen == 0 || info->size <= 0) ? -1 : tlen, |
773 | 468 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
|
469 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
470 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
|
471 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
472 /* main loop */ |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
473 do { |
611 | 474 if (!info->playback->playing) { |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
475 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
|
476 break; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
477 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
478 if (seek_skip) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
479 remainder = 0; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
480 else { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
481 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
|
482 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
|
483 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
484 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
|
485 BUFFER_SIZE - remainder); |
773 | 486 |
487 input_process_remote_metadata(info); | |
488 | |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
489 if (len <= 0) { |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
490 AUDDBG("finished decoding\n"); |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
491 break; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
492 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
493 len += remainder; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
494 if (len < MAD_BUFFER_GUARD) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
495 int i; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
496 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
|
497 buffer[i] = 0; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
498 len = MAD_BUFFER_GUARD; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
499 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
500 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
501 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
|
502 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
503 if (seek_skip) { |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
504 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
505 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
|
506 |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
507 int skip = 2; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
508 do { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
509 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
|
510 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
|
511 if (--skip == 0) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
512 mad_synth_frame(&synth, &frame); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
513 } |
611 | 514 else if (!MAD_RECOVERABLE(stream.error)) { |
515 g_mutex_lock(pb_mutex); | |
516 info->playback->error = TRUE; | |
517 info->playback->eof = 1; | |
518 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
|
519 break; |
611 | 520 } |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
521 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
522 while (skip); |
611 | 523 seek_skip = FALSE; |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
524 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
525 |
611 | 526 while (info->playback->playing) { |
778
209b08a3eff6
[svn] - hide seek bar for unseekable (info->size = 0) stream.
yaz
parents:
773
diff
changeset
|
527 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
|
528 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
529 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
|
530 |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
531 int new_position; |
807 | 532 gulong milliseconds = |
533 mad_timer_count(info->duration, MAD_UNITS_MILLISECONDS); | |
534 if (info->seek >= milliseconds) | |
535 info->seek = milliseconds; | |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
536 |
807 | 537 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
|
538 new_position = |
807 | 539 ((double) info->seek / (double) milliseconds) * info->size; |
611 | 540 |
541 if(new_position < 0) | |
542 new_position = 0; | |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
543 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
544 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
|
545 |
1978 | 546 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
|
547 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
|
548 mad_frame_mute(&frame); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
549 mad_synth_mute(&synth); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
550 stream.error = MAD_ERROR_BUFLEN; |
611 | 551 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
|
552 stream.sync = 0; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
553 info->seek = -1; |
611 | 554 seek_skip = TRUE; |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
555 break; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
556 } |
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 if (mad_header_decode(&frame.header, &stream) == -1) { |
611 | 559 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
|
560 break; |
611 | 561 } |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
562 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
|
563 /* 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
|
564 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
|
565 stream.bufend - |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
566 stream.this_frame); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
567 if (tagsize > 0) { |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
568 mad_stream_skip(&stream, tagsize); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
569 continue; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
570 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
571 } |
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("(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
|
574 info->current_frame, |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
575 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
|
576 |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
577 continue; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
578 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
579 |
673 | 580 info->bitrate = frame.header.bitrate; |
581 | |
778
209b08a3eff6
[svn] - hide seek bar for unseekable (info->size = 0) stream.
yaz
parents:
773
diff
changeset
|
582 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
|
583 |
784
5ddfe9eac8ee
[svn] - fix read_replaygain(). necessary fseek was missing in reuse fd code. closes #843.
yaz
parents:
783
diff
changeset
|
584 #ifdef DEBUG_INTENSIVELY |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
585 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
|
586 #endif |
1985
a260bd1beef0
use set_params() in madplug
William Pitcock <nenolod@atheme.org>
parents:
1978
diff
changeset
|
587 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
|
588 (tlen == 0 || info->size <= 0) ? -1 : tlen, |
673 | 589 info->bitrate, info->freq, info->channels); |
590 } | |
591 iteration++; | |
592 | |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
593 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
|
594 if (!MAD_RECOVERABLE(stream.error)) |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
595 break; |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
596 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
597 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
|
598 info->current_frame, |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
599 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
|
600 |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
601 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
602 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
603 info->current_frame++; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
604 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
605 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
|
606 || info->channels != |
611 | 607 (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
|
608 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
609 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
|
610 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
|
611 info->channels); |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
612 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
|
613 frame.header.samplerate, |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
614 (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
|
615 |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
616 info->freq = frame.header.samplerate; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
617 info->channels = MAD_NCHANNELS(&frame.header); |
794 | 618 |
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
|
619 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
|
620 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
|
621 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
622 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
|
623 |
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
|
624 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
|
625 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
|
626 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
|
627 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
|
628 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
|
629 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
|
630 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
|
631 g_message("failed to re-open audio output: %s", |
611 | 632 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
|
633 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
|
634 } |
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
|
635 // 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
|
636 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
|
637 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
638 } |
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
|
639 |
611 | 640 if (!info->playback->playing) |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
641 break; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
642 mad_synth_frame(&synth, &frame); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
643 mad_stream_sync(&stream); |
611 | 644 |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
645 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
|
646 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
|
647 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
648 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
649 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
|
650 |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
651 /* free mad stuff */ |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
652 mad_frame_finish(&frame); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
653 mad_stream_finish(&stream); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
654 mad_synth_finish(&synth); |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
655 |
611 | 656 if (info->playback->playing) { |
657 GTimeVal sleeptime; | |
658 | |
659 info->playback->output->buffer_free(); | |
660 info->playback->output->buffer_free(); | |
661 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
|
662 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
663 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
|
664 |
611 | 665 g_get_current_time(&sleeptime); |
807 | 666 g_time_val_add(&sleeptime, 500000); |
667 | |
611 | 668 g_mutex_lock(mad_mutex); |
669 g_cond_timed_wait(mad_cond, mad_mutex, &sleeptime); | |
896 | 670 g_mutex_unlock(mad_mutex); |
611 | 671 if (!info->playback->playing) { |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
672 break; |
611 | 673 } |
896 | 674 |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
675 } |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
676 } |
2214
9a869d4bb0d3
make use of AUDDBG() for debug print out.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2055
diff
changeset
|
677 |
2276
d25cd7e7eddb
append '\n' to format string for AUDDBG()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2214
diff
changeset
|
678 AUDDBG("e: decode\n"); |
610
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
679 |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1687
diff
changeset
|
680 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
|
681 info->tuple = NULL; |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
682 |
611 | 683 info->playback->output->close_audio(); |
684 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
|
685 info->playback->playing = 0; |
611 | 686 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
|
687 return NULL; /* dummy */ |
862190d39e00
[svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff
changeset
|
688 } |