annotate Plugins/Output/esd/audio.c @ 993:a9ac4beb4e15 trunk

[svn] Use taglib for length determination. Simpler code, might also deal better with some VBR MP3s if they have length info in their tags.
author chainsaw
date Sun, 30 Apr 2006 17:59:55 -0700
parents 55dc40ff1aff
children f12d7e208b43
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1 /* BMP - Cross-platform multimedia player
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
2 * Copyright (C) 2003-2004 BMP development team.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
3 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
4 * Based on XMMS:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
5 * Copyright (C) 1998-2003 XMMS development team.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
6 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
10 * (at your option) any later version.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
11 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
15 * GNU General Public License for more details.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
16 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
20 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
21
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
22 #include <glib.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
23 #include <stdlib.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
24 #include <string.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
25 #include <esd.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
26
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
27 #include <unistd.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
28
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
29 #include <libaudacious/util.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
30
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
31 #include "esdout.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
32
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
33
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
34 static gint fd = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
35 static gpointer buffer;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
36 static gboolean going = FALSE, paused = FALSE, prebuffer, remove_prebuffer;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
37 static gint buffer_size, prebuffer_size, blk_size = 4096;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
38 static gint rd_index = 0, wr_index = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
39 static gint output_time_offset = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
40 static guint64 written = 0, output_bytes = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
41 static gint bps, ebps;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
42 static gint flush;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
43 static gint format, channels, frequency, latency;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
44 static esd_format_t esd_format;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
45 static gint input_bps, input_format, input_frequency, input_channels;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
46 static GThread *buffer_thread;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
47 static gboolean realtime = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
48 static void *(*esd_translate) (void *, gint);
488
cb0f36590d98 [svn] ESD output plugin enhancements by max_verem -at- yahoo.com.
nenolod
parents: 61
diff changeset
49 static int player_id_unique = 0;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
50
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
51 static gint
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
52 get_latency(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
53 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
54 int fd, amount = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
55
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
56 #ifndef HAVE_ESD_GET_LATENCY
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
57 esd_server_info_t *info;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
58 #endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
59
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
60 fd = esd_open_sound(esd_cfg.hostname);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
62 if (fd == -1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
63 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
64
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
65 #ifdef HAVE_ESD_GET_LATENCY
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
66 amount = esd_get_latency(fd);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
67 #else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
68 info = esd_get_server_info(fd);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
69 if (info) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
70 if (info->format & ESD_STEREO) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
71 if (info->format & ESD_BITS16)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
72 amount = (44100 * (ESD_BUF_SIZE + 64)) / info->rate;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
73 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
74 amount = (44100 * (ESD_BUF_SIZE + 128)) / info->rate;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
75 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
76 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
77 if (info->format & ESD_BITS16)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
78 amount = (2 * 44100 * (ESD_BUF_SIZE + 128)) / info->rate;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
79 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
80 amount = (2 * 44100 * (ESD_BUF_SIZE + 256)) / info->rate;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
81 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
82 free(info);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
83 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
84 amount += ESD_BUF_SIZE * 2;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
85 #endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
86 esd_close(fd);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
87 return amount;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
88 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
89
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
90 static void *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
91 esd_stou8(void *data, gint length)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
92 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
93 int len = length;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
94 unsigned char *dat = (unsigned char *) data;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
95 while (len-- > 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
96 *dat++ ^= 0x80;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
97 return data;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
98 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
99
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
100 static void *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
101 esd_utos16sw(void *data, gint length)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
102 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
103 int len = length;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
104 short *dat = data;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
105 while (len > 0) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
106 *dat = GUINT16_SWAP_LE_BE(*dat) ^ 0x8000;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
107 dat++;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
108 len -= 2;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
109 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
110 return data;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
111 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
112
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
113 static void *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
114 esd_utos16(void *data, gint length)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
115 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
116 int len = length;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
117 short *dat = data;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
118 while (len > 0) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
119 *dat ^= 0x8000;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
120 dat++;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
121 len -= 2;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
122 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
123 return data;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
124 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
125
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
126 static void *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
127 esd_16sw(void *data, gint length)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
128 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
129 int len = length;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
130 short *dat = data;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
131 while (len > 0) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
132 *dat = GUINT16_SWAP_LE_BE(*dat);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
133 dat++;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
134 len -= 2;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
135 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
136 return data;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
137 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
138
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
139 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
140 esdout_setup_format(AFormat fmt, gint rate, gint nch)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
141 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
142 gboolean swap_sign = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
143 gboolean swap_16 = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
144
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
145 format = fmt;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
146 frequency = rate;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
147 channels = nch;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
148 switch (fmt) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
149 case FMT_S8:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
150 swap_sign = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
151 case FMT_U8:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
152 esd_format = ESD_BITS8;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
153 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
154 case FMT_U16_LE:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
155 case FMT_U16_BE:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
156 case FMT_U16_NE:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
157 swap_sign = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
158 case FMT_S16_LE:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
159 case FMT_S16_BE:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
160 case FMT_S16_NE:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
161 esd_format = ESD_BITS16;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
162 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
163 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
164
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
165 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
166 if (fmt == FMT_U16_LE || fmt == FMT_S16_LE)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
167 #else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
168 if (fmt == FMT_U16_BE || fmt == FMT_S16_BE)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
169 #endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
170 swap_16 = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
171
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
172 esd_translate = (void *(*)()) NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
173 if (esd_format == ESD_BITS8) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
174 if (swap_sign == TRUE)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
175 esd_translate = esd_stou8;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
176 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
177 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
178 if (swap_sign == TRUE) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
179 if (swap_16 == TRUE)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
180 esd_translate = esd_utos16sw;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
181 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
182 esd_translate = esd_utos16;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
183 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
184 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
185 if (swap_16 == TRUE)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
186 esd_translate = esd_16sw;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
187 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
188 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
189
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
190 bps = rate * nch;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
191 if (esd_format == ESD_BITS16)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
192 bps *= 2;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
193 if (nch == 1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
194 esd_format |= ESD_MONO;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
195 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
196 esd_format |= ESD_STEREO;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
197 esd_format |= ESD_STREAM | ESD_PLAY;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
198
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
199 latency = ((get_latency() * frequency) / 44100) * channels;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
200 if (format != FMT_U8 && format != FMT_S8)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
201 latency *= 2;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
202 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
203
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
204
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
205 gint
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
206 esdout_get_written_time(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
207 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
208 if (!going)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
209 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
210 return (gint) ((written * 1000) / input_bps);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
211 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
212
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
213 gint
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
214 esdout_get_output_time(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
215 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
216 guint64 bytes;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
217
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
218 if (!fd || !going)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
219 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
220
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
221 bytes = output_bytes;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
222 if (!paused)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
223 bytes -= (bytes < latency ? bytes : latency);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
224
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
225 return output_time_offset + (gint) ((bytes * 1000) / ebps);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
226 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
227
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
228 gint
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
229 esdout_used(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
230 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
231 if (realtime)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
232 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
233 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
234 if (wr_index >= rd_index)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
235 return wr_index - rd_index;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
236 return buffer_size - (rd_index - wr_index);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
237 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
238 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
239
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
240 gint
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
241 esdout_playing(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
242 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
243 if (!going)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
244 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
245 if (!esdout_used())
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
246 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
247
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
248 return TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
249 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
250
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
251 gint
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
252 esdout_free(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
253 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
254 if (!realtime) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
255 if (remove_prebuffer && prebuffer) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
256 prebuffer = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
257 remove_prebuffer = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
258 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
259 if (prebuffer)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
260 remove_prebuffer = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
261
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
262 if (rd_index > wr_index)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
263 return (rd_index - wr_index) - 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
264 return (buffer_size - (wr_index - rd_index)) - 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
265 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
266 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
267 if (paused)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
268 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
269 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
270 return 1000000;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
271 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
272 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
273
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
274 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
275 esdout_write_audio(gpointer data, gint length)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
276 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
277 AFormat new_format;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
278 gint new_frequency, new_channels;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
279 EffectPlugin *ep;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
280
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
281 new_format = input_format;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
282 new_frequency = input_frequency;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
283 new_channels = input_channels;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
284
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
285 ep = get_current_effect_plugin();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
286 if (effects_enabled() && ep && ep->query_format) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
287 ep->query_format(&new_format, &new_frequency, &new_channels);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
288 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
289
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
290 if (new_format != format || new_frequency != frequency
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
291 || new_channels != channels) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
292 output_time_offset += (gint) ((output_bytes * 1000) / ebps);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
293 output_bytes = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
294 esdout_setup_format(new_format, new_frequency, new_channels);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
295 frequency = new_frequency;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
296 channels = new_channels;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
297 esd_close(fd);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
298 esdout_set_audio_params();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
299 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
300 if (effects_enabled() && ep && ep->mod_samples)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
301 length =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
302 ep->mod_samples(&data, length, input_format, input_frequency,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
303 input_channels);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
304 if (esd_translate)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
305 output_bytes += write(fd, esd_translate(data, length), length);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
306 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
307 output_bytes += write(fd, data, length);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
308 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
309
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
310
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
311 void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
312 esdout_write(gpointer ptr, gint length)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
313 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
314 gint cnt, off = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
315
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
316 if (!realtime) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
317 remove_prebuffer = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
318
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
319 written += length;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
320 while (length > 0) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
321 cnt = MIN(length, buffer_size - wr_index);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
322 memcpy((gchar *) buffer + wr_index, (gchar *) ptr + off, cnt);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
323 wr_index = (wr_index + cnt) % buffer_size;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
324 length -= cnt;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
325 off += cnt;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
326
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
327 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
328 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
329 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
330 if (paused)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
331 return;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
332 esdout_write_audio(ptr, length);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
333 written += length;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
334
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
335 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
336
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
337 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
338
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
339 void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
340 esdout_close(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
341 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
342 if (!going)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
343 return;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
344
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
345 going = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
346
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
347 if (!realtime)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
348 g_thread_join(buffer_thread);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
349 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
350 esd_close(fd);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
351
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
352 wr_index = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
353 rd_index = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
354 g_free(esd_cfg.playername);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
355 esd_cfg.playername = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
356 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
357
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
358 void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
359 esdout_flush(gint time)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
360 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
361 if (!realtime) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
362 flush = time;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
363 while (flush != -1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
364 g_usleep(10000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
365 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
366 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
367 output_time_offset = time;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
368 written = (guint64) (time / 10) * (guint64) (input_bps / 100);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
369 output_bytes = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
370 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
371 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
372
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
373 void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
374 esdout_pause(short p)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
375 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
376 paused = p;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
377 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
378
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
379 gpointer
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
380 esdout_loop(gpointer arg)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
381 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
382 gint length, cnt;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
383
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
384
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
385 while (going) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
386 if (esdout_used() > prebuffer_size)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
387 prebuffer = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
388 if (esdout_used() > 0 && !paused && !prebuffer) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
389 length = MIN(blk_size, esdout_used());
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
390 while (length > 0) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
391 cnt = MIN(length, buffer_size - rd_index);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
392 esdout_write_audio((gchar *) buffer + rd_index, cnt);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
393 rd_index = (rd_index + cnt) % buffer_size;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
394 length -= cnt;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
395 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
396 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
397 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
398 g_usleep(10000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
399
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
400 if (flush != -1) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
401 output_time_offset = flush;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
402 written = (guint64) (flush / 10) * (guint64) (input_bps / 100);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
403 rd_index = wr_index = output_bytes = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
404 flush = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
405 prebuffer = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
406 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
407
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
408 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
409
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
410 esd_close(fd);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
411 g_free(buffer);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
412 return NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
413 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
414
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
415 void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
416 esdout_set_audio_params(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
417 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
418 fd = esd_play_stream(esd_format, frequency,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
419 esd_cfg.hostname, esd_cfg.playername);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
420 /* Set the stream's mixer */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
421 if (fd != -1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
422 esdout_mixer_init();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
423 ebps = frequency * channels;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
424 if (format == FMT_U16_BE || format == FMT_U16_LE ||
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
425 format == FMT_S16_BE || format == FMT_S16_LE ||
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
426 format == FMT_S16_NE || format == FMT_U16_NE)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
427 ebps *= 2;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
428 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
429
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
430 gint
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
431 esdout_open(AFormat fmt, gint rate, gint nch)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
432 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
433 esdout_setup_format(fmt, rate, nch);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
434
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
435 input_format = format;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
436 input_channels = channels;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
437 input_frequency = frequency;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
438 input_bps = bps;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
439
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
440 realtime = xmms_check_realtime_priority();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
441
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
442 if (!realtime) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
443 buffer_size = (esd_cfg.buffer_size * input_bps) / 1000;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
444 if (buffer_size < 8192)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
445 buffer_size = 8192;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
446 prebuffer_size = (buffer_size * esd_cfg.prebuffer) / 100;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
447 if (buffer_size - prebuffer_size < 4096)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
448 prebuffer_size = buffer_size - 4096;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
449
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
450 buffer = g_malloc0(buffer_size);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
451 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
452 flush = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
453 prebuffer = 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
454 wr_index = rd_index = output_time_offset = written = output_bytes = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
455 paused = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
456 remove_prebuffer = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
457
488
cb0f36590d98 [svn] ESD output plugin enhancements by max_verem -at- yahoo.com.
nenolod
parents: 61
diff changeset
458 esd_cfg.playername = g_strdup_printf("xmms - plugin (%d) [%d]", getpid(), player_id_unique++);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
459
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
460 if (esd_cfg.hostname)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
461 g_free(esd_cfg.hostname);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
462 if (esd_cfg.use_remote)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
463 esd_cfg.hostname =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
464 g_strdup_printf("%s:%d", esd_cfg.server, esd_cfg.port);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
465 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
466 esd_cfg.hostname = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
467
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
468 esdout_set_audio_params();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
469 if (fd == -1) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
470 g_free(esd_cfg.playername);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
471 esd_cfg.playername = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
472 g_free(buffer);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
473 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
474 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
475 going = 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
476
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
477 if (!realtime)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
478 buffer_thread = g_thread_create(esdout_loop, NULL, TRUE, NULL);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
479 return 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
480 }
517
55dc40ff1aff [svn] Add tell_audio(AFormat *, gint *, gint *), for retrieving audio
nenolod
parents: 488
diff changeset
481
55dc40ff1aff [svn] Add tell_audio(AFormat *, gint *, gint *), for retrieving audio
nenolod
parents: 488
diff changeset
482 void
55dc40ff1aff [svn] Add tell_audio(AFormat *, gint *, gint *), for retrieving audio
nenolod
parents: 488
diff changeset
483 esdout_tell(AFormat * fmt, gint * rate, gint * nch)
55dc40ff1aff [svn] Add tell_audio(AFormat *, gint *, gint *), for retrieving audio
nenolod
parents: 488
diff changeset
484 {
55dc40ff1aff [svn] Add tell_audio(AFormat *, gint *, gint *), for retrieving audio
nenolod
parents: 488
diff changeset
485 (*fmt) = format;
55dc40ff1aff [svn] Add tell_audio(AFormat *, gint *, gint *), for retrieving audio
nenolod
parents: 488
diff changeset
486 (*rate) = frequency;
55dc40ff1aff [svn] Add tell_audio(AFormat *, gint *, gint *), for retrieving audio
nenolod
parents: 488
diff changeset
487 (*nch) = channels;
55dc40ff1aff [svn] Add tell_audio(AFormat *, gint *, gint *), for retrieving audio
nenolod
parents: 488
diff changeset
488 }