annotate libao2/ao_alsa1x.c @ 1090:fd0d77973d08

bugfix
author szabii
date Sun, 10 Jun 2001 23:40:20 +0000
parents cab5ba9ffc6c
children a16b569f2702
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
1 /*
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
2 ao_alsa9 - ALSA-0.9.x output plugin for MPlayer
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
3
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
4 (C) Alex Beregszaszi <alex@naxine.org>
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
5 */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
6
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
7 #include <errno.h>
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
8 #include <sys/asoundlib.h>
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
9
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
10 #include "../config.h"
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
11
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
12 #include "audio_out.h"
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
13 #include "audio_out_internal.h"
1058
cab5ba9ffc6c fixed AFMT_ stuff (inclue afmt.h)
arpi_esp
parents: 1050
diff changeset
14 #include "afmt.h"
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
15
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
16 extern int verbose;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
17
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
18 static ao_info_t info =
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
19 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
20 "ALSA-0.9.x audio output",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
21 "alsa9",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
22 "Alex Beregszaszi <alex@naxine.org>",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
23 "under developement"
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
24 };
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
25
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
26 LIBAO_EXTERN(alsa9)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
27
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
28 /* global variables:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
29 ao_samplerate
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
30 ao_channels
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
31 ao_format
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
32 ao_bps
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
33 ao_outburst
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
34 ao_buffersize
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
35 */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
36
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
37 static snd_pcm_t *alsa_handler;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
38 static snd_pcm_format_t alsa_format;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
39 static snd_pcm_hw_params_t *alsa_hwparams;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
40 static snd_pcm_sw_params_t *alsa_swparams;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
41 static char *alsa_device;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
42 #define ALSA_DEVICE_SIZE 48
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
43
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
44 /* to set/get/query special features/parameters */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
45 static int control(int cmd, int arg)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
46 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
47 switch(cmd)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
48 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
49 case AOCONTROL_GET_DEVICE:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
50 return(char *)alsa_device; /* egy kicsit brutalis, dehat :) */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
51 case AOCONTROL_SET_DEVICE:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
52 strncpy(alsa_device, (char *)arg, ALSA_DEVICE_SIZE);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
53 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
54 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
55 return(CONTROL_UNKNOWN);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
56 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
57
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
58 /*
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
59 open & setup audio device
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
60 return: 1=success 0=fail
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
61 */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
62 static int init(int rate_hz, int channels, int format, int flags)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
63 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
64 int err;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
65 int cards = -1;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
66 snd_pcm_info_t *alsa_info;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
67 int chunck_size;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
68
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
69 printf("alsa-init: requested format: %d Hz, %d channels, %s\n", rate_hz,
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
70 channels, audio_out_format_name(format));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
71
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
72 alsa_handler = NULL;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
73
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
74 if (verbose)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
75 printf("alsa-init: compiled for ALSA-%s (%d)\n", SND_LIB_VERSION_STR,
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
76 SND_LIB_VERSION);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
77
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
78 if ((err = snd_card_next(&cards)) < 0 || cards < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
79 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
80 printf("alsa-init: no soundcards found: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
81 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
82 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
83
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
84 ao_format = format;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
85 ao_channels = channels - 1;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
86 ao_samplerate = rate_hz;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
87 ao_bps = ao_samplerate*(ao_channels+1);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
88 ao_outburst = OUTBURST;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
89 ao_buffersize = 16384;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
90
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
91 memset(&alsa_format, 0, sizeof(alsa_format));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
92 switch (format)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
93 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
94 case AFMT_S8:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
95 alsa_format = SND_PCM_FORMAT_S8;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
96 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
97 case AFMT_U8:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
98 alsa_format = SND_PCM_FORMAT_U8;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
99 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
100 case AFMT_U16_LE:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
101 alsa_format = SND_PCM_FORMAT_U16_LE;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
102 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
103 case AFMT_U16_BE:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
104 alsa_format = SND_PCM_FORMAT_U16_BE;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
105 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
106 case AFMT_S16_LE:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
107 alsa_format = SND_PCM_FORMAT_S16_LE;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
108 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
109 case AFMT_S16_BE:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
110 alsa_format = SND_PCM_FORMAT_S16_BE;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
111 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
112 default:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
113 alsa_format = SND_PCM_FORMAT_MPEG;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
114 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
115 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
116
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
117 switch(alsa_format)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
118 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
119 case SND_PCM_FORMAT_S16_LE:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
120 case SND_PCM_FORMAT_U16_LE:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
121 ao_bps *= 2;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
122 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
123 case -1:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
124 printf("alsa-init: invalid format (%s) requested - output disabled\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
125 audio_out_format_name(format));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
126 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
127 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
128
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
129 if ((err = snd_pcm_info_malloc(&alsa_info)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
130 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
131 printf("alsa-init: memory allocation error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
132 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
133 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
134
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
135 if ((alsa_device = malloc(ALSA_DEVICE_SIZE)) == NULL)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
136 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
137 printf("alsa-init: memory allocation error: %s\n", strerror(errno));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
138 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
139 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
140
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
141 snprintf(alsa_device, ALSA_DEVICE_SIZE, "hw:%d,%d",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
142 snd_pcm_info_get_device(alsa_info),
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
143 snd_pcm_info_get_subdevice(alsa_info));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
144
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
145 snd_pcm_info_free(alsa_info);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
146
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
147 printf("alsa-init: %d soundcard%s found, using: %s\n", cards+1,
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
148 (cards >= 0) ? "" : "s", alsa_device);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
149
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
150 if ((err = snd_pcm_open(&alsa_handler, alsa_device, SND_PCM_STREAM_PLAYBACK,
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
151 0)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
152 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
153 printf("alsa-init: playback open error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
154 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
155 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
156
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
157 snd_pcm_hw_params_malloc(&alsa_hwparams);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
158 snd_pcm_sw_params_malloc(&alsa_swparams);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
159
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
160 if ((err = snd_pcm_hw_params_any(alsa_handler, alsa_hwparams)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
161 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
162 printf("alsa-init: unable to get initial parameters: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
163 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
164 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
165 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
166
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
167 if ((err = snd_pcm_hw_params_set_access(alsa_handler, alsa_hwparams,
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
168 SND_PCM_ACCESS_RW_INTERLEAVED)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
169 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
170 printf("alsa-init: unable to set access type: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
171 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
172 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
173 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
174
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
175 if ((err = snd_pcm_hw_params_set_format(alsa_handler, alsa_hwparams,
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
176 alsa_format)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
177 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
178 printf("alsa-init: unable to set format: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
179 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
180 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
181 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
182
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
183 if ((err = snd_pcm_hw_params_set_channels(alsa_handler, alsa_hwparams,
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
184 ao_channels)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
185 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
186 printf("alsa-init: unable to set channels: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
187 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
188 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
189 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
190
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
191 if ((err = snd_pcm_hw_params_set_rate(alsa_handler, alsa_hwparams,
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
192 ao_samplerate, 0)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
193 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
194 printf("alsa-init: unable to set channels: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
195 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
196 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
197 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
198
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
199 #ifdef buffersize
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
200 if ((err = snd_pcm_hw_params_get_buffer_size(alsa_hwparams)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
201 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
202 printf("alsa-init: unable to get buffer size: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
203 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
204 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
205 } else
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
206 ao_buffersize = err;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
207 #endif
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
208
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
209 #ifdef buffertime
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
210 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
211 int alsa_buffer_time = 60;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
212
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
213 if ((err = snd_pcm_hw_params_set_buffer_time_near(alsa_handler, alsa_hwparams,
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
214 alsa_buffer_time, 0)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
215 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
216 printf("alsa-init: unable to set buffer time near: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
217 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
218 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
219 } else
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
220 alsa_buffer_time = err;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
221
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
222 if ((err = snd_pcm_hw_params_set_period_time_near(alsa_handler, alsa_hwparams,
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
223 alsa_buffer_time/ao_bps, 0)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
224 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
225 printf("alsa-init: unable to set period time: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
226 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
227 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
228 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
229 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
230 #endif
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
231
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
232 if ((err = snd_pcm_hw_params(alsa_handler, alsa_hwparams)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
233 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
234 printf("alsa-init: unable to set parameters: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
235 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
236 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
237 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
238
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
239 if ((err = snd_pcm_sw_params_current(alsa_handler, alsa_swparams)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
240 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
241 printf("alsa-init: unable to get parameters: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
242 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
243 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
244 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
245
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
246 if ((err = snd_pcm_sw_params_set_start_mode(alsa_handler, alsa_swparams,
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
247 SND_PCM_START_DATA)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
248 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
249 printf("alsa-init: unable to set start mode: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
250 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
251 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
252 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
253
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
254 if ((err = snd_pcm_sw_params(alsa_handler, alsa_swparams)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
255 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
256 printf("alsa-init: unable to set parameters: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
257 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
258 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
259 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
260
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
261 snd_pcm_sw_params_default(alsa_handler, alsa_swparams);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
262
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
263 if ((err = snd_pcm_prepare(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
264 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
265 printf("alsa-init: pcm prepare error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
266 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
267 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
268
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
269 if ((err = snd_pcm_start(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
270 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
271 printf("alsa-init: pcm start error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
272 if (err != -EPIPE)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
273 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
274 if ((err = snd_pcm_start(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
275 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
276 printf("alsa-init: pcm start error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
277 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
278 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
279 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
280
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
281 printf("AUDIO: %d Hz/%d channels/%d bps/%d bytes buffer/%s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
282 ao_samplerate, ao_channels+1, ao_bps, ao_buffersize,
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
283 snd_pcm_format_description(alsa_format));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
284 return(1);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
285 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
286
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
287 /* close audio device */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
288 static void uninit()
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
289 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
290 int err;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
291
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
292 if (alsa_device != NULL)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
293 free(alsa_device);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
294
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
295 snd_pcm_hw_params_free(alsa_hwparams);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
296 snd_pcm_sw_params_free(alsa_swparams);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
297
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
298 if ((err = snd_pcm_drain(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
299 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
300 printf("alsa-uninit: pcm drain error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
301 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
302 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
303
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
304 if ((err = snd_pcm_reset(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
305 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
306 printf("alsa-uninit: pcm reset error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
307 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
308 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
309
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
310 if ((err = snd_pcm_close(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
311 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
312 printf("alsa-uninit: pcm close error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
313 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
314 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
315 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
316
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
317 static void audio_pause()
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
318 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
319 int err;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
320
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
321 if ((err = snd_pcm_drain(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
322 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
323 printf("alsa-pause: pcm drain error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
324 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
325 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
326
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
327 if ((err = snd_pcm_reset(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
328 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
329 printf("alsa-pause: pcm reset error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
330 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
331 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
332 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
333
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
334 static void audio_resume()
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
335 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
336 int err;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
337
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
338 if ((err = snd_pcm_prepare(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
339 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
340 printf("alsa-resume: pcm prepare error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
341 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
342 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
343
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
344 if ((err = snd_pcm_start(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
345 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
346 printf("alsa-resume: pcm start error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
347 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
348 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
349 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
350
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
351 /* stop playing and empty buffers (for seeking/pause) */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
352 static void reset()
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
353 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
354 int err;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
355
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
356 if ((err = snd_pcm_drain(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
357 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
358 printf("alsa-reset: pcm drain error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
359 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
360 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
361
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
362 if ((err = snd_pcm_reset(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
363 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
364 printf("alsa-reset: pcm reset error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
365 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
366 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
367
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
368 if ((err = snd_pcm_prepare(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
369 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
370 printf("alsa-reset: pcm prepare error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
371 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
372 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
373
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
374 if ((err = snd_pcm_start(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
375 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
376 printf("alsa-reset: pcm start error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
377 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
378 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
379 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
380
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
381 /*
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
382 plays 'len' bytes of 'data'
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
383 returns: number of bytes played
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
384 */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
385 static int play(void* data, int len, int flags)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
386 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
387 if ((len = snd_pcm_writei(alsa_handler, data, len)) != len)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
388 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
389 if (len == -EPIPE) /* underrun? */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
390 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
391 printf("alsa-play: alsa underrun, resetting stream\n");
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
392 if ((len = snd_pcm_prepare(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
393 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
394 printf("alsa-play: playback prepare error: %s\n", snd_strerror(len));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
395 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
396 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
397 if ((len = snd_pcm_writei(alsa_handler, data, len)) != len)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
398 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
399 printf("alsa-play: write error after reset: %s - giving up\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
400 snd_strerror(len));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
401 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
402 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
403 return(len); /* 2nd write was ok */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
404 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
405 printf("alsa-play: output error: %s\n", snd_strerror(len));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
406 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
407 return(len);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
408 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
409
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
410 /* how many byes are free in the buffer */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
411 static int get_space()
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
412 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
413 snd_pcm_status_t *status;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
414 int ret;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
415
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
416 if ((ret = snd_pcm_status_malloc(&status)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
417 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
418 printf("alsa-space: memory allocation error: %s\n", snd_strerror(ret));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
419 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
420 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
421
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
422 if ((ret = snd_pcm_status(alsa_handler, status)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
423 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
424 printf("alsa-space: cannot get pcm status: %s\n", snd_strerror(ret));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
425 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
426 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
427
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
428 switch(snd_pcm_status_get_state(status))
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
429 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
430 case SND_PCM_STATE_OPEN:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
431 case SND_PCM_STATE_PREPARED:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
432 case SND_PCM_STATE_RUNNING:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
433 ret = snd_pcm_status_get_avail(status) * ao_bps;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
434 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
435 default:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
436 ret = 0;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
437 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
438
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
439 snd_pcm_status_free(status);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
440 return(ret);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
441 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
442
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
443 /* how many unplayed bytes are in the buffer */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
444 static int get_delay()
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
445 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
446 snd_pcm_status_t *status;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
447 int ret;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
448
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
449 if ((ret = snd_pcm_status_malloc(&status)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
450 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
451 printf("alsa-delay: memory allocation error: %s\n", snd_strerror(ret));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
452 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
453 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
454
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
455 if ((ret = snd_pcm_status(alsa_handler, status)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
456 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
457 printf("alsa-delay: cannot get pcm status: %s\n", snd_strerror(ret));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
458 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
459 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
460
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
461 switch(snd_pcm_status_get_state(status))
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
462 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
463 case SND_PCM_STATE_OPEN:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
464 case SND_PCM_STATE_PREPARED:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
465 case SND_PCM_STATE_RUNNING:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
466 ret = snd_pcm_status_get_delay(status) * ao_bps;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
467 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
468 default:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
469 ret = 0;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
470 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
471
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
472 snd_pcm_status_free(status);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
473 return(ret);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
474 }