annotate src/madplug/decoder.c @ 1903:5c01978673ca

fix for an undefined symbol error of __gxx_personality_v0.
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Thu, 27 Sep 2007 12:55:56 +0900
parents d158ce84fda7
children 5fa26178eaef
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
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
f931c9d744a5 [svn] -adjust size of variable in dither code.
yaz
parents: 916
diff changeset
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
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
156 if (!info->playback->playing)
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
157 return;
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
158 produce_audio(info->playback->output->written_time(),
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
159 FMT_S16_LE, MAD_NCHANNELS(header), olen, output, &(info->playback->playing));
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
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
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 768
diff changeset
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) {
1687
d158ce84fda7 Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1485
diff changeset
195 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
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
199 #ifdef DEBUG
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
200 g_message("f: scan_file");
773
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 768
diff changeset
201 g_message("scan_file frames = %d", info->frames);
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
202 #endif /* DEBUG */
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
203
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
204 while (1) {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
205 remainder = stream.bufend - stream.next_frame;
789
354c69a939bc [svn] revising vfs_fread() check code.
yaz
parents: 788
diff changeset
206
610
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 if (remainder >= BUFFER_SIZE)
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 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
211 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
212 */
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
213
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
214 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
215 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
216 BUFFER_SIZE - remainder);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
217
773
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 768
diff changeset
218 if (len <= 0) {
793
98cdc39031f9 [svn] - add sanity check for open audio parameters.
yaz
parents: 792
diff changeset
219 #ifdef DEBUG
980
6ba4a4bfd127 [svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents: 959
diff changeset
220 g_message("scan_file: len <= 0 len = %d", len);
793
98cdc39031f9 [svn] - add sanity check for open audio parameters.
yaz
parents: 792
diff changeset
221 #endif
792
2b2313fc1ddc [svn] - I was noticed vfs_fread check still causes problem. disable for now.
yaz
parents: 789
diff changeset
222 break;
773
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 768
diff changeset
223 }
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
224
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
225 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
226
674
fadf4c18a1cf [svn] madplug bug fix:
yaz
parents: 673
diff changeset
227 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
228 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
229 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
230 break;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
231 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
232 if (!MAD_RECOVERABLE(stream.error)) {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
233 #ifdef DEBUG
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
234 g_message("(fatal) error decoding header %d: %s",
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
235 info->frames, mad_stream_errorstr(&stream));
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
236 g_message("remainder = %d", remainder);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
237 g_message("len = %d", len);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
238 #endif /* DEBUG */
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
239 break;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
240 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
241 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
242 /* 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
243 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
244 stream.bufend -
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
245 stream.this_frame);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
246 if (tagsize > 0) {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
247 #ifdef DEBUG
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
248 g_message("skipping id3_tag: %d", tagsize);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
249 #endif /* DEBUG */
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
250 mad_stream_skip(&stream, tagsize);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
251 continue;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
252 }
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 #ifdef DEBUG
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
255 g_message("(recovered) error decoding header %d: %s",
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
256 info->frames, mad_stream_errorstr(&stream));
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
257 g_message("remainder = %d", remainder);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
258 g_message("len = %d", len);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
259 #endif /* DEBUG */
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
260 continue;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
261 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
262 info->frames++;
674
fadf4c18a1cf [svn] madplug bug fix:
yaz
parents: 673
diff changeset
263
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
264 #ifdef DEBUG
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
265 #ifdef DEBUG_INTENSIVELY
980
6ba4a4bfd127 [svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents: 959
diff changeset
266 g_message("header bitrate = %ld", header.bitrate);
6ba4a4bfd127 [svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents: 959
diff changeset
267 g_message("duration = %ul",
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
268 mad_timer_count(header.duration,
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
269 MAD_UNITS_MILLISECONDS));
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
270 g_message("size = %d", stream.next_frame - stream.this_frame);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
271 #endif
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
272 #endif
1687
d158ce84fda7 Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1485
diff changeset
273 if(tuple_get_int(info->tuple, FIELD_LENGTH, NULL) == -1)
738
6ea974a229a8 [svn] - add read/write support for TLEN frame.
yaz
parents: 676
diff changeset
274 mad_timer_add(&info->duration, header.duration);
6ea974a229a8 [svn] - add read/write support for TLEN frame.
yaz
parents: 676
diff changeset
275 else {
1687
d158ce84fda7 Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1485
diff changeset
276 gint length = tuple_get_int(info->tuple, FIELD_LENGTH, NULL);
1428
4993976d7ed0 madplug: tuple API changes
William Pitcock <nenolod@atheme-project.org>
parents: 1344
diff changeset
277
4993976d7ed0 madplug: tuple API changes
William Pitcock <nenolod@atheme-project.org>
parents: 1344
diff changeset
278 info->duration.seconds = length / 1000;
4993976d7ed0 madplug: tuple API changes
William Pitcock <nenolod@atheme-project.org>
parents: 1344
diff changeset
279 info->duration.fraction = length % 1000;
738
6ea974a229a8 [svn] - add read/write support for TLEN frame.
yaz
parents: 676
diff changeset
280 }
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
281 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
282 if (info->frames == 1) {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
283 /* 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
284 info->bitrate = header.bitrate;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
285 info->freq = header.samplerate;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
286 info->channels = MAD_NCHANNELS(&header);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
287 info->mpeg_layer = header.layer;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
288 info->mode = header.mode;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
289
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
290 if (audmad_config.use_xing) {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
291 frame.header = header;
674
fadf4c18a1cf [svn] madplug bug fix:
yaz
parents: 673
diff changeset
292 if (mad_frame_decode(&frame, &stream) == -1) {
fadf4c18a1cf [svn] madplug bug fix:
yaz
parents: 673
diff changeset
293 #ifdef DEBUG
773
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 768
diff changeset
294 g_message("xing frame decode failed");
674
fadf4c18a1cf [svn] madplug bug fix:
yaz
parents: 673
diff changeset
295 #endif
fadf4c18a1cf [svn] madplug bug fix:
yaz
parents: 673
diff changeset
296 goto no_xing;
fadf4c18a1cf [svn] madplug bug fix:
yaz
parents: 673
diff changeset
297 }
980
6ba4a4bfd127 [svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents: 959
diff changeset
298 if (xing_parse(&info->xing, stream.anc_ptr, stream.anc_bitlen) == 0) {
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
299 #ifdef DEBUG
980
6ba4a4bfd127 [svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents: 959
diff changeset
300 g_message("xing header found ");
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
301 #endif /* DEBUG */
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
302 has_xing = TRUE;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
303 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
304
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
305 #ifdef DEBUG
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
306 g_message("xing: bytes = %ld frames = %ld", 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
307 #endif
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
308 /* 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
309 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
310 xing_bitrate = 8 * (double)info->xing.bytes * 38 / (double)info->xing.frames; //38fps in MPEG1.
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
311 #ifdef DEBUG
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
312 {
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
313 gint tmp = (gint)(info->xing.bytes * 8 / 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
314 g_message("xing: bitrate = %4.1f kbps", xing_bitrate / 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
315 g_message("xing: duration = %d:%02d", tmp / 60, tmp % 60);
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
316 }
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
317 #endif
738
6ea974a229a8 [svn] - add read/write support for TLEN frame.
yaz
parents: 676
diff changeset
318 }
959
b2fbf53360cf [svn] bug fix for #897
yaz
parents: 925
diff changeset
319 continue;
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
320 }
980
6ba4a4bfd127 [svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents: 959
diff changeset
321 #ifdef DEBUG
6ba4a4bfd127 [svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents: 959
diff changeset
322 else {
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
323 g_message("no usable xing header");
980
6ba4a4bfd127 [svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents: 959
diff changeset
324 continue;
6ba4a4bfd127 [svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents: 959
diff changeset
325 }
6ba4a4bfd127 [svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents: 959
diff changeset
326
6ba4a4bfd127 [svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents: 959
diff changeset
327 #endif
6ba4a4bfd127 [svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents: 959
diff changeset
328 } /* xing */
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
329
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
330 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
331 else {
980
6ba4a4bfd127 [svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents: 959
diff changeset
332 /* 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
333 if (info->bitrate != header.bitrate)
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
334 info->vbr = TRUE;
673
8ed0af226d0e [svn] - calculate vbr bitrate properly.
yaz
parents: 627
diff changeset
335 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
336 accum_bitrate += (double)header.bitrate;
673
8ed0af226d0e [svn] - calculate vbr bitrate properly.
yaz
parents: 627
diff changeset
337 bitrate_frames++;
8ed0af226d0e [svn] - calculate vbr bitrate properly.
yaz
parents: 627
diff changeset
338 }
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
339 /* 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
340 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
341 g_warning("layer varies!!");
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
342 if (info->freq != header.samplerate)
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
343 g_warning("samplerate varies!!");
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
344 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
345 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
346 }
674
fadf4c18a1cf [svn] madplug bug fix:
yaz
parents: 673
diff changeset
347 no_xing:
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
348 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
349 float frame_size = ((double) data_used) / N_AVERAGE_FRAMES;
773
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 768
diff changeset
350 #ifdef DEBUG
980
6ba4a4bfd127 [svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents: 959
diff changeset
351 g_message("bitrate = %ld samplerate = %d", header.bitrate, header.samplerate);
6ba4a4bfd127 [svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents: 959
diff changeset
352 g_message("data_used = %d info->frames = %d info->size = %d tagsize = %d frame_size = %lf",
6ba4a4bfd127 [svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents: 959
diff changeset
353 data_used, info->frames, info->size, tagsize, frame_size);
773
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 768
diff changeset
354 #endif
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 768
diff changeset
355 if(info->size != 0)
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 768
diff changeset
356 info->frames = (info->size - tagsize) / frame_size;
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 768
diff changeset
357 #ifdef DEBUG
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 768
diff changeset
358 g_message("info->frames = %d", info->frames);
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 768
diff changeset
359 #endif
1687
d158ce84fda7 Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1485
diff changeset
360 if(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
361 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
362 /* 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
363 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
364 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
365 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
366 }
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
367 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
368 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
369 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
370 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
371 }
738
6ea974a229a8 [svn] - add read/write support for TLEN frame.
yaz
parents: 676
diff changeset
372 }
6ea974a229a8 [svn] - add read/write support for TLEN frame.
yaz
parents: 676
diff changeset
373 else {
1687
d158ce84fda7 Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1485
diff changeset
374 gint length = tuple_get_int(info->tuple, FIELD_LENGTH, NULL);
1428
4993976d7ed0 madplug: tuple API changes
William Pitcock <nenolod@atheme-project.org>
parents: 1344
diff changeset
375
4993976d7ed0 madplug: tuple API changes
William Pitcock <nenolod@atheme-project.org>
parents: 1344
diff changeset
376 info->duration.seconds = length / 1000;
4993976d7ed0 madplug: tuple API changes
William Pitcock <nenolod@atheme-project.org>
parents: 1344
diff changeset
377 info->duration.fraction = length % 1000;
738
6ea974a229a8 [svn] - add read/write support for TLEN frame.
yaz
parents: 676
diff changeset
378 }
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
379 #ifdef DEBUG
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
380 g_message("using fast playtime calculation");
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
381 g_message("data used = %d [tagsize=%d framesize=%f]",
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
382 data_used, tagsize, frame_size);
627
8829833d37bc [svn] Break out of the loop once we know the length. No using spinning around all day.
chainsaw
parents: 619
diff changeset
383 g_message("frames = %d, frequency = %d, channels = %d",
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
384 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
385 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
386 MAD_UNITS_MILLISECONDS);
980
6ba4a4bfd127 [svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents: 959
diff changeset
387 g_message("duration = %ld:%02ld", 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
388 #endif /* DEBUG */
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
389 break;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
390 }
980
6ba4a4bfd127 [svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents: 959
diff changeset
391 } /* while */
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
392 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
393 break;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
394 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
395
997
e46b98155d5d [svn] - fix a bug which counts number of frames twice in handling xing header.
yaz
parents: 980
diff changeset
396 if (info->xing.frames)
e46b98155d5d [svn] - fix a bug which counts number of frames twice in handling xing header.
yaz
parents: 980
diff changeset
397 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
398
980
6ba4a4bfd127 [svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents: 959
diff changeset
399 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
400 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
401 }
6ba4a4bfd127 [svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents: 959
diff changeset
402 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
403 info->bitrate = accum_bitrate / bitrate_frames;
959
b2fbf53360cf [svn] bug fix for #897
yaz
parents: 925
diff changeset
404 }
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
405
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
406 mad_frame_finish(&frame);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
407 mad_header_finish(&header);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
408 mad_stream_finish(&stream);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
409 xing_finish(&info->xing);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
410
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
411 #ifdef DEBUG
959
b2fbf53360cf [svn] bug fix for #897
yaz
parents: 925
diff changeset
412 g_message("scan_file: info->frames = %d", info->frames);
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
413 g_message("e: scan_file");
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
414 #endif /* DEBUG */
773
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 768
diff changeset
415 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
416 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
417
980
6ba4a4bfd127 [svn] - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
yaz
parents: 959
diff changeset
418 /* sanity check for audio open parameters */
896
f0846bdd9de6 [svn] - small cleanups.
yaz
parents: 807
diff changeset
419 static gboolean check_audio_param(struct mad_info_t *info)
f0846bdd9de6 [svn] - small cleanups.
yaz
parents: 807
diff changeset
420 {
f0846bdd9de6 [svn] - small cleanups.
yaz
parents: 807
diff changeset
421 if(info->fmt < FMT_U8 || info->fmt > FMT_S16_NE)
f0846bdd9de6 [svn] - small cleanups.
yaz
parents: 807
diff changeset
422 return FALSE;
f0846bdd9de6 [svn] - small cleanups.
yaz
parents: 807
diff changeset
423 if(info->freq < 0) // not sure about maximum frequency. --yaz
f0846bdd9de6 [svn] - small cleanups.
yaz
parents: 807
diff changeset
424 return FALSE;
f0846bdd9de6 [svn] - small cleanups.
yaz
parents: 807
diff changeset
425 if(info->channels < 1 || info->channels > 2)
f0846bdd9de6 [svn] - small cleanups.
yaz
parents: 807
diff changeset
426 return FALSE;
f0846bdd9de6 [svn] - small cleanups.
yaz
parents: 807
diff changeset
427
f0846bdd9de6 [svn] - small cleanups.
yaz
parents: 807
diff changeset
428 return TRUE;
f0846bdd9de6 [svn] - small cleanups.
yaz
parents: 807
diff changeset
429 }
f0846bdd9de6 [svn] - small cleanups.
yaz
parents: 807
diff changeset
430
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
431 gpointer decode_loop(gpointer arg)
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 unsigned char buffer[BUFFER_SIZE];
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
434 int len;
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
435 gboolean seek_skip = FALSE;
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
436 int remainder = 0;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
437 gint tlen;
673
8ed0af226d0e [svn] - calculate vbr bitrate properly.
yaz
parents: 627
diff changeset
438 unsigned int iteration = 0;
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
439
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
440 /* mad structs */
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
441 struct mad_stream stream;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
442 struct mad_frame frame;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
443 struct mad_synth synth;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
444
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
445 /* 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
446 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
447
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
448 #ifdef DEBUG
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
449 g_message("f: decode");
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
450 #endif /* DEBUG */
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
451
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
452 /* init mad stuff */
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
453 mad_frame_init(&frame);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
454 mad_stream_init(&stream);
925
3673bbab7372 [svn] - make madplug ignore crc error. closes #884.
yaz
parents: 924
diff changeset
455 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
456 mad_synth_init(&synth);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
457
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
458 if(!info->playback){
773
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 768
diff changeset
459 #ifdef DEBUG
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 768
diff changeset
460 g_message("decode: playback == NULL");
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 768
diff changeset
461 #endif
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
462 return NULL;
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
463 }
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
464
773
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 768
diff changeset
465 #ifdef DEBUG
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 768
diff changeset
466 g_message("decode: fmt = %d freq = %d channels = %d", info->fmt, info->freq, info->channels);
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 768
diff changeset
467 #endif
896
f0846bdd9de6 [svn] - small cleanups.
yaz
parents: 807
diff changeset
468
f0846bdd9de6 [svn] - small cleanups.
yaz
parents: 807
diff changeset
469 if(check_audio_param(info) == FALSE)
793
98cdc39031f9 [svn] - add sanity check for open audio parameters.
yaz
parents: 792
diff changeset
470 return NULL;
896
f0846bdd9de6 [svn] - small cleanups.
yaz
parents: 807
diff changeset
471
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
472 if (!info->playback->output->open_audio(info->fmt, info->freq, info->channels)) {
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
473 g_mutex_lock(pb_mutex);
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
474 info->playback->error = TRUE;
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
475 info->playback->eof = 1;
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
476 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
477 g_message("failed to open audio output: %s",
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
478 info->playback->output->description);
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
479 return NULL;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
480 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
481
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
482 /* set mainwin title */
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
483 if (info->title)
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
484 g_free(info->title);
1485
4e612b01f303 - make use of tuple_formatter_make_title_string(). now madplug can show file name if metadata is not available.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1473
diff changeset
485 info->title = tuple_formatter_make_title_string(info->tuple, audmad_config.title_override == TRUE ?
1473
eb0913bf54c3 use get_gentitle_format() to get format string so that presets and custom string can coexist.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1465
diff changeset
486 audmad_config.id3_format : get_gentitle_format());
1428
4993976d7ed0 madplug: tuple API changes
William Pitcock <nenolod@atheme-project.org>
parents: 1344
diff changeset
487
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
488 tlen = (gint) mad_timer_count(info->duration, MAD_UNITS_MILLISECONDS),
773
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 768
diff changeset
489 mad_plugin->set_info(info->title,
778
209b08a3eff6 [svn] - hide seek bar for unseekable (info->size = 0) stream.
yaz
parents: 773
diff changeset
490 (tlen == 0 || info->size <= 0) ? -1 : tlen,
773
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 768
diff changeset
491 info->bitrate, info->freq, info->channels);
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 768
diff changeset
492 #ifdef DEBUG
784
5ddfe9eac8ee [svn] - fix read_replaygain(). necessary fseek was missing in reuse fd code. closes #843.
yaz
parents: 783
diff changeset
493 g_message("decode: tlen = %d", tlen);
773
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 768
diff changeset
494 #endif
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
495
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
496 /* main loop */
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
497 do {
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
498 if (!info->playback->playing) {
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
499 #ifdef DEBUG
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
500 g_message("decode: stop signaled");
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
501 #endif /* DEBUG */
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
502 break;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
503 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
504 if (seek_skip)
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
505 remainder = 0;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
506 else {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
507 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
508 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
509 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
510 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
511 BUFFER_SIZE - remainder);
773
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 768
diff changeset
512
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 768
diff changeset
513 input_process_remote_metadata(info);
22c82f3c0411 [svn] - reduce connection latency to http stream.
yaz
parents: 768
diff changeset
514
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
515 if (len <= 0) {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
516 #ifdef DEBUG
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
517 g_message("finished decoding");
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
518 #endif /* DEBUG */
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
519 break;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
520 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
521 len += remainder;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
522 if (len < MAD_BUFFER_GUARD) {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
523 int i;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
524 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
525 buffer[i] = 0;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
526 len = MAD_BUFFER_GUARD;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
527 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
528
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
529 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
530
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
531 if (seek_skip) {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
532 #ifdef DEBUG
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
533 g_message("skipping: %d", seek_skip);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
534 #endif
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
535 int skip = 2;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
536 do {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
537 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
538 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
539 if (--skip == 0)
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
540 mad_synth_frame(&synth, &frame);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
541 }
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
542 else if (!MAD_RECOVERABLE(stream.error)) {
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
543 g_mutex_lock(pb_mutex);
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
544 info->playback->error = TRUE;
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
545 info->playback->eof = 1;
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
546 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
547 break;
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
548 }
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
549 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
550 while (skip);
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
551 seek_skip = FALSE;
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
552 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
553
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
554 while (info->playback->playing) {
778
209b08a3eff6 [svn] - hide seek bar for unseekable (info->size = 0) stream.
yaz
parents: 773
diff changeset
555 if (info->seek != -1 && info->size > 0) {
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
556 #ifdef DEBUG
896
f0846bdd9de6 [svn] - small cleanups.
yaz
parents: 807
diff changeset
557 g_message("seeking: %ld", info->seek);
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
558 #endif
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
559 int new_position;
807
0f9c8d4d3ac4 [svn] - make use of new millisecond seek API.
yaz
parents: 794
diff changeset
560 gulong milliseconds =
0f9c8d4d3ac4 [svn] - make use of new millisecond seek API.
yaz
parents: 794
diff changeset
561 mad_timer_count(info->duration, MAD_UNITS_MILLISECONDS);
0f9c8d4d3ac4 [svn] - make use of new millisecond seek API.
yaz
parents: 794
diff changeset
562 if (info->seek >= milliseconds)
0f9c8d4d3ac4 [svn] - make use of new millisecond seek API.
yaz
parents: 794
diff changeset
563 info->seek = milliseconds;
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
564
807
0f9c8d4d3ac4 [svn] - make use of new millisecond seek API.
yaz
parents: 794
diff changeset
565 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
566 new_position =
807
0f9c8d4d3ac4 [svn] - make use of new millisecond seek API.
yaz
parents: 794
diff changeset
567 ((double) info->seek / (double) milliseconds) * info->size;
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
568
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
569 if(new_position < 0)
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
570 new_position = 0;
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
571 #ifdef DEBUG
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
572 g_message("seeking to: %d bytes", new_position);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
573 #endif
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
574 if (vfs_fseek(info->infile, new_position, SEEK_SET) == -1)
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
575 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
576 mad_frame_mute(&frame);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
577 mad_synth_mute(&synth);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
578 stream.error = MAD_ERROR_BUFLEN;
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
579 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
580 stream.sync = 0;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
581 info->seek = -1;
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
582 seek_skip = TRUE;
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
583 break;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
584 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
585
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
586 if (mad_header_decode(&frame.header, &stream) == -1) {
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
587 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
588 break;
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
589 }
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
590 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
591 /* 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
592 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
593 stream.bufend -
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
594 stream.this_frame);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
595 if (tagsize > 0) {
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
596 mad_stream_skip(&stream, tagsize);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
597 continue;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
598 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
599 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
600 #ifdef DEBUG
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
601 g_message("(recovered) error decoding header %d: %s",
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
602 info->current_frame,
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
603 mad_stream_errorstr(&stream));
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
604 #endif /* DEBUG */
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
605 continue;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
606 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
607
673
8ed0af226d0e [svn] - calculate vbr bitrate properly.
yaz
parents: 627
diff changeset
608 info->bitrate = frame.header.bitrate;
8ed0af226d0e [svn] - calculate vbr bitrate properly.
yaz
parents: 627
diff changeset
609
778
209b08a3eff6 [svn] - hide seek bar for unseekable (info->size = 0) stream.
yaz
parents: 773
diff changeset
610 if (!audmad_config.show_avg_vbr_bitrate && info->vbr && (iteration % 40 == 0)) {
209b08a3eff6 [svn] - hide seek bar for unseekable (info->size = 0) stream.
yaz
parents: 773
diff changeset
611 #ifdef DEBUG
784
5ddfe9eac8ee [svn] - fix read_replaygain(). necessary fseek was missing in reuse fd code. closes #843.
yaz
parents: 783
diff changeset
612 #ifdef DEBUG_INTENSIVELY
778
209b08a3eff6 [svn] - hide seek bar for unseekable (info->size = 0) stream.
yaz
parents: 773
diff changeset
613 g_message("decode vbr tlen = %d", tlen);
209b08a3eff6 [svn] - hide seek bar for unseekable (info->size = 0) stream.
yaz
parents: 773
diff changeset
614 #endif
784
5ddfe9eac8ee [svn] - fix read_replaygain(). necessary fseek was missing in reuse fd code. closes #843.
yaz
parents: 783
diff changeset
615 #endif
673
8ed0af226d0e [svn] - calculate vbr bitrate properly.
yaz
parents: 627
diff changeset
616 mad_plugin->set_info(info->title,
778
209b08a3eff6 [svn] - hide seek bar for unseekable (info->size = 0) stream.
yaz
parents: 773
diff changeset
617 (tlen == 0 || info->size <= 0) ? -1 : tlen,
673
8ed0af226d0e [svn] - calculate vbr bitrate properly.
yaz
parents: 627
diff changeset
618 info->bitrate, info->freq, info->channels);
8ed0af226d0e [svn] - calculate vbr bitrate properly.
yaz
parents: 627
diff changeset
619 }
8ed0af226d0e [svn] - calculate vbr bitrate properly.
yaz
parents: 627
diff changeset
620 iteration++;
8ed0af226d0e [svn] - calculate vbr bitrate properly.
yaz
parents: 627
diff changeset
621
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
622 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
623 if (!MAD_RECOVERABLE(stream.error))
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
624 break;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
625 #ifdef DEBUG
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
626 g_message("(recovered) error decoding frame %d: %s",
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
627 info->current_frame,
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
628 mad_stream_errorstr(&stream));
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
629 #endif /* DEBUG */
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
630 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
631
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
632 info->current_frame++;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
633
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
634 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
635 || info->channels !=
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
636 (guint) MAD_NCHANNELS(&frame.header)) {
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
637 #ifdef DEBUG
916
a8494c2a87eb [svn] revise reopen output code for #880. time count would be reset if output was closed. so I took two measures for it.
yaz
parents: 896
diff changeset
638 g_message("change in audio type detected");
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
639 g_message("old: frequency = %d, channels = %d", info->freq,
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
640 info->channels);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
641 g_message("new: frequency = %d, channels = %d",
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
642 frame.header.samplerate,
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
643 (guint) MAD_NCHANNELS(&frame.header));
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
644 #endif /* DEBUG */
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
645 info->freq = frame.header.samplerate;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
646 info->channels = MAD_NCHANNELS(&frame.header);
794
93dbfe1f0cd0 [svn] - same sanity check on rarely executed part.
yaz
parents: 793
diff changeset
647
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
648 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
649 gint current_time = info->playback->output->output_time();
a8494c2a87eb [svn] revise reopen output code for #880. time count would be reset if output was closed. so I took two measures for it.
yaz
parents: 896
diff changeset
650 #ifdef DEBUG
a8494c2a87eb [svn] revise reopen output code for #880. time count would be reset if output was closed. so I took two measures for it.
yaz
parents: 896
diff changeset
651 g_message("re-opening audio due to change in audio type");
a8494c2a87eb [svn] revise reopen output code for #880. time count would be reset if output was closed. so I took two measures for it.
yaz
parents: 896
diff changeset
652 #endif
a8494c2a87eb [svn] revise reopen output code for #880. time count would be reset if output was closed. so I took two measures for it.
yaz
parents: 896
diff changeset
653 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
654 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
655 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
656 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
657 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
658 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
659 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
660 g_message("failed to re-open audio output: %s",
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
661 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
662 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
663 }
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
664 // 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
665 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
666 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
667 }
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
668
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
669 if (!info->playback->playing)
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
670 break;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
671 mad_synth_frame(&synth, &frame);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
672 mad_stream_sync(&stream);
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
673
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
674 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
675 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
676 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
677 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
678 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
679
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
680 /* free mad stuff */
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
681 mad_frame_finish(&frame);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
682 mad_stream_finish(&stream);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
683 mad_synth_finish(&synth);
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
684
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
685 if (info->playback->playing) {
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
686 GTimeVal sleeptime;
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
687
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
688 info->playback->output->buffer_free();
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
689 info->playback->output->buffer_free();
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
690 while (info->playback->output->buffer_playing()) {
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
691 #ifdef DEBUG
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
692 g_message("f: buffer_playing=%d",
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
693 info->playback->output->buffer_playing());
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
694 #endif
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
695 g_get_current_time(&sleeptime);
807
0f9c8d4d3ac4 [svn] - make use of new millisecond seek API.
yaz
parents: 794
diff changeset
696 g_time_val_add(&sleeptime, 500000);
0f9c8d4d3ac4 [svn] - make use of new millisecond seek API.
yaz
parents: 794
diff changeset
697
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
698 g_mutex_lock(mad_mutex);
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
699 g_cond_timed_wait(mad_cond, mad_mutex, &sleeptime);
896
f0846bdd9de6 [svn] - small cleanups.
yaz
parents: 807
diff changeset
700 g_mutex_unlock(mad_mutex);
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
701 if (!info->playback->playing) {
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
702 break;
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
703 }
896
f0846bdd9de6 [svn] - small cleanups.
yaz
parents: 807
diff changeset
704
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
705 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
706 }
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
707 #ifdef DEBUG
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
708 g_message("e: decode");
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
709 #endif /* DEBUG */
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
710
1465
db616ccdd40c use tuple_free(x) in place of mowgli_object_unref(x)
Giacomo Lozito <james@develia.org>
parents: 1428
diff changeset
711 tuple_free(info->tuple);
610
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
712 info->tuple = NULL;
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
713
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
714 info->playback->output->close_audio();
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
715 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
716 info->playback->playing = 0;
611
3f7a52adfe0e [svn] merge recent changes from yaz's branch.
yaz
parents: 610
diff changeset
717 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
718 return NULL; /* dummy */
862190d39e00 [svn] - add madplug. It is not yet hooked up, I'll do that later.
nenolod
parents:
diff changeset
719 }