annotate src/alsa/audio.c @ 3149:4b50e2a0ae1f

Branch merge.
author William Pitcock <nenolod@atheme.org>
date Mon, 11 May 2009 12:25:48 -0500
parents a6a57fe6a75c
children 3a1d7d680816
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1 /* XMMS - ALSA output plugin
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
2 * Copyright (C) 2001-2003 Matthieu Sozeau <mattam@altern.org>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
3 * Copyright (C) 1998-2003 Peter Alm, Mikael Alm, Olle Hallnas,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
4 * Thomas Nilsson and 4Front Technologies
1479
7b3aa5513041 Port some changes over from XMMS that:
William Pitcock <nenolod@atheme-project.org>
parents: 1131
diff changeset
5 * Copyright (C) 1999-2006 Haavard Kvaalen
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
6 * Copyright (C) 2005 Takashi Iwai
2353
415e67d313ad Experimental 24-bit support. Can someone test this? It doesn't work for me.
William Pitcock <nenolod@atheme.org>
parents: 2228
diff changeset
7 * Copyright (C) 2007-2008 William Pitcock
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
8 *
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
9 * This program is free software; you can redistribute it and/or modify
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
12 * (at your option) any later version.
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
13 *
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
17 * GNU General Public License for more details.
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
18 *
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
20 * along with this program; if not, write to the Free Software
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
22 */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
23
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
24 /*
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
25 * CHANGES
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
26 *
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
27 * 2005.01.05 Takashi Iwai <tiwai@suse.de>
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
28 * Impelemented the multi-threaded mode with an audio-thread.
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
29 * Many fixes and cleanups.
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
30 */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
31
2377
9056897525e1 pretend to be stopped when buffer is free. needed for correct waiting for free buffer
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2353
diff changeset
32 /*#define AUD_DEBUG*/
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
33
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
34 #include "alsa.h"
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
35 #include <ctype.h>
1479
7b3aa5513041 Port some changes over from XMMS that:
William Pitcock <nenolod@atheme-project.org>
parents: 1131
diff changeset
36 #include <math.h>
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
37
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
38 static snd_pcm_t *alsa_pcm;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
39 static snd_output_t *logs;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
40
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
41
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
42 /* Number of bytes that we have received from the input plugin */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
43 static guint64 alsa_total_written;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
44 /* Number of bytes that we have sent to the sound card */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
45 static guint64 alsa_hw_written;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
46 static guint64 output_time_offset;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
47
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
48 /* device buffer/period sizes in bytes */
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
49 static gint hw_buffer_size, hw_period_size; /* in output bytes */
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
50 static gint hw_buffer_size_in, hw_period_size_in; /* in input bytes */
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
51
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
52 /* Set/Get volume */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
53 static snd_mixer_elem_t *pcm_element;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
54 static snd_mixer_t *mixer;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
55
2477
11f7c096f7e6 Do NOT use 'volatile' keyword!
Matti Hamalainen <ccr@tnsp.org>
parents: 2457
diff changeset
56 static gboolean going, paused, mixer_start = TRUE;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
57 static gboolean prebuffer, remove_prebuffer;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
58
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
59 static gboolean alsa_can_pause;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
60
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
61 /* for audio thread */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
62 static GThread *audio_thread; /* audio loop thread */
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
63 static gint thread_buffer_size; /* size of intermediate buffer in bytes */
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
64 static gchar *thread_buffer; /* audio intermediate buffer */
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
65 static gint rd_index, wr_index; /* current read/write position in int-buffer */
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
66 static gboolean pause_request; /* pause status currently requested */
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
67 static gint flush_request; /* flush status (time) currently requested */
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
68 static gint prebuffer_size;
1753
c730f0212456 Use a GStaticMutex instead of a GMutex to avoid crashing and resource conflicts.
William Pitcock <nenolod@atheme.org>
parents: 1728
diff changeset
69 GStaticMutex alsa_mutex = G_STATIC_MUTEX_INIT;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
70
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
71 struct snd_format {
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
72 guint rate;
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
73 guint channels;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
74 snd_pcm_format_t format;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
75 AFormat xmms_format;
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
76 gint sample_bits;
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
77 gint bps;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
78 };
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
79
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
80 static struct snd_format *inputf = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
81 static struct snd_format *outputf = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
82
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
83 static gint alsa_setup(struct snd_format *f);
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
84 static void alsa_write_audio(gchar *data, gint length);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
85 static void alsa_cleanup_mixer(void);
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
86 static gint get_thread_buffer_filled(void);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
87
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
88 static struct snd_format * snd_format_from_xmms(AFormat fmt, gint rate, gint channels);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
89
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
90 static const struct {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
91 AFormat xmms;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
92 snd_pcm_format_t alsa;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
93 } format_table[] =
2353
415e67d313ad Experimental 24-bit support. Can someone test this? It doesn't work for me.
William Pitcock <nenolod@atheme.org>
parents: 2228
diff changeset
94 {
415e67d313ad Experimental 24-bit support. Can someone test this? It doesn't work for me.
William Pitcock <nenolod@atheme.org>
parents: 2228
diff changeset
95 #if 0
415e67d313ad Experimental 24-bit support. Can someone test this? It doesn't work for me.
William Pitcock <nenolod@atheme.org>
parents: 2228
diff changeset
96 /* i don't know if we will ever do this --nenolod */
415e67d313ad Experimental 24-bit support. Can someone test this? It doesn't work for me.
William Pitcock <nenolod@atheme.org>
parents: 2228
diff changeset
97 {FMT_S32_LE, SND_PCM_FORMAT_S32_LE},
415e67d313ad Experimental 24-bit support. Can someone test this? It doesn't work for me.
William Pitcock <nenolod@atheme.org>
parents: 2228
diff changeset
98 {FMT_S32_BE, SND_PCM_FORMAT_S32_BE},
415e67d313ad Experimental 24-bit support. Can someone test this? It doesn't work for me.
William Pitcock <nenolod@atheme.org>
parents: 2228
diff changeset
99 {FMT_S32_NE, SND_PCM_FORMAT_S32},
415e67d313ad Experimental 24-bit support. Can someone test this? It doesn't work for me.
William Pitcock <nenolod@atheme.org>
parents: 2228
diff changeset
100 #endif
415e67d313ad Experimental 24-bit support. Can someone test this? It doesn't work for me.
William Pitcock <nenolod@atheme.org>
parents: 2228
diff changeset
101 {FMT_S24_LE, SND_PCM_FORMAT_S24_LE},
415e67d313ad Experimental 24-bit support. Can someone test this? It doesn't work for me.
William Pitcock <nenolod@atheme.org>
parents: 2228
diff changeset
102 {FMT_S24_BE, SND_PCM_FORMAT_S24_BE},
415e67d313ad Experimental 24-bit support. Can someone test this? It doesn't work for me.
William Pitcock <nenolod@atheme.org>
parents: 2228
diff changeset
103 {FMT_S24_NE, SND_PCM_FORMAT_S24},
415e67d313ad Experimental 24-bit support. Can someone test this? It doesn't work for me.
William Pitcock <nenolod@atheme.org>
parents: 2228
diff changeset
104 {FMT_U24_LE, SND_PCM_FORMAT_U24_LE},
415e67d313ad Experimental 24-bit support. Can someone test this? It doesn't work for me.
William Pitcock <nenolod@atheme.org>
parents: 2228
diff changeset
105 {FMT_U24_BE, SND_PCM_FORMAT_U24_BE},
415e67d313ad Experimental 24-bit support. Can someone test this? It doesn't work for me.
William Pitcock <nenolod@atheme.org>
parents: 2228
diff changeset
106 {FMT_U24_NE, SND_PCM_FORMAT_U24},
415e67d313ad Experimental 24-bit support. Can someone test this? It doesn't work for me.
William Pitcock <nenolod@atheme.org>
parents: 2228
diff changeset
107 {FMT_S16_LE, SND_PCM_FORMAT_S16_LE},
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
108 {FMT_S16_BE, SND_PCM_FORMAT_S16_BE},
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
109 {FMT_S16_NE, SND_PCM_FORMAT_S16},
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
110 {FMT_U16_LE, SND_PCM_FORMAT_U16_LE},
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
111 {FMT_U16_BE, SND_PCM_FORMAT_U16_BE},
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
112 {FMT_U16_NE, SND_PCM_FORMAT_U16},
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
113 {FMT_U8, SND_PCM_FORMAT_U8},
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
114 {FMT_S8, SND_PCM_FORMAT_S8},
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
115 };
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
116
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
117
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
118 static void debug(gchar *str, ...) G_GNUC_PRINTF(1, 2);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
119
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
120 static void debug(gchar *str, ...)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
121 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
122 va_list args;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
123
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
124 if (alsa_cfg.debug)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
125 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
126 va_start(args, str);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
127 g_logv(NULL, G_LOG_LEVEL_MESSAGE, str, args);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
128 va_end(args);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
129 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
130 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
131
3003
8b7a44631121 Add hardware_present probe for a meaningful return code. Probe priority 1.
Tony Vroon <chainsaw@gentoo.org>
parents: 2987
diff changeset
132 int alsa_hardware_present(void)
8b7a44631121 Add hardware_present probe for a meaningful return code. Probe priority 1.
Tony Vroon <chainsaw@gentoo.org>
parents: 2987
diff changeset
133 {
3054
919ec26c66c3 Do not assign the result of snd_card_next, we do not care about it. Code analysis, unique ID HQvjgU.
Tony Vroon <chainsaw@gentoo.org>
parents: 3003
diff changeset
134 gint card = -1;
3003
8b7a44631121 Add hardware_present probe for a meaningful return code. Probe priority 1.
Tony Vroon <chainsaw@gentoo.org>
parents: 2987
diff changeset
135
3054
919ec26c66c3 Do not assign the result of snd_card_next, we do not care about it. Code analysis, unique ID HQvjgU.
Tony Vroon <chainsaw@gentoo.org>
parents: 3003
diff changeset
136 if ((snd_card_next(&card)) != 0)
3003
8b7a44631121 Add hardware_present probe for a meaningful return code. Probe priority 1.
Tony Vroon <chainsaw@gentoo.org>
parents: 2987
diff changeset
137 return 0;
8b7a44631121 Add hardware_present probe for a meaningful return code. Probe priority 1.
Tony Vroon <chainsaw@gentoo.org>
parents: 2987
diff changeset
138
8b7a44631121 Add hardware_present probe for a meaningful return code. Probe priority 1.
Tony Vroon <chainsaw@gentoo.org>
parents: 2987
diff changeset
139 return 1;
8b7a44631121 Add hardware_present probe for a meaningful return code. Probe priority 1.
Tony Vroon <chainsaw@gentoo.org>
parents: 2987
diff changeset
140 }
8b7a44631121 Add hardware_present probe for a meaningful return code. Probe priority 1.
Tony Vroon <chainsaw@gentoo.org>
parents: 2987
diff changeset
141
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
142 int alsa_playing(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
143 {
3149
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
144 gint ret;
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
145
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
146 g_static_mutex_lock(&alsa_mutex);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
147
3149
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
148 if (!going || paused || prebuffer || alsa_pcm == NULL)
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
149 ret = FALSE;
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
150 else
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
151 ret = snd_pcm_state(alsa_pcm) == SND_PCM_STATE_RUNNING &&
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
152 !paused &&
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
153 !prebuffer &&
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
154 get_thread_buffer_filled() > hw_period_size_in;
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
155
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
156 g_static_mutex_unlock(&alsa_mutex);
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
157
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
158 return ret;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
159 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
160
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
161 static gint
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
162 alsa_recovery(gint err)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
163 {
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
164 gint err2;
1727
9d6de95dd7ed Clean up and rework xrun/suspend handling, and add myself to Copyright holders.
William Pitcock <nenolod@atheme.org>
parents: 1725
diff changeset
165
9d6de95dd7ed Clean up and rework xrun/suspend handling, and add myself to Copyright holders.
William Pitcock <nenolod@atheme.org>
parents: 1725
diff changeset
166 /* if debug mode is enabled, dump ALSA state to console */
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
167 if (alsa_cfg.debug)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
168 {
2022
c6023e5efd06 warning fixes
William Pitcock <nenolod@atheme.org>
parents: 1934
diff changeset
169 snd_pcm_status_t *alsa_status = NULL;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
170 snd_pcm_status_alloca(&alsa_status);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
171 if (snd_pcm_status(alsa_pcm, alsa_status) < 0)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
172 g_warning("xrun_recover(): snd_pcm_status() failed");
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
173 else
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
174 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
175 printf("Status:\n");
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
176 snd_pcm_status_dump(alsa_status, logs);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
177 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
178 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
179
1727
9d6de95dd7ed Clean up and rework xrun/suspend handling, and add myself to Copyright holders.
William Pitcock <nenolod@atheme.org>
parents: 1725
diff changeset
180 /*
9d6de95dd7ed Clean up and rework xrun/suspend handling, and add myself to Copyright holders.
William Pitcock <nenolod@atheme.org>
parents: 1725
diff changeset
181 * specifically handle -EPIPE and -ESTRPIPE to recover
9d6de95dd7ed Clean up and rework xrun/suspend handling, and add myself to Copyright holders.
William Pitcock <nenolod@atheme.org>
parents: 1725
diff changeset
182 * PCM fragment periods without losing data.
9d6de95dd7ed Clean up and rework xrun/suspend handling, and add myself to Copyright holders.
William Pitcock <nenolod@atheme.org>
parents: 1725
diff changeset
183 */
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
184 switch (err)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
185 {
1934
c62011e48c61 alsa_recovery(): some bugfixes.
William Pitcock <nenolod@atheme.org>
parents: 1753
diff changeset
186 case -ESTRPIPE:
c62011e48c61 alsa_recovery(): some bugfixes.
William Pitcock <nenolod@atheme.org>
parents: 1753
diff changeset
187 case ESTRPIPE: /* "suspend": wait until ALSA is "running" again. */
1727
9d6de95dd7ed Clean up and rework xrun/suspend handling, and add myself to Copyright holders.
William Pitcock <nenolod@atheme.org>
parents: 1725
diff changeset
188 while ((err2 = snd_pcm_resume(alsa_pcm)) == -EAGAIN)
9d6de95dd7ed Clean up and rework xrun/suspend handling, and add myself to Copyright holders.
William Pitcock <nenolod@atheme.org>
parents: 1725
diff changeset
189 g_usleep(100000);
9d6de95dd7ed Clean up and rework xrun/suspend handling, and add myself to Copyright holders.
William Pitcock <nenolod@atheme.org>
parents: 1725
diff changeset
190
9d6de95dd7ed Clean up and rework xrun/suspend handling, and add myself to Copyright holders.
William Pitcock <nenolod@atheme.org>
parents: 1725
diff changeset
191 if (err2 < 0)
9d6de95dd7ed Clean up and rework xrun/suspend handling, and add myself to Copyright holders.
William Pitcock <nenolod@atheme.org>
parents: 1725
diff changeset
192 return snd_pcm_prepare(alsa_pcm);
9d6de95dd7ed Clean up and rework xrun/suspend handling, and add myself to Copyright holders.
William Pitcock <nenolod@atheme.org>
parents: 1725
diff changeset
193
9d6de95dd7ed Clean up and rework xrun/suspend handling, and add myself to Copyright holders.
William Pitcock <nenolod@atheme.org>
parents: 1725
diff changeset
194 break;
9d6de95dd7ed Clean up and rework xrun/suspend handling, and add myself to Copyright holders.
William Pitcock <nenolod@atheme.org>
parents: 1725
diff changeset
195
1934
c62011e48c61 alsa_recovery(): some bugfixes.
William Pitcock <nenolod@atheme.org>
parents: 1753
diff changeset
196 case -EPIPE:
c62011e48c61 alsa_recovery(): some bugfixes.
William Pitcock <nenolod@atheme.org>
parents: 1753
diff changeset
197 case EPIPE: /* under-run and the I/O pipe closed on us */
1727
9d6de95dd7ed Clean up and rework xrun/suspend handling, and add myself to Copyright holders.
William Pitcock <nenolod@atheme.org>
parents: 1725
diff changeset
198 return snd_pcm_prepare(alsa_pcm);
9d6de95dd7ed Clean up and rework xrun/suspend handling, and add myself to Copyright holders.
William Pitcock <nenolod@atheme.org>
parents: 1725
diff changeset
199 break;
9d6de95dd7ed Clean up and rework xrun/suspend handling, and add myself to Copyright holders.
William Pitcock <nenolod@atheme.org>
parents: 1725
diff changeset
200
1934
c62011e48c61 alsa_recovery(): some bugfixes.
William Pitcock <nenolod@atheme.org>
parents: 1753
diff changeset
201 case EINTR:
c62011e48c61 alsa_recovery(): some bugfixes.
William Pitcock <nenolod@atheme.org>
parents: 1753
diff changeset
202 case -EINTR:
c62011e48c61 alsa_recovery(): some bugfixes.
William Pitcock <nenolod@atheme.org>
parents: 1753
diff changeset
203 break;
c62011e48c61 alsa_recovery(): some bugfixes.
William Pitcock <nenolod@atheme.org>
parents: 1753
diff changeset
204
1727
9d6de95dd7ed Clean up and rework xrun/suspend handling, and add myself to Copyright holders.
William Pitcock <nenolod@atheme.org>
parents: 1725
diff changeset
205 default:
9d6de95dd7ed Clean up and rework xrun/suspend handling, and add myself to Copyright holders.
William Pitcock <nenolod@atheme.org>
parents: 1725
diff changeset
206 g_warning("Unhandled ALSA exception code %d (%s), trying hard restart.", err, snd_strerror(err));
9d6de95dd7ed Clean up and rework xrun/suspend handling, and add myself to Copyright holders.
William Pitcock <nenolod@atheme.org>
parents: 1725
diff changeset
207 return snd_pcm_prepare(alsa_pcm);
9d6de95dd7ed Clean up and rework xrun/suspend handling, and add myself to Copyright holders.
William Pitcock <nenolod@atheme.org>
parents: 1725
diff changeset
208 break;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
209 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
210
1727
9d6de95dd7ed Clean up and rework xrun/suspend handling, and add myself to Copyright holders.
William Pitcock <nenolod@atheme.org>
parents: 1725
diff changeset
211 return 0;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
212 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
213
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
214 /* update and get the available space on h/w buffer (in frames) */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
215 static snd_pcm_sframes_t alsa_get_avail(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
216 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
217 snd_pcm_sframes_t ret;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
218
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
219 if (alsa_pcm == NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
220 return 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
221
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
222 while ((ret = snd_pcm_avail_update(alsa_pcm)) < 0)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
223 {
1727
9d6de95dd7ed Clean up and rework xrun/suspend handling, and add myself to Copyright holders.
William Pitcock <nenolod@atheme.org>
parents: 1725
diff changeset
224 ret = alsa_recovery(ret);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
225 if (ret < 0)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
226 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
227 g_warning("alsa_get_avail(): snd_pcm_avail_update() failed: %s",
1725
f9856ca98943 Pass literal values to snd_strerror(), as passing -err will cause an invalid dereference in any modern ALSA.
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
228 snd_strerror(ret));
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
229 return 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
230 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
231 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
232 return ret;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
233 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
234
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
235 /* get the free space on buffer */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
236 int alsa_free(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
237 {
3149
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
238 gint ret;
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
239
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
240 g_static_mutex_lock(&alsa_mutex);
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
241
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
242 if (remove_prebuffer && prebuffer)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
243 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
244 prebuffer = FALSE;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
245 remove_prebuffer = FALSE;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
246 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
247 if (prebuffer)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
248 remove_prebuffer = TRUE;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
249
3149
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
250 ret = thread_buffer_size - get_thread_buffer_filled() - 1;
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
251
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
252 g_static_mutex_unlock(&alsa_mutex);
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
253
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
254 return ret;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
255 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
256
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
257 /* do pause operation */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
258 static void alsa_do_pause(gboolean p)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
259 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
260 if (paused == p)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
261 return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
262
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
263 if (alsa_pcm)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
264 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
265 if (alsa_can_pause)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
266 snd_pcm_pause(alsa_pcm, p);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
267 else if (p)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
268 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
269 snd_pcm_drop(alsa_pcm);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
270 snd_pcm_prepare(alsa_pcm);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
271 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
272 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
273 paused = p;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
274 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
275
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
276 void alsa_pause(short p)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
277 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
278 debug("alsa_pause");
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
279 pause_request = p;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
280 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
281
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
282 /* close PCM and release associated resources */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
283 static void alsa_close_pcm(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
284 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
285 if (alsa_pcm)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
286 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
287 int err;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
288 snd_pcm_drop(alsa_pcm);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
289 if ((err = snd_pcm_close(alsa_pcm)) < 0)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
290 g_warning("alsa_pcm_close() failed: %s",
1725
f9856ca98943 Pass literal values to snd_strerror(), as passing -err will cause an invalid dereference in any modern ALSA.
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
291 snd_strerror(err));
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
292 alsa_pcm = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
293 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
294 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
295
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
296 void alsa_close(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
297 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
298 if (!going)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
299 return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
300
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
301 debug("Closing device");
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
302
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
303 going = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
304
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
305 g_thread_join(audio_thread);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
306
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
307 alsa_cleanup_mixer();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
308
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
309 g_free(inputf);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
310 inputf = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
311 g_free(outputf);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
312 outputf = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
313
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
314 alsa_save_config();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
315
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
316 if (alsa_cfg.debug)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
317 snd_output_close(logs);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
318 debug("Device closed");
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
319 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
320
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
321 /* reopen ALSA PCM */
2228
0f2ac612f318 eliminate warning.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2063
diff changeset
322 #if 0
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
323 static gint alsa_reopen(struct snd_format *f)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
324 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
325 /* remember the current position */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
326 output_time_offset += (alsa_hw_written * 1000) / outputf->bps;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
327 alsa_hw_written = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
328
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
329 alsa_close_pcm();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
330
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
331 return alsa_setup(f);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
332 }
2228
0f2ac612f318 eliminate warning.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2063
diff changeset
333 #endif
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
334
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
335 /* do flush (drop) operation */
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
336 static void alsa_do_flush(gint time)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
337 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
338 if (alsa_pcm)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
339 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
340 snd_pcm_drop(alsa_pcm);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
341 snd_pcm_prepare(alsa_pcm);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
342 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
343 /* correct the offset */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
344 output_time_offset = time;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
345 alsa_total_written = (guint64) time * inputf->bps / 1000;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
346 rd_index = wr_index = alsa_hw_written = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
347 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
348
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
349 void alsa_flush(gint time)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
350 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
351 flush_request = time;
2457
bb55de702ffb alsa: Make spinlocks a bit less scary. Don't lock up in alsa_flush when output is closed.
Sascha Hlusiak <contact@saschahlusiak.de>
parents: 2450
diff changeset
352 while ((flush_request != -1) && (going))
1676
aee4ebea943a xmms_usleep() was removed, use g_usleep()
Matti Hamalainen <ccr@tnsp.org>
parents: 1479
diff changeset
353 g_usleep(10000);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
354 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
355
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
356 static void parse_mixer_name(gchar *str, gchar **name, gint *index)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
357 {
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
358 gchar *end;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
359
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
360 while (isspace(*str))
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
361 str++;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
362
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
363 if ((end = strchr(str, ',')) != NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
364 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
365 *name = g_strndup(str, end - str);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
366 end++;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
367 *index = atoi(end);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
368 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
369 else
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
370 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
371 *name = g_strdup(str);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
372 *index = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
373 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
374 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
375
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
376 gint alsa_get_mixer(snd_mixer_t **mixer, gint card)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
377 {
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
378 gchar *dev;
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
379 gint err;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
380
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
381 debug("alsa_get_mixer");
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
382
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
383 if ((err = snd_mixer_open(mixer, 0)) < 0)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
384 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
385 g_warning("alsa_get_mixer(): Failed to open empty mixer: %s",
1725
f9856ca98943 Pass literal values to snd_strerror(), as passing -err will cause an invalid dereference in any modern ALSA.
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
386 snd_strerror(err));
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
387 mixer = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
388 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
389 }
1479
7b3aa5513041 Port some changes over from XMMS that:
William Pitcock <nenolod@atheme-project.org>
parents: 1131
diff changeset
390
7b3aa5513041 Port some changes over from XMMS that:
William Pitcock <nenolod@atheme-project.org>
parents: 1131
diff changeset
391 dev = g_strdup_printf("hw:%i", card);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
392 if ((err = snd_mixer_attach(*mixer, dev)) < 0)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
393 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
394 g_warning("alsa_get_mixer(): Attaching to mixer %s failed: %s",
1725
f9856ca98943 Pass literal values to snd_strerror(), as passing -err will cause an invalid dereference in any modern ALSA.
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
395 dev, snd_strerror(err));
1479
7b3aa5513041 Port some changes over from XMMS that:
William Pitcock <nenolod@atheme-project.org>
parents: 1131
diff changeset
396 g_free(dev);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
397 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
398 }
1479
7b3aa5513041 Port some changes over from XMMS that:
William Pitcock <nenolod@atheme-project.org>
parents: 1131
diff changeset
399 g_free(dev);
7b3aa5513041 Port some changes over from XMMS that:
William Pitcock <nenolod@atheme-project.org>
parents: 1131
diff changeset
400
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
401 if ((err = snd_mixer_selem_register(*mixer, NULL, NULL)) < 0)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
402 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
403 g_warning("alsa_get_mixer(): Failed to register mixer: %s",
1725
f9856ca98943 Pass literal values to snd_strerror(), as passing -err will cause an invalid dereference in any modern ALSA.
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
404 snd_strerror(err));
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
405 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
406 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
407 if ((err = snd_mixer_load(*mixer)) < 0)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
408 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
409 g_warning("alsa_get_mixer(): Failed to load mixer: %s",
1725
f9856ca98943 Pass literal values to snd_strerror(), as passing -err will cause an invalid dereference in any modern ALSA.
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
410 snd_strerror(err));
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
411 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
412 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
413
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
414 return (*mixer != NULL);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
415 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
416
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
417
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
418 static snd_mixer_elem_t* alsa_get_mixer_elem(snd_mixer_t *mixer, gchar *name, gint index)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
419 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
420 snd_mixer_selem_id_t *selem_id;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
421 snd_mixer_elem_t* elem;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
422 snd_mixer_selem_id_alloca(&selem_id);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
423
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
424 if (index != -1)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
425 snd_mixer_selem_id_set_index(selem_id, index);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
426 if (name != NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
427 snd_mixer_selem_id_set_name(selem_id, name);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
428
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
429 elem = snd_mixer_find_selem(mixer, selem_id);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
430
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
431 return elem;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
432 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
433
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
434 static int alsa_setup_mixer(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
435 {
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
436 gchar *name;
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
437 glong a, b;
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
438 glong alsa_min_vol, alsa_max_vol;
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
439 gint err, index;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
440
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
441 debug("alsa_setup_mixer");
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
442
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
443 if ((err = alsa_get_mixer(&mixer, alsa_cfg.mixer_card)) < 0)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
444 return err;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
445
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
446 parse_mixer_name(alsa_cfg.mixer_device, &name, &index);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
447
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
448 pcm_element = alsa_get_mixer_elem(mixer, name, index);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
449
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
450 g_free(name);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
451
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
452 if (!pcm_element)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
453 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
454 g_warning("alsa_setup_mixer(): Failed to find mixer element: %s",
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
455 alsa_cfg.mixer_device);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
456 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
457 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
458
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
459 /*
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
460 * Work around a bug in alsa-lib up to 1.0.0rc2 where the
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
461 * new range don't take effect until the volume is changed.
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
462 * This hack should be removed once we depend on Alsa 1.0.0.
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
463 */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
464 snd_mixer_selem_get_playback_volume(pcm_element,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
465 SND_MIXER_SCHN_FRONT_LEFT, &a);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
466 snd_mixer_selem_get_playback_volume(pcm_element,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
467 SND_MIXER_SCHN_FRONT_RIGHT, &b);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
468
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
469 snd_mixer_selem_get_playback_volume_range(pcm_element,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
470 &alsa_min_vol, &alsa_max_vol);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
471 snd_mixer_selem_set_playback_volume_range(pcm_element, 0, 100);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
472
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
473 if (alsa_max_vol == 0)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
474 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
475 pcm_element = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
476 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
477 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
478
1728
63feceeb3799 Remove software volume control (it has been moved to the core as a pipeline flow element).
William Pitcock <nenolod@atheme.org>
parents: 1727
diff changeset
479 alsa_set_volume(a * 100 / alsa_max_vol, b * 100 / alsa_max_vol);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
480
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
481 debug("alsa_setup_mixer: end");
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
482
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
483 return 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
484 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
485
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
486 static void alsa_cleanup_mixer(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
487 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
488 pcm_element = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
489 if (mixer)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
490 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
491 snd_mixer_close(mixer);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
492 mixer = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
493 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
494 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
495
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
496 void alsa_get_volume(gint *l, gint *r)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
497 {
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
498 glong ll = *l, lr = *r;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
499
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
500 if (mixer_start)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
501 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
502 alsa_setup_mixer();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
503 mixer_start = FALSE;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
504 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
505
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
506 if (!pcm_element)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
507 return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
508
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
509 snd_mixer_handle_events(mixer);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
510
1728
63feceeb3799 Remove software volume control (it has been moved to the core as a pipeline flow element).
William Pitcock <nenolod@atheme.org>
parents: 1727
diff changeset
511 snd_mixer_selem_get_playback_volume(pcm_element,
63feceeb3799 Remove software volume control (it has been moved to the core as a pipeline flow element).
William Pitcock <nenolod@atheme.org>
parents: 1727
diff changeset
512 SND_MIXER_SCHN_FRONT_LEFT,
63feceeb3799 Remove software volume control (it has been moved to the core as a pipeline flow element).
William Pitcock <nenolod@atheme.org>
parents: 1727
diff changeset
513 &ll);
63feceeb3799 Remove software volume control (it has been moved to the core as a pipeline flow element).
William Pitcock <nenolod@atheme.org>
parents: 1727
diff changeset
514 snd_mixer_selem_get_playback_volume(pcm_element,
63feceeb3799 Remove software volume control (it has been moved to the core as a pipeline flow element).
William Pitcock <nenolod@atheme.org>
parents: 1727
diff changeset
515 SND_MIXER_SCHN_FRONT_RIGHT,
63feceeb3799 Remove software volume control (it has been moved to the core as a pipeline flow element).
William Pitcock <nenolod@atheme.org>
parents: 1727
diff changeset
516 &lr);
63feceeb3799 Remove software volume control (it has been moved to the core as a pipeline flow element).
William Pitcock <nenolod@atheme.org>
parents: 1727
diff changeset
517 *l = ll;
63feceeb3799 Remove software volume control (it has been moved to the core as a pipeline flow element).
William Pitcock <nenolod@atheme.org>
parents: 1727
diff changeset
518 *r = lr;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
519 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
520
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
521
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
522 void alsa_set_volume(gint l, gint r)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
523 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
524 if (!pcm_element)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
525 return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
526
555
279846578fdc [svn] If we are controlling a mono mixer component, ignore balance gracefully rather than muting the audio when the slider is moved to the left.
chainsaw
parents: 343
diff changeset
527 if (snd_mixer_selem_is_playback_mono(pcm_element))
279846578fdc [svn] If we are controlling a mono mixer component, ignore balance gracefully rather than muting the audio when the slider is moved to the left.
chainsaw
parents: 343
diff changeset
528 {
279846578fdc [svn] If we are controlling a mono mixer component, ignore balance gracefully rather than muting the audio when the slider is moved to the left.
chainsaw
parents: 343
diff changeset
529 if (l > r)
279846578fdc [svn] If we are controlling a mono mixer component, ignore balance gracefully rather than muting the audio when the slider is moved to the left.
chainsaw
parents: 343
diff changeset
530 snd_mixer_selem_set_playback_volume(pcm_element,
279846578fdc [svn] If we are controlling a mono mixer component, ignore balance gracefully rather than muting the audio when the slider is moved to the left.
chainsaw
parents: 343
diff changeset
531 SND_MIXER_SCHN_MONO, l);
279846578fdc [svn] If we are controlling a mono mixer component, ignore balance gracefully rather than muting the audio when the slider is moved to the left.
chainsaw
parents: 343
diff changeset
532 else
279846578fdc [svn] If we are controlling a mono mixer component, ignore balance gracefully rather than muting the audio when the slider is moved to the left.
chainsaw
parents: 343
diff changeset
533 snd_mixer_selem_set_playback_volume(pcm_element,
279846578fdc [svn] If we are controlling a mono mixer component, ignore balance gracefully rather than muting the audio when the slider is moved to the left.
chainsaw
parents: 343
diff changeset
534 SND_MIXER_SCHN_MONO, r);
279846578fdc [svn] If we are controlling a mono mixer component, ignore balance gracefully rather than muting the audio when the slider is moved to the left.
chainsaw
parents: 343
diff changeset
535 }
279846578fdc [svn] If we are controlling a mono mixer component, ignore balance gracefully rather than muting the audio when the slider is moved to the left.
chainsaw
parents: 343
diff changeset
536 else
279846578fdc [svn] If we are controlling a mono mixer component, ignore balance gracefully rather than muting the audio when the slider is moved to the left.
chainsaw
parents: 343
diff changeset
537 {
279846578fdc [svn] If we are controlling a mono mixer component, ignore balance gracefully rather than muting the audio when the slider is moved to the left.
chainsaw
parents: 343
diff changeset
538 snd_mixer_selem_set_playback_volume(pcm_element,
279846578fdc [svn] If we are controlling a mono mixer component, ignore balance gracefully rather than muting the audio when the slider is moved to the left.
chainsaw
parents: 343
diff changeset
539 SND_MIXER_SCHN_FRONT_LEFT, l);
279846578fdc [svn] If we are controlling a mono mixer component, ignore balance gracefully rather than muting the audio when the slider is moved to the left.
chainsaw
parents: 343
diff changeset
540 snd_mixer_selem_set_playback_volume(pcm_element,
279846578fdc [svn] If we are controlling a mono mixer component, ignore balance gracefully rather than muting the audio when the slider is moved to the left.
chainsaw
parents: 343
diff changeset
541 SND_MIXER_SCHN_FRONT_RIGHT, r);
279846578fdc [svn] If we are controlling a mono mixer component, ignore balance gracefully rather than muting the audio when the slider is moved to the left.
chainsaw
parents: 343
diff changeset
542 }
343
5d3f4b156197 [svn] - mute the soundcard if volume is 0.
nenolod
parents: 12
diff changeset
543
960
34325e9fcc60 [svn] - alsa: on volume changes, only use channel switches if the audio card supports separated ones
giacomo
parents: 888
diff changeset
544 if (snd_mixer_selem_has_playback_switch(pcm_element) && !snd_mixer_selem_has_playback_switch_joined(pcm_element))
343
5d3f4b156197 [svn] - mute the soundcard if volume is 0.
nenolod
parents: 12
diff changeset
545 {
5d3f4b156197 [svn] - mute the soundcard if volume is 0.
nenolod
parents: 12
diff changeset
546 snd_mixer_selem_set_playback_switch(pcm_element,
5d3f4b156197 [svn] - mute the soundcard if volume is 0.
nenolod
parents: 12
diff changeset
547 SND_MIXER_SCHN_FRONT_LEFT, l != 0);
5d3f4b156197 [svn] - mute the soundcard if volume is 0.
nenolod
parents: 12
diff changeset
548 snd_mixer_selem_set_playback_switch(pcm_element,
5d3f4b156197 [svn] - mute the soundcard if volume is 0.
nenolod
parents: 12
diff changeset
549 SND_MIXER_SCHN_FRONT_RIGHT, r != 0);
5d3f4b156197 [svn] - mute the soundcard if volume is 0.
nenolod
parents: 12
diff changeset
550 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
551 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
552
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
553
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
554 /*
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
555 * audio stuff
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
556 */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
557
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
558 /* return the size of audio data filled in the audio thread buffer */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
559 static int get_thread_buffer_filled(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
560 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
561 if (wr_index >= rd_index)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
562 return wr_index - rd_index;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
563 return thread_buffer_size - (rd_index - wr_index);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
564 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
565
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
566 gint alsa_get_output_time(void)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
567 {
3149
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
568 gint ret = 0;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
569 snd_pcm_sframes_t delay;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
570 guint64 bytes = alsa_hw_written;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
571
3149
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
572 g_static_mutex_lock(&alsa_mutex);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
573
3149
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
574 if (going && alsa_pcm != NULL)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
575 {
3149
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
576 if (!snd_pcm_delay(alsa_pcm, &delay))
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
577 {
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
578 unsigned int d = snd_pcm_frames_to_bytes(alsa_pcm, delay);
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
579 if (bytes < d)
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
580 bytes = 0;
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
581 else
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
582 bytes -= d;
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
583 }
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
584 ret = output_time_offset + (bytes * 1000) / outputf->bps;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
585 }
3149
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
586
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
587 g_static_mutex_unlock(&alsa_mutex);
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
588
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
589 return ret;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
590 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
591
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
592 gint alsa_get_written_time(void)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
593 {
3149
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
594 gint ret = 0;
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
595
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
596 g_static_mutex_lock(&alsa_mutex);
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
597
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
598 if (going)
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
599 ret = (alsa_total_written * 1000) / inputf->bps;
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
600
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
601 g_static_mutex_unlock(&alsa_mutex);
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
602
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
603 return ret;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
604 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
605
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
606 /* transfer data to audio h/w; length is given in bytes
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
607 *
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
608 * data can be modified via effect plugin, rate conversion or
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
609 * software volume before passed to audio h/w
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
610 */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
611 static void alsa_do_write(gpointer data, int length)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
612 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
613 if (paused)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
614 return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
615
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
616 alsa_write_audio(data, length);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
617 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
618
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
619 /* write callback */
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
620 void alsa_write(gpointer data, gint length)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
621 {
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
622 gint cnt;
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
623 gchar *src = (gchar *)data;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
624
3149
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
625 g_static_mutex_lock(&alsa_mutex);
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
626
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
627 remove_prebuffer = FALSE;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
628
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
629 alsa_total_written += length;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
630 while (length > 0)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
631 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
632 int wr;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
633 cnt = MIN(length, thread_buffer_size - wr_index);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
634 memcpy(thread_buffer + wr_index, src, cnt);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
635 wr = (wr_index + cnt) % thread_buffer_size;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
636 wr_index = wr;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
637 length -= cnt;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
638 src += cnt;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
639 }
3149
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
640 g_static_mutex_unlock(&alsa_mutex);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
641 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
642
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
643 /* transfer data to audio h/w via normal write */
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
644 static void alsa_write_audio(gchar *data, gint length)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
645 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
646 snd_pcm_sframes_t written_frames;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
647
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
648 while (length > 0)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
649 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
650 int frames = snd_pcm_bytes_to_frames(alsa_pcm, length);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
651 written_frames = snd_pcm_writei(alsa_pcm, data, frames);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
652
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
653 if (written_frames > 0)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
654 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
655 int written = snd_pcm_frames_to_bytes(alsa_pcm,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
656 written_frames);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
657 length -= written;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
658 data += written;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
659 alsa_hw_written += written;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
660 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
661 else
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
662 {
1727
9d6de95dd7ed Clean up and rework xrun/suspend handling, and add myself to Copyright holders.
William Pitcock <nenolod@atheme.org>
parents: 1725
diff changeset
663 int err = alsa_recovery((int)written_frames);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
664 if (err < 0)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
665 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
666 g_warning("alsa_write_audio(): write error: %s",
1725
f9856ca98943 Pass literal values to snd_strerror(), as passing -err will cause an invalid dereference in any modern ALSA.
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
667 snd_strerror(err));
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
668 break;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
669 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
670 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
671 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
672 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
673
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
674 /* transfer audio data from thread buffer to h/w */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
675 static void alsa_write_out_thread_data(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
676 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
677 gint length, cnt, avail;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
678
3149
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
679 length = MIN(hw_period_size_in, get_thread_buffer_filled());
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
680 avail = snd_pcm_frames_to_bytes(alsa_pcm, alsa_get_avail());
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
681 length = MIN(length, avail);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
682 while (length > 0)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
683 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
684 int rd;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
685 cnt = MIN(length, thread_buffer_size - rd_index);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
686 alsa_do_write(thread_buffer + rd_index, cnt);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
687 rd = (rd_index + cnt) % thread_buffer_size;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
688 rd_index = rd;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
689 length -= cnt;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
690 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
691 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
692
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
693 /* audio thread loop */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
694 /* FIXME: proper lock? */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
695 static void *alsa_loop(void *arg)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
696 {
3149
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
697 struct pollfd *pfd;
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
698 unsigned short *revents;
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
699 gint i, npfds, err, wr;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
700
1753
c730f0212456 Use a GStaticMutex instead of a GMutex to avoid crashing and resource conflicts.
William Pitcock <nenolod@atheme.org>
parents: 1728
diff changeset
701 g_static_mutex_lock(&alsa_mutex);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
702
3149
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
703 npfds = snd_pcm_poll_descriptors_count(alsa_pcm);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
704 if (npfds <= 0)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
705 goto _error;
879
c7daa70ffe7e [svn] alsa output plugin: use snd_pcm_wait in place of raw polls to handle device readyness; this allows to use alsa plugins such as jackplug; requires testing
giacomo
parents: 555
diff changeset
706
3149
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
707 pfd = alloca(sizeof(*pfd) * npfds);
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
708 revents = alloca(sizeof(*revents) * npfds);
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
709 err = snd_pcm_poll_descriptors(alsa_pcm, pfd, npfds);
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
710 if (err != npfds)
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
711 goto _error;
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
712
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
713 while (going && alsa_pcm)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
714 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
715 if (get_thread_buffer_filled() > prebuffer_size)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
716 prebuffer = FALSE;
3149
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
717 if (!paused && !prebuffer &&
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
718 get_thread_buffer_filled() > hw_period_size_in)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
719 {
3149
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
720 g_static_mutex_unlock(&alsa_mutex);
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
721 err = poll(pfd, npfds, 10);
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
722 g_static_mutex_lock(&alsa_mutex);
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
723
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
724 if (err == 0)
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
725 continue;
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
726
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
727 if (err < 0) {
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
728 if (errno == EINTR)
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
729 continue;
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
730 goto _error;
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
731 }
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
732
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
733 err = snd_pcm_poll_descriptors_revents(alsa_pcm, pfd, npfds, revents);
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
734 if (err < 0)
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
735 goto _error;
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
736
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
737 wr = 0;
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
738 for (i = 0; i < npfds; i++) {
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
739 if (revents[i] & (POLLERR | POLLNVAL)) {
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
740 wr = -1;
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
741 break;
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
742 }
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
743 if (revents[i] & POLLOUT)
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
744 wr = 1;
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
745 }
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
746
885
1d8d643134db [svn] - alsa: handle errors on snd_pcm_wait (xrun, supend)
giacomo
parents: 879
diff changeset
747 if (wr > 0)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
748 {
879
c7daa70ffe7e [svn] alsa output plugin: use snd_pcm_wait in place of raw polls to handle device readyness; this allows to use alsa plugins such as jackplug; requires testing
giacomo
parents: 555
diff changeset
749 alsa_write_out_thread_data();
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
750 }
885
1d8d643134db [svn] - alsa: handle errors on snd_pcm_wait (xrun, supend)
giacomo
parents: 879
diff changeset
751 else if (wr < 0)
1d8d643134db [svn] - alsa: handle errors on snd_pcm_wait (xrun, supend)
giacomo
parents: 879
diff changeset
752 {
1727
9d6de95dd7ed Clean up and rework xrun/suspend handling, and add myself to Copyright holders.
William Pitcock <nenolod@atheme.org>
parents: 1725
diff changeset
753 alsa_recovery(wr);
885
1d8d643134db [svn] - alsa: handle errors on snd_pcm_wait (xrun, supend)
giacomo
parents: 879
diff changeset
754 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
755 }
1934
c62011e48c61 alsa_recovery(): some bugfixes.
William Pitcock <nenolod@atheme.org>
parents: 1753
diff changeset
756 else /* XXX: why is this here? --nenolod */
3149
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
757 {
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
758 g_static_mutex_unlock(&alsa_mutex);
1676
aee4ebea943a xmms_usleep() was removed, use g_usleep()
Matti Hamalainen <ccr@tnsp.org>
parents: 1479
diff changeset
759 g_usleep(10000);
3149
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
760 g_static_mutex_lock(&alsa_mutex);
4b50e2a0ae1f Branch merge.
William Pitcock <nenolod@atheme.org>
parents: 3147
diff changeset
761 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
762
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
763 if (pause_request != paused)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
764 alsa_do_pause(pause_request);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
765
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
766 if (flush_request != -1)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
767 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
768 alsa_do_flush(flush_request);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
769 flush_request = -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
770 prebuffer = TRUE;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
771 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
772 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
773
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
774 _error:
1753
c730f0212456 Use a GStaticMutex instead of a GMutex to avoid crashing and resource conflicts.
William Pitcock <nenolod@atheme.org>
parents: 1728
diff changeset
775 g_static_mutex_unlock(&alsa_mutex);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
776 alsa_close_pcm();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
777 g_free(thread_buffer);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
778 thread_buffer = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
779 g_thread_exit(NULL);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
780 return(NULL);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
781 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
782
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
783 /* open callback */
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
784 gint alsa_open(AFormat fmt, gint rate, gint nch)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
785 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
786 debug("Opening device");
2398
684a26ccca54 check input fmt thoughtfully
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2387
diff changeset
787 if((inputf = snd_format_from_xmms(fmt, rate, nch)) == NULL) return 0;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
788
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
789 if (alsa_cfg.debug)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
790 snd_output_stdio_attach(&logs, stdout, 0);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
791
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
792 if (alsa_setup(inputf) < 0)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
793 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
794 alsa_close();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
795 return 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
796 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
797
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
798 if (!mixer)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
799 alsa_setup_mixer();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
800
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
801 output_time_offset = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
802 alsa_total_written = alsa_hw_written = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
803 going = TRUE;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
804 paused = FALSE;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
805 prebuffer = TRUE;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
806 remove_prebuffer = FALSE;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
807
2059
70b1f1fc4804 use aud_cfg in some places
William Pitcock <nenolod@atheme.org>
parents: 2022
diff changeset
808 thread_buffer_size = (guint64)aud_cfg->output_buffer_size * inputf->bps / 1000;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
809 if (thread_buffer_size < hw_buffer_size)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
810 thread_buffer_size = hw_buffer_size * 2;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
811 if (thread_buffer_size < 8192)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
812 thread_buffer_size = 8192;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
813 prebuffer_size = thread_buffer_size / 2;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
814 if (prebuffer_size < 8192)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
815 prebuffer_size = 8192;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
816 thread_buffer_size += hw_buffer_size;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
817 thread_buffer_size -= thread_buffer_size % hw_period_size;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
818 thread_buffer = g_malloc0(thread_buffer_size);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
819 wr_index = rd_index = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
820 pause_request = FALSE;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
821 flush_request = -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
822
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
823 audio_thread = g_thread_create((GThreadFunc)alsa_loop, NULL, TRUE, NULL);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
824 return 1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
825 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
826
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
827 static struct snd_format * snd_format_from_xmms(AFormat fmt, gint rate, gint channels)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
828 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
829 struct snd_format *f = g_malloc(sizeof(struct snd_format));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
830 size_t i;
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
831 gint found = 0;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
832
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
833 f->xmms_format = fmt;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
834 f->format = SND_PCM_FORMAT_UNKNOWN;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
835
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
836 for (i = 0; i < sizeof(format_table) / sizeof(format_table[0]); i++)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
837 if (format_table[i].xmms == fmt)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
838 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
839 f->format = format_table[i].alsa;
2398
684a26ccca54 check input fmt thoughtfully
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2387
diff changeset
840 found = 1;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
841 break;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
842 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
843
2398
684a26ccca54 check input fmt thoughtfully
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2387
diff changeset
844 if(!found) {
684a26ccca54 check input fmt thoughtfully
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2387
diff changeset
845 g_free(f);
684a26ccca54 check input fmt thoughtfully
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2387
diff changeset
846 return NULL;
684a26ccca54 check input fmt thoughtfully
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2387
diff changeset
847 }
684a26ccca54 check input fmt thoughtfully
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2387
diff changeset
848
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
849 /* Get rid of _NE */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
850 for (i = 0; i < sizeof(format_table) / sizeof(format_table[0]); i++)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
851 if (format_table[i].alsa == f->format)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
852 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
853 f->xmms_format = format_table[i].xmms;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
854 break;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
855 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
856
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
857
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
858 f->rate = rate;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
859 f->channels = channels;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
860 f->sample_bits = snd_pcm_format_physical_width(f->format);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
861 f->bps = (rate * f->sample_bits * channels) >> 3;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
862
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
863 return f;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
864 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
865
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
866 static gint alsa_setup(struct snd_format *f)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
867 {
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
868 gint err;
2022
c6023e5efd06 warning fixes
William Pitcock <nenolod@atheme.org>
parents: 1934
diff changeset
869 snd_pcm_hw_params_t *hwparams = NULL;
c6023e5efd06 warning fixes
William Pitcock <nenolod@atheme.org>
parents: 1934
diff changeset
870 snd_pcm_sw_params_t *swparams = NULL;
2760
35ac6cb80680 Use glib types.
Matti Hamalainen <ccr@tnsp.org>
parents: 2611
diff changeset
871 guint alsa_buffer_time, alsa_period_time;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
872 snd_pcm_uframes_t alsa_buffer_size, alsa_period_size;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
873
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
874 debug("alsa_setup");
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
875
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
876 g_free(outputf);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
877 outputf = snd_format_from_xmms(f->xmms_format, f->rate, f->channels);
2398
684a26ccca54 check input fmt thoughtfully
Eugene Zagidullin <e.asphyx@gmail.com>
parents: 2387
diff changeset
878 if(outputf == NULL) return -1;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
879
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
880 debug("Opening device: %s", alsa_cfg.pcm_device);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
881 /* FIXME: Can snd_pcm_open() return EAGAIN? */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
882 if ((err = snd_pcm_open(&alsa_pcm, alsa_cfg.pcm_device,
2987
58c63fbbd3ce Do not use non-blocking playback, it is entirely unnecessary and is the source of many problems we have with ALSA on weird cards.
William Pitcock <nenolod@atheme.org>
parents: 2760
diff changeset
883 SND_PCM_STREAM_PLAYBACK, 0)) < 0)
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
884 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
885 g_warning("alsa_setup(): Failed to open pcm device (%s): %s",
1725
f9856ca98943 Pass literal values to snd_strerror(), as passing -err will cause an invalid dereference in any modern ALSA.
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
886 alsa_cfg.pcm_device, snd_strerror(err));
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
887 alsa_pcm = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
888 g_free(outputf);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
889 outputf = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
890 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
891 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
892
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
893 /* doesn't care about non-blocking */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
894 /* snd_pcm_nonblock(alsa_pcm, 0); */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
895
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
896 if (alsa_cfg.debug)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
897 {
2022
c6023e5efd06 warning fixes
William Pitcock <nenolod@atheme.org>
parents: 1934
diff changeset
898 snd_pcm_info_t *info = NULL;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
899 int alsa_card, alsa_device, alsa_subdevice;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
900
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
901 snd_pcm_info_alloca(&info);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
902 snd_pcm_info(alsa_pcm, info);
2022
c6023e5efd06 warning fixes
William Pitcock <nenolod@atheme.org>
parents: 1934
diff changeset
903 alsa_card = snd_pcm_info_get_card(info);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
904 alsa_device = snd_pcm_info_get_device(info);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
905 alsa_subdevice = snd_pcm_info_get_subdevice(info);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
906 printf("Card %i, Device %i, Subdevice %i\n",
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
907 alsa_card, alsa_device, alsa_subdevice);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
908 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
909
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
910 snd_pcm_hw_params_alloca(&hwparams);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
911
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
912 if ((err = snd_pcm_hw_params_any(alsa_pcm, hwparams)) < 0)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
913 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
914 g_warning("alsa_setup(): No configuration available for "
1725
f9856ca98943 Pass literal values to snd_strerror(), as passing -err will cause an invalid dereference in any modern ALSA.
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
915 "playback: %s", snd_strerror(err));
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
916 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
917 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
918
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
919 if ((err = snd_pcm_hw_params_set_access(alsa_pcm, hwparams,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
920 SND_PCM_ACCESS_RW_INTERLEAVED)) < 0)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
921 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
922 g_warning("alsa_setup(): Cannot set direct write mode: %s",
1725
f9856ca98943 Pass literal values to snd_strerror(), as passing -err will cause an invalid dereference in any modern ALSA.
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
923 snd_strerror(err));
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
924 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
925 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
926
2353
415e67d313ad Experimental 24-bit support. Can someone test this? It doesn't work for me.
William Pitcock <nenolod@atheme.org>
parents: 2228
diff changeset
927 /* XXX: there is no down-dithering for 24bit yet --nenolod */
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
928 if ((err = snd_pcm_hw_params_set_format(alsa_pcm, hwparams, outputf->format)) < 0)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
929 {
2353
415e67d313ad Experimental 24-bit support. Can someone test this? It doesn't work for me.
William Pitcock <nenolod@atheme.org>
parents: 2228
diff changeset
930 g_warning("alsa_setup(): Sample format not "
415e67d313ad Experimental 24-bit support. Can someone test this? It doesn't work for me.
William Pitcock <nenolod@atheme.org>
parents: 2228
diff changeset
931 "available for playback: %s",
415e67d313ad Experimental 24-bit support. Can someone test this? It doesn't work for me.
William Pitcock <nenolod@atheme.org>
parents: 2228
diff changeset
932 snd_strerror(err));
415e67d313ad Experimental 24-bit support. Can someone test this? It doesn't work for me.
William Pitcock <nenolod@atheme.org>
parents: 2228
diff changeset
933 return -1;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
934 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
935
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
936 snd_pcm_hw_params_set_channels_near(alsa_pcm, hwparams, &outputf->channels);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
937 if (outputf->channels != f->channels)
2382
9f1dc50ed75d Remove calls into xconvert PAPI.
William Pitcock <nenolod@atheme.org>
parents: 2377
diff changeset
938 return -1;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
939
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
940 snd_pcm_hw_params_set_rate_near(alsa_pcm, hwparams, &outputf->rate, 0);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
941 if (outputf->rate == 0)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
942 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
943 g_warning("alsa_setup(): No usable samplerate available.");
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
944 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
945 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
946 if (outputf->rate != f->rate)
2382
9f1dc50ed75d Remove calls into xconvert PAPI.
William Pitcock <nenolod@atheme.org>
parents: 2377
diff changeset
947 return -1;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
948
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
949 outputf->sample_bits = snd_pcm_format_physical_width(outputf->format);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
950 outputf->bps = (outputf->rate * outputf->sample_bits * outputf->channels) >> 3;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
951
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
952 alsa_buffer_time = alsa_cfg.buffer_time * 1000;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
953 if ((err = snd_pcm_hw_params_set_buffer_time_near(alsa_pcm, hwparams,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
954 &alsa_buffer_time, 0)) < 0)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
955 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
956 g_warning("alsa_setup(): Set buffer time failed: %s.",
1725
f9856ca98943 Pass literal values to snd_strerror(), as passing -err will cause an invalid dereference in any modern ALSA.
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
957 snd_strerror(err));
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
958 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
959 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
960
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
961 alsa_period_time = alsa_cfg.period_time * 1000;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
962 if ((err = snd_pcm_hw_params_set_period_time_near(alsa_pcm, hwparams,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
963 &alsa_period_time, 0)) < 0)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
964 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
965 g_warning("alsa_setup(): Set period time failed: %s.",
1725
f9856ca98943 Pass literal values to snd_strerror(), as passing -err will cause an invalid dereference in any modern ALSA.
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
966 snd_strerror(err));
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
967 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
968 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
969
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
970 if (snd_pcm_hw_params(alsa_pcm, hwparams) < 0)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
971 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
972 if (alsa_cfg.debug)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
973 snd_pcm_hw_params_dump(hwparams, logs);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
974 g_warning("alsa_setup(): Unable to install hw params");
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
975 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
976 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
977
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
978 if ((err = snd_pcm_hw_params_get_buffer_size(hwparams, &alsa_buffer_size)) < 0)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
979 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
980 g_warning("alsa_setup(): snd_pcm_hw_params_get_buffer_size() "
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
981 "failed: %s",
1725
f9856ca98943 Pass literal values to snd_strerror(), as passing -err will cause an invalid dereference in any modern ALSA.
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
982 snd_strerror(err));
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
983 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
984 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
985
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
986 if ((err = snd_pcm_hw_params_get_period_size(hwparams, &alsa_period_size, 0)) < 0)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
987 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
988 g_warning("alsa_setup(): snd_pcm_hw_params_get_period_size() "
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
989 "failed: %s",
1725
f9856ca98943 Pass literal values to snd_strerror(), as passing -err will cause an invalid dereference in any modern ALSA.
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
990 snd_strerror(err));
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
991 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
992 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
993
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
994 alsa_can_pause = snd_pcm_hw_params_can_pause(hwparams);
1479
7b3aa5513041 Port some changes over from XMMS that:
William Pitcock <nenolod@atheme-project.org>
parents: 1131
diff changeset
995 debug("can pause: %d", alsa_can_pause);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
996
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
997 snd_pcm_sw_params_alloca(&swparams);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
998 snd_pcm_sw_params_current(alsa_pcm, swparams);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
999
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1000 if ((err = snd_pcm_sw_params_set_start_threshold(alsa_pcm,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1001 swparams, alsa_buffer_size - alsa_period_size) < 0))
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1002 g_warning("alsa_setup(): setting start "
1725
f9856ca98943 Pass literal values to snd_strerror(), as passing -err will cause an invalid dereference in any modern ALSA.
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
1003 "threshold failed: %s", snd_strerror(err));
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1004 if (snd_pcm_sw_params(alsa_pcm, swparams) < 0)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1005 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1006 g_warning("alsa_setup(): Unable to install sw params");
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1007 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1008 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1009
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1010 if (alsa_cfg.debug)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1011 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1012 snd_pcm_sw_params_dump(swparams, logs);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1013 snd_pcm_dump(alsa_pcm, logs);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1014 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1015
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1016 hw_buffer_size = snd_pcm_frames_to_bytes(alsa_pcm, alsa_buffer_size);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1017 hw_period_size = snd_pcm_frames_to_bytes(alsa_pcm, alsa_period_size);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1018 if (inputf->bps != outputf->bps)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1019 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1020 int align = (inputf->sample_bits * inputf->channels) / 8;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1021 hw_buffer_size_in = ((guint64)hw_buffer_size * inputf->bps +
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1022 outputf->bps/2) / outputf->bps;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1023 hw_period_size_in = ((guint64)hw_period_size * inputf->bps +
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1024 outputf->bps/2) / outputf->bps;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1025 hw_buffer_size_in -= hw_buffer_size_in % align;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1026 hw_period_size_in -= hw_period_size_in % align;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1027 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1028 else
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1029 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1030 hw_buffer_size_in = hw_buffer_size;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1031 hw_period_size_in = hw_period_size;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1032 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1033
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1034 debug("Device setup: buffer time: %i, size: %i.", alsa_buffer_time,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1035 hw_buffer_size);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1036 debug("Device setup: period time: %i, size: %i.", alsa_period_time,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1037 hw_period_size);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1038 debug("bits per sample: %i; frame size: %i; Bps: %i",
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1039 snd_pcm_format_physical_width(outputf->format),
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1040 (int)snd_pcm_frames_to_bytes(alsa_pcm, 1), outputf->bps);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1041
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1042 return 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1043 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1044
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1045 void alsa_tell(AFormat * fmt, gint * rate, gint * nch)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1046 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1047 (*fmt) = inputf->xmms_format;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1048 (*rate) = inputf->rate;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1049 (*nch) = inputf->channels;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1050 }