annotate Plugins/Output/alsa/audio.c @ 749:3787176f9875 trunk

[svn] more fixing
author nenolod
date Mon, 27 Feb 2006 20:32:58 -0800
parents d539e5c5f730
children 6bafb1360398
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1 /* XMMS - ALSA output plugin
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
2 * Copyright (C) 2001-2003 Matthieu Sozeau <mattam@altern.org>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
3 * Copyright (C) 1998-2003 Peter Alm, Mikael Alm, Olle Hallnas,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
4 * Thomas Nilsson and 4Front Technologies
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
5 * Copyright (C) 1999-2005 Haavard Kvaalen
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
6 * Copyright (C) 2005 Takashi Iwai
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
7 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
11 * (at your option) any later version.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
12 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
16 * GNU General Public License for more details.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
17 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
21 */
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
22
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
23 /*
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
24 * CHANGES
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
25 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
26 * 2005.01.05 Takashi Iwai <tiwai@suse.de>
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
27 * Impelemented the multi-threaded mode with an audio-thread.
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
28 * Many fixes and cleanups.
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
29 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
30
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
31
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
32 #include "alsa.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
33 #include <ctype.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
34 #include <libaudacious/xconvert.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
35
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
36 static snd_pcm_t *alsa_pcm;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
37 static snd_output_t *logs;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
38
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
39
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
40 /* Number of bytes that we have received from the input plugin */
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
41 static guint64 alsa_total_written;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
42 /* Number of bytes that we have sent to the sound card */
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
43 static guint64 alsa_hw_written;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
44 static guint64 output_time_offset;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
45
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
46 /* device buffer/period sizes in bytes */
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
47 static int hw_buffer_size, hw_period_size; /* in output bytes */
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
48 static int hw_buffer_size_in, hw_period_size_in; /* in input bytes */
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
49
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
50 /* Set/Get volume */
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
51 static snd_mixer_elem_t *pcm_element;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
52 static snd_mixer_t *mixer;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
53
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
54 static gboolean going, paused, mixer_start = TRUE;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
55 static gboolean prebuffer, remove_prebuffer;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
56
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
57 static gboolean alsa_can_pause;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
58
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
59 /* for audio thread */
215
84162f8f2164 [svn] GThreadify output plugin.
chainsaw
parents: 211
diff changeset
60 static GThread *audio_thread; /* audio loop thread */
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
61 static int thread_buffer_size; /* size of intermediate buffer in bytes */
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
62 static char *thread_buffer; /* audio intermediate buffer */
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
63 static int rd_index, wr_index; /* current read/write position in int-buffer */
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
64 static gboolean pause_request; /* pause status currently requested */
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
65 static int flush_request; /* flush status (time) currently requested */
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
66 static int prebuffer_size;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
67
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
68 static guint mixer_timeout;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
69
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
70 struct snd_format {
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
71 unsigned int rate;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
72 unsigned int channels;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
73 snd_pcm_format_t format;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
74 AFormat xmms_format;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
75 int sample_bits;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
76 int bps;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
77 };
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
78
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
79 static struct snd_format *inputf = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
80 static struct snd_format *effectf = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
81 static struct snd_format *outputf = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
82
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
83 static int alsa_setup(struct snd_format *f);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
84 static void alsa_write_audio(char *data, int length);
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
85 static void alsa_cleanup_mixer(void);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
86 static int get_thread_buffer_filled(void);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
87
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
88 static struct snd_format * snd_format_from_xmms(AFormat fmt, int rate, int channels);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
89
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
90 static struct xmms_convert_buffers *convertb;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
91
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
92 static convert_func_t alsa_convert_func;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
93 static convert_channel_func_t alsa_stereo_convert_func;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
94 static convert_freq_func_t alsa_frequency_convert_func;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
95
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
96 static const struct {
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
97 AFormat xmms;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
98 snd_pcm_format_t alsa;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
99 } format_table[] =
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
100 {{FMT_S16_LE, SND_PCM_FORMAT_S16_LE},
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
101 {FMT_S16_BE, SND_PCM_FORMAT_S16_BE},
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
102 {FMT_S16_NE, SND_PCM_FORMAT_S16},
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
103 {FMT_U16_LE, SND_PCM_FORMAT_U16_LE},
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
104 {FMT_U16_BE, SND_PCM_FORMAT_U16_BE},
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
105 {FMT_U16_NE, SND_PCM_FORMAT_U16},
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
106 {FMT_U8, SND_PCM_FORMAT_U8},
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
107 {FMT_S8, SND_PCM_FORMAT_S8},
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
108 };
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
109
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
110
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
111 static void debug(char *str, ...) G_GNUC_PRINTF(1, 2);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
112
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
113 static void debug(char *str, ...)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
114 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
115 va_list args;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
116
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
117 if (alsa_cfg.debug)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
118 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
119 va_start(args, str);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
120 g_logv(NULL, G_LOG_LEVEL_MESSAGE, str, args);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
121 va_end(args);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
122 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
123 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
124
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
125 int alsa_playing(void)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
126 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
127 if (!going || paused || alsa_pcm == NULL)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
128 return FALSE;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
129
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
130 return snd_pcm_state(alsa_pcm) == SND_PCM_STATE_RUNNING;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
131 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
132
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
133 static int xrun_recover(void)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
134 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
135 if (alsa_cfg.debug)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
136 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
137 snd_pcm_status_t *alsa_status;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
138 snd_pcm_status_alloca(&alsa_status);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
139 if (snd_pcm_status(alsa_pcm, alsa_status) < 0)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
140 g_warning("xrun_recover(): snd_pcm_status() failed");
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
141 else
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
142 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
143 printf("Status:\n");
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
144 snd_pcm_status_dump(alsa_status, logs);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
145 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
146 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
147 return snd_pcm_prepare(alsa_pcm);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
148 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
149
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
150 static int suspend_recover(void)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
151 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
152 int err;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
153
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
154 while ((err = snd_pcm_resume(alsa_pcm)) == -EAGAIN)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
155 /* wait until suspend flag is released */
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
156 sleep(1);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
157 if (err < 0)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
158 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
159 g_warning("alsa_handle_error(): "
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
160 "snd_pcm_resume() failed.");
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
161 return snd_pcm_prepare(alsa_pcm);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
162 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
163 return err;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
164 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
165
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
166 /* handle generic errors */
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
167 static int alsa_handle_error(int err)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
168 {
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
169 switch (err)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
170 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
171 case -EPIPE:
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
172 return xrun_recover();
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
173 case -ESTRPIPE:
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
174 return suspend_recover();
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
175 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
176
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
177 return err;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
178 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
179
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
180 /* update and get the available space on h/w buffer (in frames) */
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
181 static snd_pcm_sframes_t alsa_get_avail(void)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
182 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
183 snd_pcm_sframes_t ret;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
184
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
185 if (alsa_pcm == NULL)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
186 return 0;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
187
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
188 while ((ret = snd_pcm_avail_update(alsa_pcm)) < 0)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
189 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
190 ret = alsa_handle_error(ret);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
191 if (ret < 0)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
192 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
193 g_warning("alsa_get_avail(): snd_pcm_avail_update() failed: %s",
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
194 snd_strerror(-ret));
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
195 return 0;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
196 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
197 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
198 return ret;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
199 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
200
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
201 /* get the free space on buffer */
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
202 int alsa_free(void)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
203 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
204 if (remove_prebuffer && prebuffer)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
205 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
206 prebuffer = FALSE;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
207 remove_prebuffer = FALSE;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
208 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
209 if (prebuffer)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
210 remove_prebuffer = TRUE;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
212 return thread_buffer_size - get_thread_buffer_filled() - 1;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
213 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
214
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
215 /* do pause operation */
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
216 static void alsa_do_pause(gboolean p)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
217 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
218 if (paused == p)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
219 return;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
220
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
221 if (alsa_pcm)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
222 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
223 if (alsa_can_pause)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
224 snd_pcm_pause(alsa_pcm, p);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
225 else if (p)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
226 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
227 snd_pcm_drop(alsa_pcm);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
228 snd_pcm_prepare(alsa_pcm);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
229 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
230 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
231 paused = p;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
232 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
233
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
234 void alsa_pause(short p)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
235 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
236 debug("alsa_pause");
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
237 pause_request = p;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
238 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
239
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
240 /* close PCM and release associated resources */
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
241 static void alsa_close_pcm(void)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
242 {
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
243 if (alsa_pcm)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
244 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
245 int err;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
246 snd_pcm_drop(alsa_pcm);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
247 if ((err = snd_pcm_close(alsa_pcm)) < 0)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
248 g_warning("alsa_pcm_close() failed: %s",
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
249 snd_strerror(-err));
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
250 alsa_pcm = NULL;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
251 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
252 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
253
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
254 void alsa_close(void)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
255 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
256 if (!going)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
257 return;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
258
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
259 debug("Closing device");
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
260
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
261 going = 0;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
262
215
84162f8f2164 [svn] GThreadify output plugin.
chainsaw
parents: 211
diff changeset
263 g_thread_join(audio_thread);
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
264
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
265 alsa_cleanup_mixer();
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
266
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
267 xmms_convert_buffers_destroy(convertb);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
268 convertb = NULL;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
269 g_free(inputf);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
270 inputf = NULL;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
271 g_free(effectf);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
272 effectf = NULL;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
273 g_free(outputf);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
274 outputf = NULL;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
275
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
276 alsa_save_config();
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
277
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
278 if (alsa_cfg.debug)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
279 snd_output_close(logs);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
280 debug("Device closed");
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
281 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
282
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
283 /* reopen ALSA PCM */
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
284 static int alsa_reopen(struct snd_format *f)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
285 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
286 /* remember the current position */
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
287 output_time_offset += (alsa_hw_written * 1000) / outputf->bps;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
288 alsa_hw_written = 0;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
289
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
290 alsa_close_pcm();
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
291
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
292 return alsa_setup(f);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
293 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
294
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
295 /* do flush (drop) operation */
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
296 static void alsa_do_flush(int time)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
297 {
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
298 if (alsa_pcm)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
299 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
300 snd_pcm_drop(alsa_pcm);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
301 snd_pcm_prepare(alsa_pcm);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
302 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
303 /* correct the offset */
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
304 output_time_offset = time;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
305 alsa_total_written = (guint64) time * inputf->bps / 1000;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
306 rd_index = wr_index = alsa_hw_written = 0;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
307 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
308
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
309 void alsa_flush(int time)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
310 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
311 flush_request = time;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
312 while (flush_request != -1)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
313 xmms_usleep(10000);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
314 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
315
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
316 static void parse_mixer_name(char *str, char **name, int *index)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
317 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
318 char *end;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
319
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
320 while (isspace(*str))
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
321 str++;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
322
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
323 if ((end = strchr(str, ',')) != NULL)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
324 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
325 *name = g_strndup(str, end - str);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
326 end++;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
327 *index = atoi(end);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
328 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
329 else
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
330 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
331 *name = g_strdup(str);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
332 *index = 0;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
333 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
334 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
335
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
336 int alsa_get_mixer(snd_mixer_t **mixer, int card)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
337 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
338 char *dev;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
339 int err;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
340
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
341 debug("alsa_get_mixer");
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
342
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
343 dev = g_strdup_printf("hw:%i", card);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
344
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
345 if ((err = snd_mixer_open(mixer, 0)) < 0)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
346 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
347 g_warning("alsa_get_mixer(): Failed to open empty mixer: %s",
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
348 snd_strerror(-err));
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
349 mixer = NULL;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
350 return -1;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
351 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
352 if ((err = snd_mixer_attach(*mixer, dev)) < 0)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
353 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
354 g_warning("alsa_get_mixer(): Attaching to mixer %s failed: %s",
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
355 dev, snd_strerror(-err));
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
356 return -1;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
357 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
358 if ((err = snd_mixer_selem_register(*mixer, NULL, NULL)) < 0)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
359 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
360 g_warning("alsa_get_mixer(): Failed to register mixer: %s",
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
361 snd_strerror(-err));
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
362 return -1;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
363 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
364 if ((err = snd_mixer_load(*mixer)) < 0)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
365 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
366 g_warning("alsa_get_mixer(): Failed to load mixer: %s",
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
367 snd_strerror(-err));
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
368 return -1;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
369 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
370
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
371 g_free(dev);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
372
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
373 return (*mixer != NULL);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
374 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
375
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
376
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
377 static snd_mixer_elem_t* alsa_get_mixer_elem(snd_mixer_t *mixer, char *name, int index)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
378 {
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
379 snd_mixer_selem_id_t *selem_id;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
380 snd_mixer_elem_t* elem;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
381 snd_mixer_selem_id_alloca(&selem_id);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
382
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
383 if (index != -1)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
384 snd_mixer_selem_id_set_index(selem_id, index);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
385 if (name != NULL)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
386 snd_mixer_selem_id_set_name(selem_id, name);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
387
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
388 elem = snd_mixer_find_selem(mixer, selem_id);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
389
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
390 return elem;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
391 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
392
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
393 static int alsa_setup_mixer(void)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
394 {
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
395 char *name;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
396 long int a, b;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
397 long alsa_min_vol, alsa_max_vol;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
398 int err, index;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
399
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
400 debug("alsa_setup_mixer");
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
401
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
402 if ((err = alsa_get_mixer(&mixer, alsa_cfg.mixer_card)) < 0)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
403 return err;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
404
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
405 parse_mixer_name(alsa_cfg.mixer_device, &name, &index);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
406
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
407 pcm_element = alsa_get_mixer_elem(mixer, name, index);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
408
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
409 g_free(name);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
410
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
411 if (!pcm_element)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
412 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
413 g_warning("alsa_setup_mixer(): Failed to find mixer element: %s",
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
414 alsa_cfg.mixer_device);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
415 return -1;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
416 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
417
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
418 /*
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
419 * Work around a bug in alsa-lib up to 1.0.0rc2 where the
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
420 * new range don't take effect until the volume is changed.
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
421 * This hack should be removed once we depend on Alsa 1.0.0.
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
422 */
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
423 snd_mixer_selem_get_playback_volume(pcm_element,
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
424 SND_MIXER_SCHN_FRONT_LEFT, &a);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
425 snd_mixer_selem_get_playback_volume(pcm_element,
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
426 SND_MIXER_SCHN_FRONT_RIGHT, &b);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
427
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
428 snd_mixer_selem_get_playback_volume_range(pcm_element,
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
429 &alsa_min_vol, &alsa_max_vol);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
430 snd_mixer_selem_set_playback_volume_range(pcm_element, 0, 100);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
431
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
432 if (alsa_max_vol == 0)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
433 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
434 pcm_element = NULL;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
435 return -1;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
436 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
437
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
438 if (!alsa_cfg.soft_volume)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
439 alsa_set_volume(a * 100 / alsa_max_vol, b * 100 / alsa_max_vol);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
440
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
441 debug("alsa_setup_mixer: end");
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
442
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
443 return 0;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
444 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
445
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
446 static int alsa_mixer_timeout(void *data)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
447 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
448 if (mixer)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
449 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
450 snd_mixer_close(mixer);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
451 mixer = NULL;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
452 pcm_element = NULL;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
453 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
454 mixer_timeout = 0;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
455 mixer_start = TRUE;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
456
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
457 g_message("alsa mixer timed out");
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
458 return FALSE;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
459 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
460
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
461 static void alsa_cleanup_mixer(void)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
462 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
463 pcm_element = NULL;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
464 if (mixer)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
465 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
466 snd_mixer_close(mixer);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
467 mixer = NULL;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
468 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
469 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
470
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
471 void alsa_get_volume(int *l, int *r)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
472 {
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
473 long ll = *l, lr = *r;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
474
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
475 if (mixer_start)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
476 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
477 alsa_setup_mixer();
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
478 mixer_start = FALSE;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
479 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
480
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
481 if (alsa_cfg.soft_volume)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
482 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
483 *l = alsa_cfg.vol.left;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
484 *r = alsa_cfg.vol.right;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
485 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
486
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
487 if (!pcm_element)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
488 return;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
489
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
490 snd_mixer_handle_events(mixer);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
491
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
492 if (!alsa_cfg.soft_volume)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
493 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
494 snd_mixer_selem_get_playback_volume(pcm_element,
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
495 SND_MIXER_SCHN_FRONT_LEFT,
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
496 &ll);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
497 snd_mixer_selem_get_playback_volume(pcm_element,
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
498 SND_MIXER_SCHN_FRONT_RIGHT,
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
499 &lr);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
500 *l = ll;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
501 *r = lr;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
502 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
503 if (mixer_timeout)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
504 gtk_timeout_remove(mixer_timeout);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
505 mixer_timeout = gtk_timeout_add(5000, alsa_mixer_timeout, NULL);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
506 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
507
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
508
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
509 void alsa_set_volume(int l, int r)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
510 {
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
511 if (alsa_cfg.soft_volume)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
512 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
513 alsa_cfg.vol.left = l;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
514 alsa_cfg.vol.right = r;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
515 return;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
516 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
517
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
518 if (!pcm_element)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
519 return;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
520
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
521 snd_mixer_selem_set_playback_volume(pcm_element,
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
522 SND_MIXER_SCHN_FRONT_LEFT, l);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
523 snd_mixer_selem_set_playback_volume(pcm_element,
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
524 SND_MIXER_SCHN_FRONT_RIGHT, r);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
525 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
526
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
527
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
528 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
529 * audio stuff
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
530 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
531
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
532 /* return the size of audio data filled in the audio thread buffer */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
533 static int get_thread_buffer_filled(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
534 {
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
535 if (wr_index >= rd_index)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
536 return wr_index - rd_index;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
537 return thread_buffer_size - (rd_index - wr_index);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
538 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
539
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
540 int alsa_get_output_time(void)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
541 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
542 snd_pcm_sframes_t delay;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
543 guint64 bytes = alsa_hw_written;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
544
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
545 if (!going || alsa_pcm == NULL)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
546 return 0;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
547
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
548 if (!snd_pcm_delay(alsa_pcm, &delay))
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
549 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
550 unsigned int d = snd_pcm_frames_to_bytes(alsa_pcm, delay);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
551 if (bytes < d)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
552 bytes = 0;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
553 else
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
554 bytes -= d;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
555 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
556 return output_time_offset + (bytes * 1000) / outputf->bps;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
557 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
558
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
559 int alsa_get_written_time(void)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
560 {
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
561 if (!going)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
562 return 0;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
563 return (alsa_total_written * 1000) / inputf->bps;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
564 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
565
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
566 #define STEREO_ADJUST(type, type2, endian) \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
567 do { \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
568 type *ptr = data; \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
569 for (i = 0; i < length; i += 4) \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
570 { \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
571 *ptr = type2##_TO_##endian(type2##_FROM_## endian(*ptr) * \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
572 alsa_cfg.vol.left / 100); \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
573 ptr++; \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
574 *ptr = type2##_TO_##endian(type2##_FROM_##endian(*ptr) * \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
575 alsa_cfg.vol.right / 100); \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
576 ptr++; \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
577 } \
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
578 } while (0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
579
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
580 #define MONO_ADJUST(type, type2, endian) \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
581 do { \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
582 type *ptr = data; \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
583 for (i = 0; i < length; i += 2) \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
584 { \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
585 *ptr = type2##_TO_##endian(type2##_FROM_## endian(*ptr) * \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
586 vol / 100); \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
587 ptr++; \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
588 } \
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
589 } while (0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
590
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
591 #define VOLUME_ADJUST(type, type2, endian) \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
592 do { \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
593 if (channels == 2) \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
594 STEREO_ADJUST(type, type2, endian); \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
595 else \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
596 MONO_ADJUST(type, type2, endian); \
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
597 } while (0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
598
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
599 #define STEREO_ADJUST8(type) \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
600 do { \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
601 type *ptr = data; \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
602 for (i = 0; i < length; i += 2) \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
603 { \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
604 *ptr = *ptr * alsa_cfg.vol.left / 100; \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
605 ptr++; \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
606 *ptr = *ptr * alsa_cfg.vol.right / 100; \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
607 ptr++; \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
608 } \
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
609 } while (0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
610
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
611 #define MONO_ADJUST8(type) \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
612 do { \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
613 type *ptr = data; \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
614 for (i = 0; i < length; i++) \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
615 { \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
616 *ptr = *ptr * vol / 100; \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
617 ptr++; \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
618 } \
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
619 } while (0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
620
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
621 #define VOLUME_ADJUST8(type) \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
622 do { \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
623 if (channels == 2) \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
624 STEREO_ADJUST8(type); \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
625 else \
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
626 MONO_ADJUST8(type); \
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
627 } while (0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
628
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
629
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
630 static void volume_adjust(void* data, int length, AFormat fmt, int channels)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
631 {
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
632 int i, vol;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
633
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
634 if ((alsa_cfg.vol.left == 100 && alsa_cfg.vol.right == 100) ||
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
635 (channels == 1 &&
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
636 (alsa_cfg.vol.left == 100 || alsa_cfg.vol.right == 100)))
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
637 return;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
638
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
639 vol = MAX(alsa_cfg.vol.left, alsa_cfg.vol.right);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
640
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
641 switch (fmt)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
642 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
643 case FMT_S16_LE:
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
644 VOLUME_ADJUST(gint16, GINT16, LE);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
645 break;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
646 case FMT_U16_LE:
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
647 VOLUME_ADJUST(guint16, GUINT16, LE);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
648 break;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
649 case FMT_S16_BE:
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
650 VOLUME_ADJUST(gint16, GINT16, BE);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
651 break;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
652 case FMT_U16_BE:
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
653 VOLUME_ADJUST(guint16, GUINT16, BE);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
654 break;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
655 case FMT_S8:
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
656 VOLUME_ADJUST8(gint8);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
657 break;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
658 case FMT_U8:
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
659 VOLUME_ADJUST8(guint8);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
660 break;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
661 default:
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
662 g_warning("volue_adjust(): unhandled format: %d", fmt);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
663 break;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
664 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
665 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
666
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
667
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
668 /* transfer data to audio h/w; length is given in bytes
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
669 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
670 * data can be modified via effect plugin, rate conversion or
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
671 * software volume before passed to audio h/w
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
672 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
673 static void alsa_do_write(gpointer data, int length)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
674 {
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
675 EffectPlugin *ep = NULL;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
676 int new_freq;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
677 int new_chn;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
678 AFormat f;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
679
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
680 if (paused)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
681 return;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
682
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
683 new_freq = inputf->rate;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
684 new_chn = inputf->channels;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
685 f = inputf->xmms_format;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
686
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
687 if (effects_enabled() && (ep = get_current_effect_plugin()) &&
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
688 ep->query_format)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
689 ep->query_format(&f, &new_freq, &new_chn);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
690
701
d539e5c5f730 [svn] Fixes of the remaining GCC 4.1 warnings from external contributor Diego "Flameeyes" Petteno (Gentoo).
chainsaw
parents: 517
diff changeset
691 if (f != effectf->xmms_format || (unsigned int)new_freq != effectf->rate ||
d539e5c5f730 [svn] Fixes of the remaining GCC 4.1 warnings from external contributor Diego "Flameeyes" Petteno (Gentoo).
chainsaw
parents: 517
diff changeset
692 (unsigned int)new_chn != effectf->channels)
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
693 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
694 debug("Changing audio format for effect plugin");
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
695 g_free(effectf);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
696 effectf = snd_format_from_xmms(f, new_freq, new_chn);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
697 if (alsa_reopen(effectf) < 0)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
698 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
699 /* fatal error... */
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
700 alsa_close();
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
701 return;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
702 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
703 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
704
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
705 if (ep)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
706 length = ep->mod_samples(&data, length,
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
707 inputf->xmms_format,
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
708 inputf->rate,
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
709 inputf->channels);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
710
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
711 if (alsa_convert_func != NULL)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
712 length = alsa_convert_func(convertb, &data, length);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
713 if (alsa_stereo_convert_func != NULL)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
714 length = alsa_stereo_convert_func(convertb, &data, length);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
715 if (alsa_frequency_convert_func != NULL)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
716 length = alsa_frequency_convert_func(convertb, &data, length,
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
717 effectf->rate,
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
718 outputf->rate);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
719
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
720 if (alsa_cfg.soft_volume)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
721 volume_adjust(data, length, outputf->xmms_format, outputf->channels);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
722
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
723 alsa_write_audio(data, length);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
724 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
725
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
726 /* write callback */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
727 void alsa_write(gpointer data, int length)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
728 {
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
729 int cnt;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
730 char *src = (char *)data;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
731
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
732 remove_prebuffer = FALSE;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
733
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
734 alsa_total_written += length;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
735 while (length > 0)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
736 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
737 int wr;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
738 cnt = MIN(length, thread_buffer_size - wr_index);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
739 memcpy(thread_buffer + wr_index, src, cnt);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
740 wr = (wr_index + cnt) % thread_buffer_size;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
741 wr_index = wr;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
742 length -= cnt;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
743 src += cnt;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
744 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
745 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
746
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
747 /* transfer data to audio h/w via normal write */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
748 static void alsa_write_audio(char *data, int length)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
749 {
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
750 snd_pcm_sframes_t written_frames;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
751
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
752 while (length > 0)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
753 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
754 int frames = snd_pcm_bytes_to_frames(alsa_pcm, length);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
755 written_frames = snd_pcm_writei(alsa_pcm, data, frames);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
756
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
757 if (written_frames > 0)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
758 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
759 int written = snd_pcm_frames_to_bytes(alsa_pcm,
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
760 written_frames);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
761 length -= written;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
762 data += written;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
763 alsa_hw_written += written;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
764 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
765 else
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
766 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
767 int err = alsa_handle_error((int)written_frames);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
768 if (err < 0)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
769 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
770 g_warning("alsa_write_audio(): write error: %s",
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
771 snd_strerror(-err));
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
772 break;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
773 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
774 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
775 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
776 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
777
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
778 /* transfer audio data from thread buffer to h/w */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
779 static void alsa_write_out_thread_data(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
780 {
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
781 gint length, cnt, avail;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
782
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
783 length = MIN(hw_period_size_in, get_thread_buffer_filled());
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
784 avail = snd_pcm_frames_to_bytes(alsa_pcm, alsa_get_avail());
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
785 length = MIN(length, avail);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
786 while (length > 0)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
787 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
788 int rd;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
789 cnt = MIN(length, thread_buffer_size - rd_index);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
790 alsa_do_write(thread_buffer + rd_index, cnt);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
791 rd = (rd_index + cnt) % thread_buffer_size;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
792 rd_index = rd;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
793 length -= cnt;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
794 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
795 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
796
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
797 /* audio thread loop */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
798 /* FIXME: proper lock? */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
799 static void *alsa_loop(void *arg)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
800 {
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
801 int npfds = snd_pcm_poll_descriptors_count(alsa_pcm);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
802 struct pollfd *pfds;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
803 unsigned short *revents;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
804
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
805 if (npfds <= 0)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
806 goto _error;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
807 pfds = alloca(sizeof(*pfds) * npfds);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
808 revents = alloca(sizeof(*revents) * npfds);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
809 while (going && alsa_pcm)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
810 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
811 if (get_thread_buffer_filled() > prebuffer_size)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
812 prebuffer = FALSE;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
813 if (!paused && !prebuffer &&
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
814 get_thread_buffer_filled() > hw_period_size_in)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
815 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
816 snd_pcm_poll_descriptors(alsa_pcm, pfds, npfds);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
817 if (poll(pfds, npfds, 10) > 0)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
818 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
819 /*
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
820 * need to check revents. poll() with
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
821 * dmix returns a postive value even
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
822 * if no data is available
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
823 */
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
824 int i;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
825 snd_pcm_poll_descriptors_revents(alsa_pcm, pfds,
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
826 npfds, revents);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
827 for (i = 0; i < npfds; i++)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
828 if (revents[i] & POLLOUT)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
829 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
830 alsa_write_out_thread_data();
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
831 break;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
832 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
833 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
834 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
835 else
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
836 xmms_usleep(10000);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
837
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
838 if (pause_request != paused)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
839 alsa_do_pause(pause_request);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
840
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
841 if (flush_request != -1)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
842 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
843 alsa_do_flush(flush_request);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
844 flush_request = -1;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
845 prebuffer = TRUE;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
846 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
847 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
848
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
849 _error:
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
850 alsa_close_pcm();
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
851 g_free(thread_buffer);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
852 thread_buffer = NULL;
215
84162f8f2164 [svn] GThreadify output plugin.
chainsaw
parents: 211
diff changeset
853 g_thread_exit(NULL);
246
acae8fa925c3 [svn] Add casts to callbacks in signal handlers to avoid warning. GCC would like a return statement too.
chainsaw
parents: 215
diff changeset
854 return(NULL);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
855 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
856
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
857 /* open callback */
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
858 int alsa_open(AFormat fmt, int rate, int nch)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
859 {
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
860 debug("Opening device");
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
861 inputf = snd_format_from_xmms(fmt, rate, nch);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
862 effectf = snd_format_from_xmms(fmt, rate, nch);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
863
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
864 if (alsa_cfg.debug)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
865 snd_output_stdio_attach(&logs, stdout, 0);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
866
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
867 if (alsa_setup(inputf) < 0)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
868 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
869 alsa_close();
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
870 return 0;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
871 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
872
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
873 if (!mixer)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
874 alsa_setup_mixer();
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
875
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
876 convertb = xmms_convert_buffers_new();
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
877
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
878 output_time_offset = 0;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
879 alsa_total_written = alsa_hw_written = 0;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
880 going = TRUE;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
881 paused = FALSE;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
882 prebuffer = TRUE;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
883 remove_prebuffer = FALSE;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
884
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
885 thread_buffer_size = (guint64)alsa_cfg.thread_buffer_time * inputf->bps / 1000;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
886 if (thread_buffer_size < hw_buffer_size)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
887 thread_buffer_size = hw_buffer_size * 2;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
888 if (thread_buffer_size < 8192)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
889 thread_buffer_size = 8192;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
890 prebuffer_size = thread_buffer_size / 2;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
891 if (prebuffer_size < 8192)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
892 prebuffer_size = 8192;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
893 thread_buffer_size += hw_buffer_size;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
894 thread_buffer_size -= thread_buffer_size % hw_period_size;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
895 thread_buffer = g_malloc0(thread_buffer_size);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
896 wr_index = rd_index = 0;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
897 pause_request = FALSE;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
898 flush_request = -1;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
899
215
84162f8f2164 [svn] GThreadify output plugin.
chainsaw
parents: 211
diff changeset
900 audio_thread = g_thread_create((GThreadFunc)alsa_loop, NULL, TRUE, NULL);
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
901 return 1;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
902 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
903
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
904 static struct snd_format * snd_format_from_xmms(AFormat fmt, int rate, int channels)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
905 {
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
906 struct snd_format *f = g_malloc(sizeof(struct snd_format));
701
d539e5c5f730 [svn] Fixes of the remaining GCC 4.1 warnings from external contributor Diego "Flameeyes" Petteno (Gentoo).
chainsaw
parents: 517
diff changeset
907 size_t i;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
908
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
909 f->xmms_format = fmt;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
910 f->format = SND_PCM_FORMAT_UNKNOWN;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
911
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
912 for (i = 0; i < sizeof(format_table) / sizeof(format_table[0]); i++)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
913 if (format_table[i].xmms == fmt)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
914 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
915 f->format = format_table[i].alsa;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
916 break;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
917 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
918
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
919 /* Get rid of _NE */
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
920 for (i = 0; i < sizeof(format_table) / sizeof(format_table[0]); i++)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
921 if (format_table[i].alsa == f->format)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
922 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
923 f->xmms_format = format_table[i].xmms;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
924 break;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
925 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
926
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
927
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
928 f->rate = rate;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
929 f->channels = channels;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
930 f->sample_bits = snd_pcm_format_physical_width(f->format);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
931 f->bps = (rate * f->sample_bits * channels) >> 3;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
932
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
933 return f;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
934 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
935
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
936 static int format_from_alsa(snd_pcm_format_t fmt)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
937 {
701
d539e5c5f730 [svn] Fixes of the remaining GCC 4.1 warnings from external contributor Diego "Flameeyes" Petteno (Gentoo).
chainsaw
parents: 517
diff changeset
938 size_t i;
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
939 for (i = 0; i < sizeof(format_table) / sizeof(format_table[0]); i++)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
940 if (format_table[i].alsa == fmt)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
941 return format_table[i].xmms;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
942 g_warning("Unsupported format: %s", snd_pcm_format_name(fmt));
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
943 return -1;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
944 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
945
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
946 static int alsa_setup(struct snd_format *f)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
947 {
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
948 int err;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
949 snd_pcm_hw_params_t *hwparams;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
950 snd_pcm_sw_params_t *swparams;
400
197bf689da02 [svn] Care about pointer signedness.
chainsaw
parents: 249
diff changeset
951 uint alsa_buffer_time;
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
952 unsigned int alsa_period_time;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
953 snd_pcm_uframes_t alsa_buffer_size, alsa_period_size;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
954
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
955 debug("alsa_setup");
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
956
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
957 alsa_convert_func = NULL;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
958 alsa_stereo_convert_func = NULL;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
959 alsa_frequency_convert_func = NULL;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
960
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
961 g_free(outputf);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
962 outputf = snd_format_from_xmms(f->xmms_format, f->rate, f->channels);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
963
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
964 debug("Opening device: %s", alsa_cfg.pcm_device);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
965 /* FIXME: Can snd_pcm_open() return EAGAIN? */
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
966 if ((err = snd_pcm_open(&alsa_pcm, alsa_cfg.pcm_device,
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
967 SND_PCM_STREAM_PLAYBACK,
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
968 SND_PCM_NONBLOCK)) < 0)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
969 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
970 g_warning("alsa_setup(): Failed to open pcm device (%s): %s",
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
971 alsa_cfg.pcm_device, snd_strerror(-err));
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
972 alsa_pcm = NULL;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
973 g_free(outputf);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
974 outputf = NULL;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
975 return -1;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
976 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
977
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
978 /* doesn't care about non-blocking */
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
979 /* snd_pcm_nonblock(alsa_pcm, 0); */
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
980
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
981 if (alsa_cfg.debug)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
982 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
983 snd_pcm_info_t *info;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
984 int alsa_card, alsa_device, alsa_subdevice;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
985
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
986 snd_pcm_info_alloca(&info);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
987 snd_pcm_info(alsa_pcm, info);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
988 alsa_card = snd_pcm_info_get_card(info);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
989 alsa_device = snd_pcm_info_get_device(info);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
990 alsa_subdevice = snd_pcm_info_get_subdevice(info);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
991 printf("Card %i, Device %i, Subdevice %i\n",
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
992 alsa_card, alsa_device, alsa_subdevice);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
993 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
994
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
995 snd_pcm_hw_params_alloca(&hwparams);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
996
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
997 if ((err = snd_pcm_hw_params_any(alsa_pcm, hwparams)) < 0)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
998 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
999 g_warning("alsa_setup(): No configuration available for "
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1000 "playback: %s", snd_strerror(-err));
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1001 return -1;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1002 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1003
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1004 if ((err = snd_pcm_hw_params_set_access(alsa_pcm, hwparams,
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1005 SND_PCM_ACCESS_RW_INTERLEAVED)) < 0)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1006 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1007 g_warning("alsa_setup(): Cannot set direct write mode: %s",
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1008 snd_strerror(-err));
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1009 return -1;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1010 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1011
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1012 if ((err = snd_pcm_hw_params_set_format(alsa_pcm, hwparams, outputf->format)) < 0)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1013 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1014 /*
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1015 * Try if one of these format work (one of them should work
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1016 * on almost all soundcards)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1017 */
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1018 snd_pcm_format_t formats[] = {SND_PCM_FORMAT_S16_LE,
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1019 SND_PCM_FORMAT_S16_BE,
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1020 SND_PCM_FORMAT_U8};
701
d539e5c5f730 [svn] Fixes of the remaining GCC 4.1 warnings from external contributor Diego "Flameeyes" Petteno (Gentoo).
chainsaw
parents: 517
diff changeset
1021 size_t i;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1022
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1023 for (i = 0; i < sizeof(formats) / sizeof(formats[0]); i++)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1024 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1025 if (snd_pcm_hw_params_set_format(alsa_pcm, hwparams,
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1026 formats[i]) == 0)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1027 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1028 outputf->format = formats[i];
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1029 break;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1030 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1031 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1032 if (outputf->format != f->format)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1033 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1034 outputf->xmms_format =
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1035 format_from_alsa(outputf->format);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1036 debug("Converting format from %d to %d",
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1037 f->xmms_format, outputf->xmms_format);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1038 alsa_convert_func =
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1039 xmms_convert_get_func(outputf->xmms_format,
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1040 f->xmms_format);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1041 if (alsa_convert_func == NULL)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1042 return -1;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1043 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1044 else
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1045 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1046 g_warning("alsa_setup(): Sample format not "
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1047 "available for playback: %s",
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1048 snd_strerror(-err));
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1049 return -1;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1050 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1051 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1052
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1053 snd_pcm_hw_params_set_channels_near(alsa_pcm, hwparams, &outputf->channels);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1054 if (outputf->channels != f->channels)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1055 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1056 debug("Converting channels from %d to %d",
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1057 f->channels, outputf->channels);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1058 alsa_stereo_convert_func =
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1059 xmms_convert_get_channel_func(outputf->xmms_format,
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1060 outputf->channels,
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1061 f->channels);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1062 if (alsa_stereo_convert_func == NULL)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1063 return -1;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1064 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1065
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1066 snd_pcm_hw_params_set_rate_near(alsa_pcm, hwparams, &outputf->rate, 0);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1067 if (outputf->rate == 0)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1068 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1069 g_warning("alsa_setup(): No usable samplerate available.");
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1070 return -1;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1071 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1072 if (outputf->rate != f->rate)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1073 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1074 debug("Converting samplerate from %d to %d",
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1075 f->rate, outputf->rate);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1076 alsa_frequency_convert_func =
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1077 xmms_convert_get_frequency_func(outputf->xmms_format,
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1078 outputf->channels);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1079 if (alsa_frequency_convert_func == NULL)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1080 return -1;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1081 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1082
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1083 outputf->sample_bits = snd_pcm_format_physical_width(outputf->format);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1084 outputf->bps = (outputf->rate * outputf->sample_bits * outputf->channels) >> 3;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1085
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1086 alsa_buffer_time = alsa_cfg.buffer_time * 1000;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1087 if ((err = snd_pcm_hw_params_set_buffer_time_near(alsa_pcm, hwparams,
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1088 &alsa_buffer_time, 0)) < 0)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1089 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1090 g_warning("alsa_setup(): Set buffer time failed: %s.",
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1091 snd_strerror(-err));
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1092 return -1;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1093 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1094
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1095 alsa_period_time = alsa_cfg.period_time * 1000;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1096 if ((err = snd_pcm_hw_params_set_period_time_near(alsa_pcm, hwparams,
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1097 &alsa_period_time, 0)) < 0)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1098 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1099 g_warning("alsa_setup(): Set period time failed: %s.",
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1100 snd_strerror(-err));
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1101 return -1;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1102 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1103
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1104 if (snd_pcm_hw_params(alsa_pcm, hwparams) < 0)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1105 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1106 if (alsa_cfg.debug)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1107 snd_pcm_hw_params_dump(hwparams, logs);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1108 g_warning("alsa_setup(): Unable to install hw params");
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1109 return -1;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1110 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1111
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1112 if ((err = snd_pcm_hw_params_get_buffer_size(hwparams, &alsa_buffer_size)) < 0)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1113 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1114 g_warning("alsa_setup(): snd_pcm_hw_params_get_buffer_size() "
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1115 "failed: %s",
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1116 snd_strerror(-err));
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1117 return -1;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1118 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1119
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1120 if ((err = snd_pcm_hw_params_get_period_size(hwparams, &alsa_period_size, 0)) < 0)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1121 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1122 g_warning("alsa_setup(): snd_pcm_hw_params_get_period_size() "
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1123 "failed: %s",
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1124 snd_strerror(-err));
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1125 return -1;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1126 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1127
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1128 alsa_can_pause = snd_pcm_hw_params_can_pause(hwparams);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1129
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1130 snd_pcm_sw_params_alloca(&swparams);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1131 snd_pcm_sw_params_current(alsa_pcm, swparams);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1132
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1133 /* This has effect for non-mmap only */
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1134 if ((err = snd_pcm_sw_params_set_start_threshold(alsa_pcm,
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1135 swparams, alsa_buffer_size - alsa_period_size) < 0))
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1136 g_warning("alsa_setup(): setting start "
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1137 "threshold failed: %s", snd_strerror(-err));
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1138 if (snd_pcm_sw_params(alsa_pcm, swparams) < 0)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1139 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1140 g_warning("alsa_setup(): Unable to install sw params");
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1141 return -1;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1142 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1143
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1144 if (alsa_cfg.debug)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1145 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1146 snd_pcm_sw_params_dump(swparams, logs);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1147 snd_pcm_dump(alsa_pcm, logs);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1148 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1149
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1150 hw_buffer_size = snd_pcm_frames_to_bytes(alsa_pcm, alsa_buffer_size);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1151 hw_period_size = snd_pcm_frames_to_bytes(alsa_pcm, alsa_period_size);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1152 if (inputf->bps != outputf->bps)
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1153 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1154 int align = (inputf->sample_bits * inputf->channels) / 8;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1155 hw_buffer_size_in = ((guint64)hw_buffer_size * inputf->bps +
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1156 outputf->bps/2) / outputf->bps;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1157 hw_period_size_in = ((guint64)hw_period_size * inputf->bps +
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1158 outputf->bps/2) / outputf->bps;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1159 hw_buffer_size_in -= hw_buffer_size_in % align;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1160 hw_period_size_in -= hw_period_size_in % align;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1161 }
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1162 else
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1163 {
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1164 hw_buffer_size_in = hw_buffer_size;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1165 hw_period_size_in = hw_period_size;
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1166 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1167
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1168 debug("Device setup: buffer time: %i, size: %i.", alsa_buffer_time,
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1169 hw_buffer_size);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1170 debug("Device setup: period time: %i, size: %i.", alsa_period_time,
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1171 hw_period_size);
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1172 debug("bits per sample: %i; frame size: %i; Bps: %i",
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1173 snd_pcm_format_physical_width(outputf->format),
249
a4566101cab4 [svn] Add two missing casts and update the player buffer description from XMMS to Audacious.
chainsaw
parents: 246
diff changeset
1174 (int)snd_pcm_frames_to_bytes(alsa_pcm, 1), outputf->bps);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1175
211
0b48662886e9 [svn] Sync ALSA plugin with enhancements/patches from Fatal (XMMS cvs)
nenolod
parents: 61
diff changeset
1176 return 0;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1177 }
517
55dc40ff1aff [svn] Add tell_audio(AFormat *, gint *, gint *), for retrieving audio
nenolod
parents: 400
diff changeset
1178
55dc40ff1aff [svn] Add tell_audio(AFormat *, gint *, gint *), for retrieving audio
nenolod
parents: 400
diff changeset
1179 void alsa_tell(AFormat * fmt, gint * rate, gint * nch)
55dc40ff1aff [svn] Add tell_audio(AFormat *, gint *, gint *), for retrieving audio
nenolod
parents: 400
diff changeset
1180 {
55dc40ff1aff [svn] Add tell_audio(AFormat *, gint *, gint *), for retrieving audio
nenolod
parents: 400
diff changeset
1181 (*fmt) = inputf->xmms_format;
55dc40ff1aff [svn] Add tell_audio(AFormat *, gint *, gint *), for retrieving audio
nenolod
parents: 400
diff changeset
1182 (*rate) = inputf->rate;
55dc40ff1aff [svn] Add tell_audio(AFormat *, gint *, gint *), for retrieving audio
nenolod
parents: 400
diff changeset
1183 (*nch) = inputf->channels;
55dc40ff1aff [svn] Add tell_audio(AFormat *, gint *, gint *), for retrieving audio
nenolod
parents: 400
diff changeset
1184 }