Mercurial > mplayer.hg
annotate libao2/ao_alsa1x.c @ 13121:93774d4a0c1d
id3edit updated
author | diego |
---|---|
date | Tue, 24 Aug 2004 19:29:17 +0000 |
parents | 99798c3cdb93 |
children |
rev | line source |
---|---|
1050 | 1 /* |
11775 | 2 ao_alsa1x - ALSA-1.x output plugin for MPlayer |
1050 | 3 |
10366 | 4 (C) Alex Beregszaszi |
6193
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
5 |
7077 | 6 modified for real alsa-0.9.0-support by Joy Winter <joy@pingfm.org> |
7 additional AC3 passthrough support by Andy Lo A Foe <andy@alsaplayer.org> | |
8 08/22/2002 iec958-init rewritten and merged with common init, joy | |
6193
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
9 |
11775 | 10 Trivial port to ALSA 1.x API by Jindrich Makovicka |
11 | |
7077 | 12 Any bugreports regarding to this driver are welcome. |
1050 | 13 */ |
14 | |
15 #include <errno.h> | |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
16 #include <sys/time.h> |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
17 #include <stdlib.h> |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
18 #include <math.h> |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
19 #include <string.h> |
6749 | 20 #include <sys/poll.h> |
5855
c21948cd027d
fix for latest alsa (sys/asoundlib.h has been moved to alsa/asoundlib.h)
pl
parents:
5790
diff
changeset
|
21 |
5857 | 22 #include "../config.h" |
11764 | 23 #include "../mixer.h" |
5857 | 24 |
5855
c21948cd027d
fix for latest alsa (sys/asoundlib.h has been moved to alsa/asoundlib.h)
pl
parents:
5790
diff
changeset
|
25 #if HAVE_SYS_ASOUNDLIB_H |
1050 | 26 #include <sys/asoundlib.h> |
5855
c21948cd027d
fix for latest alsa (sys/asoundlib.h has been moved to alsa/asoundlib.h)
pl
parents:
5790
diff
changeset
|
27 #elif HAVE_ALSA_ASOUNDLIB_H |
c21948cd027d
fix for latest alsa (sys/asoundlib.h has been moved to alsa/asoundlib.h)
pl
parents:
5790
diff
changeset
|
28 #include <alsa/asoundlib.h> |
c21948cd027d
fix for latest alsa (sys/asoundlib.h has been moved to alsa/asoundlib.h)
pl
parents:
5790
diff
changeset
|
29 #else |
c21948cd027d
fix for latest alsa (sys/asoundlib.h has been moved to alsa/asoundlib.h)
pl
parents:
5790
diff
changeset
|
30 #error "asoundlib.h is not in sys/ or alsa/ - please bugreport" |
c21948cd027d
fix for latest alsa (sys/asoundlib.h has been moved to alsa/asoundlib.h)
pl
parents:
5790
diff
changeset
|
31 #endif |
1050 | 32 |
33 #include "audio_out.h" | |
34 #include "audio_out_internal.h" | |
1058 | 35 #include "afmt.h" |
1050 | 36 |
37 extern int verbose; | |
38 | |
39 static ao_info_t info = | |
40 { | |
11775 | 41 "ALSA-1.x audio output", |
42 "alsa1x", | |
10366 | 43 "Alex Beregszaszi, Joy Winter <joy@pingfm.org>", |
1050 | 44 "under developement" |
45 }; | |
46 | |
11775 | 47 LIBAO_EXTERN(alsa1x) |
1050 | 48 |
49 | |
50 static snd_pcm_t *alsa_handler; | |
51 static snd_pcm_format_t alsa_format; | |
52 static snd_pcm_hw_params_t *alsa_hwparams; | |
53 static snd_pcm_sw_params_t *alsa_swparams; | |
8036 | 54 static char *alsa_device; |
1050 | 55 |
6749 | 56 /* possible 4096, original 8192 |
57 * was only needed for calculating chunksize? */ | |
58 static int alsa_fragsize = 4096; | |
59 /* 16 sets buffersize to 16 * chunksize is as default 1024 | |
60 * which seems to be good avarge for most situations | |
61 * so buffersize is 16384 frames by default */ | |
62 static int alsa_fragcount = 16; | |
11775 | 63 static snd_pcm_uframes_t chunk_size = 1024; //is alsa_fragsize / 4 |
2209 | 64 |
8874 | 65 #define MIN_CHUNK_SIZE 1024 |
66 | |
7657
dda97c5190d7
fixed ao_data.bps - patch by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7077
diff
changeset
|
67 static size_t bits_per_sample, bytes_per_sample, bits_per_frame; |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
68 static size_t chunk_bytes; |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
69 |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
70 int ao_mmap = 0; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
71 int ao_noblock = 0; |
6749 | 72 int first = 1; |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
73 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
74 static int open_mode; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
75 static int set_block_mode; |
10514
760e12774430
better pause mechanism and faster uninit support by Vladimir I. Umnov <uvi@ezmail.ru>
alex
parents:
10366
diff
changeset
|
76 static int alsa_can_pause = 0; |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
77 |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
78 #define ALSA_DEVICE_SIZE 48 |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
79 |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
80 #undef BUFFERTIME |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
81 #define SET_CHUNKSIZE |
11775 | 82 //#define BUFFERTIME |
83 //#undef SET_CHUNKSIZE | |
6749 | 84 #undef USE_POLL |
1128 | 85 |
6193
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
86 |
1050 | 87 /* to set/get/query special features/parameters */ |
9633
12b1790038b0
64bit libao2 fix by Jens Axboe <mplayer-dev@kernel.dk>
alex
parents:
9587
diff
changeset
|
88 static int control(int cmd, void *arg) |
1050 | 89 { |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
90 switch(cmd) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
91 case AOCONTROL_QUERY_FORMAT: |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
92 return CONTROL_TRUE; |
10659 | 93 #ifndef WORDS_BIGENDIAN |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
94 case AOCONTROL_GET_VOLUME: |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
95 case AOCONTROL_SET_VOLUME: |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
96 { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
97 ao_control_vol_t *vol = (ao_control_vol_t *)arg; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
98 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
99 int err; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
100 snd_mixer_t *handle; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
101 snd_mixer_elem_t *elem; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
102 snd_mixer_selem_id_t *sid; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
103 |
11775 | 104 static char *mix_name = NULL; |
11764 | 105 static char *card = NULL; |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
106 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
107 long pmin, pmax; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
108 long get_vol, set_vol; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
109 float calc_vol, diff, f_multi; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
110 |
11764 | 111 if(mix_name == NULL){ |
112 if(mixer_device) { | |
113 card = strdup(mixer_device); | |
114 mix_name = strchr(card, '/'); | |
115 if(mix_name) { | |
116 *mix_name++ = 0; | |
117 } else { | |
118 mix_name = "PCM"; | |
119 } | |
120 } else { | |
121 mix_name = "PCM"; | |
122 card = "default"; | |
123 } | |
124 } | |
125 | |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
126 if(ao_data.format == AFMT_AC3) |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
127 return CONTROL_TRUE; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
128 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
129 //allocate simple id |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
130 snd_mixer_selem_id_alloca(&sid); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
131 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
132 //sets simple-mixer index and name |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
133 snd_mixer_selem_id_set_index(sid, 0); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
134 snd_mixer_selem_id_set_name(sid, mix_name); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
135 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
136 if ((err = snd_mixer_open(&handle, 0)) < 0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
137 printf("alsa-control: mixer open error: %s\n", snd_strerror(err)); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
138 return CONTROL_ERROR; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
139 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
140 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
141 if ((err = snd_mixer_attach(handle, card)) < 0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
142 printf("alsa-control: mixer attach %s error: %s", card, snd_strerror(err)); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
143 snd_mixer_close(handle); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
144 return CONTROL_ERROR; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
145 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
146 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
147 if ((err = snd_mixer_selem_register(handle, NULL, NULL)) < 0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
148 printf("alsa-control: mixer register error: %s", snd_strerror(err)); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
149 snd_mixer_close(handle); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
150 return CONTROL_ERROR; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
151 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
152 err = snd_mixer_load(handle); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
153 if (err < 0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
154 printf("alsa-control: mixer load error: %s", snd_strerror(err)); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
155 snd_mixer_close(handle); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
156 return CONTROL_ERROR; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
157 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
158 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
159 elem = snd_mixer_find_selem(handle, sid); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
160 if (!elem) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
161 printf("alsa-control: unable to find simple control '%s',%i\n", snd_mixer_selem_id_get_name(sid), snd_mixer_selem_id_get_index(sid)); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
162 snd_mixer_close(handle); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
163 return CONTROL_ERROR; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
164 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
165 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
166 snd_mixer_selem_get_playback_volume_range(elem,&pmin,&pmax); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
167 f_multi = (100 / (float)pmax); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
168 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
169 if (cmd == AOCONTROL_SET_VOLUME) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
170 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
171 diff = (vol->left+vol->right) / 2; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
172 set_vol = rint(diff / f_multi); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
173 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
174 if (set_vol < 0) |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
175 set_vol = 0; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
176 else if (set_vol > pmax) |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
177 set_vol = pmax; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
178 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
179 //setting channels |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
180 if ((err = snd_mixer_selem_set_playback_volume(elem, 0, set_vol)) < 0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
181 printf("alsa-control: error setting left channel, %s",snd_strerror(err)); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
182 return CONTROL_ERROR; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
183 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
184 if ((err = snd_mixer_selem_set_playback_volume(elem, 1, set_vol)) < 0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
185 printf("alsa-control: error setting right channel, %s",snd_strerror(err)); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
186 return CONTROL_ERROR; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
187 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
188 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
189 //printf("diff=%f, set_vol=%i, pmax=%i, mult=%f\n", diff, set_vol, pmax, f_multi); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
190 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
191 else { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
192 snd_mixer_selem_get_playback_volume(elem, 0, &get_vol); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
193 calc_vol = get_vol; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
194 calc_vol = rintf(calc_vol * f_multi); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
195 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
196 vol->left = vol->right = (int)calc_vol; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
197 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
198 //printf("get_vol = %i, calc=%i\n",get_vol, calc_vol); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
199 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
200 snd_mixer_close(handle); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
201 return CONTROL_OK; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
202 } |
7050
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
203 #endif |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
204 |
10659 | 205 } //end switch |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
206 return(CONTROL_UNKNOWN); |
1050 | 207 } |
208 | |
1128 | 209 |
1050 | 210 /* |
211 open & setup audio device | |
212 return: 1=success 0=fail | |
213 */ | |
214 static int init(int rate_hz, int channels, int format, int flags) | |
215 { | |
216 int err; | |
217 int cards = -1; | |
11775 | 218 int dir; |
219 snd_pcm_uframes_t bufsize; | |
1050 | 220 snd_pcm_info_t *alsa_info; |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
221 char *str_block_mode; |
6702 | 222 int device_set = 0; |
10623
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
223 |
1050 | 224 printf("alsa-init: requested format: %d Hz, %d channels, %s\n", rate_hz, |
225 channels, audio_out_format_name(format)); | |
226 | |
227 alsa_handler = NULL; | |
228 | |
8027 | 229 if (verbose>0) |
2059 | 230 printf("alsa-init: compiled for ALSA-%s\n", SND_LIB_VERSION_STR); |
1050 | 231 |
232 if ((err = snd_card_next(&cards)) < 0 || cards < 0) | |
233 { | |
234 printf("alsa-init: no soundcards found: %s\n", snd_strerror(err)); | |
235 return(0); | |
236 } | |
237 | |
3095 | 238 ao_data.samplerate = rate_hz; |
7657
dda97c5190d7
fixed ao_data.bps - patch by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7077
diff
changeset
|
239 ao_data.bps = channels * rate_hz; |
3095 | 240 ao_data.format = format; |
241 ao_data.channels = channels; | |
242 ao_data.outburst = OUTBURST; | |
6749 | 243 //ao_data.buffersize = MAX_OUTBURST; // was 16384 |
1050 | 244 |
245 switch (format) | |
7050
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
246 { |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
247 case AFMT_S8: |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
248 alsa_format = SND_PCM_FORMAT_S8; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
249 break; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
250 case AFMT_U8: |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
251 alsa_format = SND_PCM_FORMAT_U8; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
252 break; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
253 case AFMT_U16_LE: |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
254 alsa_format = SND_PCM_FORMAT_U16_LE; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
255 break; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
256 case AFMT_U16_BE: |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
257 alsa_format = SND_PCM_FORMAT_U16_BE; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
258 break; |
5790 | 259 #ifndef WORDS_BIGENDIAN |
7050
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
260 case AFMT_AC3: |
5790 | 261 #endif |
7050
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
262 case AFMT_S16_LE: |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
263 alsa_format = SND_PCM_FORMAT_S16_LE; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
264 break; |
5790 | 265 #ifdef WORDS_BIGENDIAN |
7050
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
266 case AFMT_AC3: |
5790 | 267 #endif |
7050
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
268 case AFMT_S16_BE: |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
269 alsa_format = SND_PCM_FORMAT_S16_BE; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
270 break; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
271 case AFMT_S32_LE: |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
272 alsa_format = SND_PCM_FORMAT_S32_LE; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
273 break; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
274 case AFMT_S32_BE: |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
275 alsa_format = SND_PCM_FORMAT_S32_BE; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
276 break; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
277 |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
278 default: |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
279 alsa_format = SND_PCM_FORMAT_MPEG; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
280 break; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
281 } |
1050 | 282 |
283 switch(alsa_format) | |
7050
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
284 { |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
285 case SND_PCM_FORMAT_S16_LE: |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
286 case SND_PCM_FORMAT_U16_LE: |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
287 ao_data.bps *= 2; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
288 break; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
289 case SND_PCM_FORMAT_S32_LE: |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
290 case SND_PCM_FORMAT_S32_BE: |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
291 ao_data.bps *= 4; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
292 break; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
293 case -1: |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
294 printf("alsa-init: invalid format (%s) requested - output disabled\n", |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
295 audio_out_format_name(format)); |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
296 return(0); |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
297 default: |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
298 break; |
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
299 } |
7657
dda97c5190d7
fixed ao_data.bps - patch by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7077
diff
changeset
|
300 |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
301 if (ao_subdevice) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
302 //start parsing ao_subdevice, ugly and not thread safe! |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
303 //maybe there's a better way? |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
304 int i2 = 1; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
305 int i3 = 0; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
306 char *sub_str; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
307 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
308 char *token_str[3]; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
309 char* test_str = strdup(ao_subdevice); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
310 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
311 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
312 if ((strcspn(ao_subdevice, ":")) > 0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
313 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
314 sub_str = strtok(test_str, ":"); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
315 *(token_str) = sub_str; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
316 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
317 while (((sub_str = strtok(NULL, ":")) != NULL) && (i2 <= 3)) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
318 *(token_str+i2) = sub_str; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
319 i2 += 1; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
320 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
321 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
322 for (i3=0; i3 <= i2-1; i3++) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
323 if (strcmp(*(token_str + i3), "mmap") == 0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
324 ao_mmap = 1; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
325 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
326 else if (strcmp(*(token_str+i3), "noblock") == 0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
327 ao_noblock = 1; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
328 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
329 else if (strcmp(*(token_str+i3), "hw") == 0) { |
6702 | 330 if ((i3 < i2-1) && (strcmp(*(token_str+i3+1), "noblock") != 0) && (strcmp(*(token_str+i3+1), "mmap") != 0)) { |
10258
d9371eecb619
-ao alsa9:hw:0,0 fix by Wojtek Kaniewski <wojtekka@bydg.pdi.net>
alex
parents:
9633
diff
changeset
|
331 char *tmp; |
d9371eecb619
-ao alsa9:hw:0,0 fix by Wojtek Kaniewski <wojtekka@bydg.pdi.net>
alex
parents:
9633
diff
changeset
|
332 |
6702 | 333 alsa_device = alloca(ALSA_DEVICE_SIZE); |
334 snprintf(alsa_device, ALSA_DEVICE_SIZE, "hw:%s", *(token_str+(i3+1))); | |
10258
d9371eecb619
-ao alsa9:hw:0,0 fix by Wojtek Kaniewski <wojtekka@bydg.pdi.net>
alex
parents:
9633
diff
changeset
|
335 if ((tmp = strrchr(alsa_device, '.')) && isdigit(*(tmp+1))) |
d9371eecb619
-ao alsa9:hw:0,0 fix by Wojtek Kaniewski <wojtekka@bydg.pdi.net>
alex
parents:
9633
diff
changeset
|
336 *tmp = ','; |
6702 | 337 device_set = 1; |
338 } | |
339 else { | |
340 alsa_device = *(token_str+i3); | |
341 device_set = 1; | |
342 } | |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
343 } |
6702 | 344 else if (device_set == 0 && (!ao_mmap || !ao_noblock)) { |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
345 alsa_device = *(token_str+i3); |
6702 | 346 device_set = 1; |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
347 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
348 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
349 } |
10623
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
350 } else { //end parsing ao_subdevice |
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
351 /* in any case for multichannel playback we should select |
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
352 * appropriate device |
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
353 */ |
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
354 char devstr[128]; |
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
355 |
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
356 switch (channels) { |
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
357 case 4: |
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
358 strcpy(devstr, "surround40"); |
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
359 alsa_device = devstr; |
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
360 break; |
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
361 case 6: |
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
362 strcpy(devstr, "surround51"); |
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
363 alsa_device = devstr; |
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
364 break; |
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
365 default: |
11775 | 366 break; |
10623
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
367 } |
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
368 } |
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
369 |
1207 | 370 |
7077 | 371 /* switch for spdif |
372 * sets opening sequence for SPDIF | |
373 * sets also the playback and other switches 'on the fly' | |
374 * while opening the abstract alias for the spdif subdevice | |
375 * 'iec958' | |
376 */ | |
377 if (format == AFMT_AC3) { | |
378 char devstr[128]; | |
379 unsigned char s[4]; | |
380 int err, c; | |
381 | |
382 switch (channels) { | |
383 case 1: | |
384 case 2: | |
385 | |
386 s[0] = IEC958_AES0_NONAUDIO | | |
387 IEC958_AES0_CON_EMPHASIS_NONE; | |
388 s[1] = IEC958_AES1_CON_ORIGINAL | | |
389 IEC958_AES1_CON_PCM_CODER; | |
390 s[2] = 0; | |
391 s[3] = IEC958_AES3_CON_FS_48000; | |
392 | |
393 sprintf(devstr, "iec958:AES0=0x%x,AES1=0x%x,AES2=0x%x,AES3=0x%x", | |
394 s[0], s[1], s[2], s[3]); | |
395 | |
8027 | 396 if (verbose>0) |
7077 | 397 printf("alsa-spdif-init: playing AC3, %i channels\n", channels); |
398 break; | |
399 case 4: | |
400 strcpy(devstr, "surround40"); | |
401 break; | |
402 | |
403 case 6: | |
404 strcpy(devstr, "surround51"); | |
405 break; | |
406 | |
407 default: | |
408 fprintf(stderr, "%d channels are not supported\n", channels); | |
10659 | 409 return(0); |
7077 | 410 } |
411 | |
412 alsa_device = devstr; | |
413 } | |
414 | |
1146
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
415 if (alsa_device == NULL) |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
416 { |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
417 int tmp_device, tmp_subdevice, err; |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
418 |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
419 if ((err = snd_pcm_info_malloc(&alsa_info)) < 0) |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
420 { |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
421 printf("alsa-init: memory allocation error: %s\n", snd_strerror(err)); |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
422 return(0); |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
423 } |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
424 |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
425 if ((alsa_device = alloca(ALSA_DEVICE_SIZE)) == NULL) |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
426 { |
1146
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
427 printf("alsa-init: memory allocation error: %s\n", strerror(errno)); |
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
428 return(0); |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
429 } |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
430 |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
431 if ((tmp_device = snd_pcm_info_get_device(alsa_info)) < 0) |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
432 { |
11000 | 433 printf("alsa-init: can't get device\n"); |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
434 return(0); |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
435 } |
1050 | 436 |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
437 if ((tmp_subdevice = snd_pcm_info_get_subdevice(alsa_info)) < 0) |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
438 { |
11000 | 439 printf("alsa-init: can't get subdevice\n"); |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
440 return(0); |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
441 } |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
442 |
8027 | 443 if (verbose>0) |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
444 printf("alsa-init: got device=%i, subdevice=%i\n", tmp_device, tmp_subdevice); |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
445 |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
446 if ((err = snprintf(alsa_device, ALSA_DEVICE_SIZE, "hw:%1d,%1d", tmp_device, tmp_subdevice)) <= 0) |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
447 { |
11000 | 448 printf("alsa-init: can't write device-id\n"); |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
449 } |
1050 | 450 |
1146
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
451 snd_pcm_info_free(alsa_info); |
6702 | 452 printf("alsa-init: %d soundcard%s found, using: %s\n", cards+1, |
453 (cards >= 0) ? "" : "s", alsa_device); | |
454 } else if (strcmp(alsa_device, "help") == 0) { | |
455 printf("alsa-help: available options are:\n"); | |
456 printf(" mmap: sets mmap-mode\n"); | |
457 printf(" noblock: sets noblock-mode\n"); | |
10258
d9371eecb619
-ao alsa9:hw:0,0 fix by Wojtek Kaniewski <wojtekka@bydg.pdi.net>
alex
parents:
9633
diff
changeset
|
458 printf(" device-name: sets device name (change comma to point)\n"); |
11775 | 459 printf(" example -ao alsa1x:mmap:noblock:hw:0.3 sets noblock-mode,\n"); |
10258
d9371eecb619
-ao alsa9:hw:0,0 fix by Wojtek Kaniewski <wojtekka@bydg.pdi.net>
alex
parents:
9633
diff
changeset
|
460 printf(" mmap-mode and the device-name as first card fourth device\n"); |
6702 | 461 return(0); |
462 } else { | |
463 printf("alsa-init: soundcard set to %s\n", alsa_device); | |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
464 } |
1050 | 465 |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
466 //setting modes for block or nonblock-mode |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
467 if (ao_noblock) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
468 open_mode = SND_PCM_NONBLOCK; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
469 set_block_mode = 1; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
470 str_block_mode = "nonblock-mode"; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
471 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
472 else { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
473 open_mode = 0; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
474 set_block_mode = 0; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
475 str_block_mode = "block-mode"; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
476 } |
7050
a5b2b377ab50
changed spdif default from "hw:0,2" to general alias "iec958"
joyping
parents:
6749
diff
changeset
|
477 |
6749 | 478 //sets buff/chunksize if its set manually |
479 if (ao_data.buffersize) { | |
480 switch (ao_data.buffersize) | |
481 { | |
482 case 1: | |
483 alsa_fragcount = 16; | |
484 chunk_size = 512; | |
8027 | 485 if (verbose>0) { |
6749 | 486 printf("alsa-init: buffersize set manually to 8192\n"); |
487 printf("alsa-init: chunksize set manually to 512\n"); | |
488 } | |
489 break; | |
490 case 2: | |
491 alsa_fragcount = 8; | |
492 chunk_size = 1024; | |
8027 | 493 if (verbose>0) { |
6749 | 494 printf("alsa-init: buffersize set manually to 8192\n"); |
495 printf("alsa-init: chunksize set manually to 1024\n"); | |
496 } | |
497 break; | |
498 case 3: | |
499 alsa_fragcount = 32; | |
500 chunk_size = 512; | |
8027 | 501 if (verbose>0) { |
6749 | 502 printf("alsa-init: buffersize set manually to 16384\n"); |
503 printf("alsa-init: chunksize set manually to 512\n"); | |
504 } | |
505 break; | |
506 case 4: | |
507 alsa_fragcount = 16; | |
508 chunk_size = 1024; | |
8027 | 509 if (verbose>0) { |
6749 | 510 printf("alsa-init: buffersize set manually to 16384\n"); |
511 printf("alsa-init: chunksize set manually to 1024\n"); | |
512 } | |
513 break; | |
514 default: | |
515 alsa_fragcount = 16; | |
516 if (ao_mmap) | |
517 chunk_size = 512; | |
518 else | |
519 chunk_size = 1024; | |
520 break; | |
521 } | |
522 } | |
523 | |
6193
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
524 if (!alsa_handler) { |
6702 | 525 //modes = 0, SND_PCM_NONBLOCK, SND_PCM_ASYNC |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
526 if ((err = snd_pcm_open(&alsa_handler, alsa_device, SND_PCM_STREAM_PLAYBACK, open_mode)) < 0) |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
527 { |
10898 | 528 if (err != -EBUSY && ao_noblock) { |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
529 printf("alsa-init: open in nonblock-mode failed, trying to open in block-mode\n"); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
530 if ((err = snd_pcm_open(&alsa_handler, alsa_device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
531 printf("alsa-init: playback open error: %s\n", snd_strerror(err)); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
532 return(0); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
533 } else { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
534 set_block_mode = 0; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
535 str_block_mode = "block-mode"; |
6193
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
536 } |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
537 } else { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
538 printf("alsa-init: playback open error: %s\n", snd_strerror(err)); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
539 return(0); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
540 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
541 } |
1050 | 542 |
6702 | 543 if ((err = snd_pcm_nonblock(alsa_handler, set_block_mode)) < 0) { |
544 printf("alsa-init: error set block-mode %s\n", snd_strerror(err)); | |
545 } | |
8027 | 546 else if (verbose>0) { |
11775 | 547 printf("alsa-init: pcm opened in %s\n", str_block_mode); |
6702 | 548 } |
549 | |
550 snd_pcm_hw_params_alloca(&alsa_hwparams); | |
551 snd_pcm_sw_params_alloca(&alsa_swparams); | |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
552 |
6702 | 553 // setting hw-parameters |
554 if ((err = snd_pcm_hw_params_any(alsa_handler, alsa_hwparams)) < 0) | |
555 { | |
556 printf("alsa-init: unable to get initial parameters: %s\n", | |
557 snd_strerror(err)); | |
558 return(0); | |
559 } | |
1050 | 560 |
6702 | 561 if (ao_mmap) { |
562 snd_pcm_access_mask_t *mask = alloca(snd_pcm_access_mask_sizeof()); | |
563 snd_pcm_access_mask_none(mask); | |
564 snd_pcm_access_mask_set(mask, SND_PCM_ACCESS_MMAP_INTERLEAVED); | |
565 snd_pcm_access_mask_set(mask, SND_PCM_ACCESS_MMAP_NONINTERLEAVED); | |
566 snd_pcm_access_mask_set(mask, SND_PCM_ACCESS_MMAP_COMPLEX); | |
567 err = snd_pcm_hw_params_set_access_mask(alsa_handler, alsa_hwparams, mask); | |
568 printf("alsa-init: mmap set\n"); | |
569 } else { | |
570 err = snd_pcm_hw_params_set_access(alsa_handler, alsa_hwparams,SND_PCM_ACCESS_RW_INTERLEAVED); | |
571 } | |
572 if (err < 0) { | |
573 printf("alsa-init: unable to set access type: %s\n", snd_strerror(err)); | |
574 return (0); | |
575 } | |
10623
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
576 |
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
577 /* workaround for nonsupported formats |
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
578 sets default format to S16_LE if the given formats aren't supported */ |
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
579 if ((err = snd_pcm_hw_params_test_format(alsa_handler, alsa_hwparams, |
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
580 alsa_format)) < 0) |
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
581 { |
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
582 printf("alsa-init: format %s are not supported by hardware, trying default\n", |
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
583 audio_out_format_name(format)); |
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
584 alsa_format = SND_PCM_FORMAT_S16_LE; |
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
585 ao_data.format = AFMT_S16_LE; |
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
586 ao_data.bps = channels * rate_hz * 2; |
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
587 } |
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
588 |
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
589 bytes_per_sample = ao_data.bps / ao_data.samplerate; //it should be here |
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
590 |
1050 | 591 |
6702 | 592 if ((err = snd_pcm_hw_params_set_format(alsa_handler, alsa_hwparams, |
593 alsa_format)) < 0) | |
594 { | |
595 printf("alsa-init: unable to set format: %s\n", | |
596 snd_strerror(err)); | |
597 return(0); | |
598 } | |
1050 | 599 |
6702 | 600 if ((err = snd_pcm_hw_params_set_channels(alsa_handler, alsa_hwparams, |
601 ao_data.channels)) < 0) | |
602 { | |
603 printf("alsa-init: unable to set channels: %s\n", | |
604 snd_strerror(err)); | |
605 return(0); | |
606 } | |
1050 | 607 |
11775 | 608 dir = 0; |
609 if ((err = snd_pcm_hw_params_set_rate_near(alsa_handler, alsa_hwparams, &ao_data.samplerate, &dir)) < 0) | |
2059 | 610 { |
6702 | 611 printf("alsa-init: unable to set samplerate-2: %s\n", |
612 snd_strerror(err)); | |
613 return(0); | |
2059 | 614 } |
1050 | 615 |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
616 #ifdef BUFFERTIME |
6702 | 617 { |
618 int alsa_buffer_time = 500000; /* original 60 */ | |
11775 | 619 int alsa_period_time; |
1050 | 620 |
11775 | 621 dir = 0; |
622 if ((err = snd_pcm_hw_params_set_buffer_time_near(alsa_handler, alsa_hwparams, &alsa_buffer_time, &dir)) < 0) | |
6702 | 623 { |
1050 | 624 printf("alsa-init: unable to set buffer time near: %s\n", |
6702 | 625 snd_strerror(err)); |
1050 | 626 return(0); |
11775 | 627 } |
1050 | 628 |
11775 | 629 alsa_period_time = alsa_buffer_time/4; ; |
630 | |
631 dir = 0; | |
12002 | 632 if ((err = snd_pcm_hw_params_set_period_time_near(alsa_handler, alsa_hwparams, &alsa_period_time, &dir)) < 0) |
3095 | 633 /* original: alsa_buffer_time/ao_data.bps */ |
6702 | 634 { |
1050 | 635 printf("alsa-init: unable to set period time: %s\n", |
6702 | 636 snd_strerror(err)); |
1050 | 637 return(0); |
6702 | 638 } |
8027 | 639 if (verbose>0) |
11775 | 640 printf("alsa-init: buffer_time: %d, period_time :%d\n",alsa_buffer_time, alsa_period_time); |
6702 | 641 } |
1050 | 642 #endif |
643 | |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
644 #ifdef SET_CHUNKSIZE |
6702 | 645 { |
646 //set chunksize | |
11775 | 647 dir = 0; |
648 if ((err = snd_pcm_hw_params_set_period_size_near(alsa_handler, alsa_hwparams, &chunk_size, &dir)) < 0) | |
6702 | 649 { |
650 printf("alsa-init: unable to set periodsize: %s\n", snd_strerror(err)); | |
651 return(0); | |
652 } | |
8027 | 653 else if (verbose>0) { |
6702 | 654 printf("alsa-init: chunksize set to %i\n", chunk_size); |
655 } | |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
656 |
11775 | 657 dir = 0; |
658 if ((err = snd_pcm_hw_params_set_periods_near(alsa_handler, alsa_hwparams, &alsa_fragcount, &dir)) < 0) { | |
659 printf("alsa-init: unable to set periods: %s\n", snd_strerror(err)); | |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
660 } |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
661 |
8027 | 662 if (verbose>0) |
11775 | 663 printf("alsa-init: fragcount=%i\n", alsa_fragcount); |
6702 | 664 } |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
665 #endif |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
666 |
6702 | 667 /* finally install hardware parameters */ |
668 if ((err = snd_pcm_hw_params(alsa_handler, alsa_hwparams)) < 0) | |
669 { | |
670 printf("alsa-init: unable to set hw-parameters: %s\n", | |
671 snd_strerror(err)); | |
672 return(0); | |
673 } | |
674 // end setting hw-params | |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
675 |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
676 |
6702 | 677 // gets buffersize for control |
11775 | 678 if ((err = snd_pcm_hw_params_get_buffer_size(alsa_hwparams, &bufsize)) < 0) |
6702 | 679 { |
680 printf("alsa-init: unable to get buffersize: %s\n", snd_strerror(err)); | |
681 return(0); | |
682 } | |
683 else { | |
11775 | 684 ao_data.buffersize = bufsize * bytes_per_sample; |
8027 | 685 if (verbose>0) |
6702 | 686 printf("alsa-init: got buffersize=%i\n", ao_data.buffersize); |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
687 } |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
688 |
6702 | 689 // setting sw-params (only avail-min) if noblocking mode was choosed |
690 if (ao_noblock) | |
691 { | |
1050 | 692 |
6702 | 693 if ((err = snd_pcm_sw_params_current(alsa_handler, alsa_swparams)) < 0) |
694 { | |
695 printf("alsa-init: unable to get parameters: %s\n",snd_strerror(err)); | |
696 return(0); | |
697 } | |
698 | |
699 //set min available frames to consider pcm ready (4) | |
700 //increased for nonblock-mode should be set dynamically later | |
6749 | 701 if ((err = snd_pcm_sw_params_set_avail_min(alsa_handler, alsa_swparams, 4)) < 0) |
6702 | 702 { |
703 printf("alsa-init: unable to set avail_min %s\n",snd_strerror(err)); | |
704 return(0); | |
705 } | |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
706 |
6702 | 707 if ((err = snd_pcm_sw_params(alsa_handler, alsa_swparams)) < 0) |
708 { | |
709 printf("alsa-init: unable to install sw-params\n"); | |
710 return(0); | |
711 } | |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
712 |
6702 | 713 bits_per_sample = snd_pcm_format_physical_width(alsa_format); |
714 bits_per_frame = bits_per_sample * channels; | |
715 chunk_bytes = chunk_size * bits_per_frame / 8; | |
1050 | 716 |
8027 | 717 if (verbose>0) { |
6702 | 718 printf("alsa-init: bits per sample (bps)=%i, bits per frame (bpf)=%i, chunk_bytes=%i\n",bits_per_sample,bits_per_frame,chunk_bytes);} |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
719 |
6702 | 720 }//end swparams |
1050 | 721 |
6702 | 722 if ((err = snd_pcm_prepare(alsa_handler)) < 0) |
723 { | |
724 printf("alsa-init: pcm prepare error: %s\n", snd_strerror(err)); | |
725 return(0); | |
726 } | |
727 | |
11775 | 728 printf("alsa1x: %d Hz/%d channels/%d bpf/%d bytes buffer/%s\n", |
7657
dda97c5190d7
fixed ao_data.bps - patch by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7077
diff
changeset
|
729 ao_data.samplerate, ao_data.channels, bytes_per_sample, ao_data.buffersize, |
6702 | 730 snd_pcm_format_description(alsa_format)); |
731 | |
732 } // end switch alsa_handler (spdif) | |
10514
760e12774430
better pause mechanism and faster uninit support by Vladimir I. Umnov <uvi@ezmail.ru>
alex
parents:
10366
diff
changeset
|
733 alsa_can_pause = snd_pcm_hw_params_can_pause(alsa_hwparams); |
1050 | 734 return(1); |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
735 } // end init |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
736 |
1050 | 737 |
738 /* close audio device */ | |
12145 | 739 static void uninit(int immed) |
1050 | 740 { |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
741 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
742 if (alsa_handler) { |
1050 | 743 int err; |
744 | |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
745 if (!ao_noblock) { |
10514
760e12774430
better pause mechanism and faster uninit support by Vladimir I. Umnov <uvi@ezmail.ru>
alex
parents:
10366
diff
changeset
|
746 if ((err = snd_pcm_drop(alsa_handler)) < 0) |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
747 { |
10514
760e12774430
better pause mechanism and faster uninit support by Vladimir I. Umnov <uvi@ezmail.ru>
alex
parents:
10366
diff
changeset
|
748 printf("alsa-uninit: pcm drop error: %s\n", snd_strerror(err)); |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
749 return; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
750 } |
1050 | 751 } |
752 | |
753 if ((err = snd_pcm_close(alsa_handler)) < 0) | |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
754 { |
1050 | 755 printf("alsa-uninit: pcm close error: %s\n", snd_strerror(err)); |
756 return; | |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
757 } |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
758 else { |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
759 alsa_handler = NULL; |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
760 alsa_device = NULL; |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
761 printf("alsa-uninit: pcm closed\n"); |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
762 } |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
763 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
764 else { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
765 printf("alsa-uninit: no handler defined!\n"); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
766 } |
1050 | 767 } |
768 | |
769 static void audio_pause() | |
770 { | |
771 int err; | |
772 | |
10514
760e12774430
better pause mechanism and faster uninit support by Vladimir I. Umnov <uvi@ezmail.ru>
alex
parents:
10366
diff
changeset
|
773 if (alsa_can_pause) { |
760e12774430
better pause mechanism and faster uninit support by Vladimir I. Umnov <uvi@ezmail.ru>
alex
parents:
10366
diff
changeset
|
774 if ((err = snd_pcm_pause(alsa_handler, 1)) < 0) |
760e12774430
better pause mechanism and faster uninit support by Vladimir I. Umnov <uvi@ezmail.ru>
alex
parents:
10366
diff
changeset
|
775 { |
760e12774430
better pause mechanism and faster uninit support by Vladimir I. Umnov <uvi@ezmail.ru>
alex
parents:
10366
diff
changeset
|
776 printf("alsa-pause: pcm pause error: %s\n", snd_strerror(err)); |
760e12774430
better pause mechanism and faster uninit support by Vladimir I. Umnov <uvi@ezmail.ru>
alex
parents:
10366
diff
changeset
|
777 return; |
760e12774430
better pause mechanism and faster uninit support by Vladimir I. Umnov <uvi@ezmail.ru>
alex
parents:
10366
diff
changeset
|
778 } |
760e12774430
better pause mechanism and faster uninit support by Vladimir I. Umnov <uvi@ezmail.ru>
alex
parents:
10366
diff
changeset
|
779 if (verbose) |
760e12774430
better pause mechanism and faster uninit support by Vladimir I. Umnov <uvi@ezmail.ru>
alex
parents:
10366
diff
changeset
|
780 printf("alsa-pause: pause supported by hardware\n"); |
760e12774430
better pause mechanism and faster uninit support by Vladimir I. Umnov <uvi@ezmail.ru>
alex
parents:
10366
diff
changeset
|
781 } else { |
760e12774430
better pause mechanism and faster uninit support by Vladimir I. Umnov <uvi@ezmail.ru>
alex
parents:
10366
diff
changeset
|
782 if ((err = snd_pcm_drop(alsa_handler)) < 0) |
760e12774430
better pause mechanism and faster uninit support by Vladimir I. Umnov <uvi@ezmail.ru>
alex
parents:
10366
diff
changeset
|
783 { |
760e12774430
better pause mechanism and faster uninit support by Vladimir I. Umnov <uvi@ezmail.ru>
alex
parents:
10366
diff
changeset
|
784 printf("alsa-pause: pcm drop error: %s\n", snd_strerror(err)); |
760e12774430
better pause mechanism and faster uninit support by Vladimir I. Umnov <uvi@ezmail.ru>
alex
parents:
10366
diff
changeset
|
785 return; |
760e12774430
better pause mechanism and faster uninit support by Vladimir I. Umnov <uvi@ezmail.ru>
alex
parents:
10366
diff
changeset
|
786 } |
1050 | 787 } |
788 } | |
789 | |
790 static void audio_resume() | |
791 { | |
792 int err; | |
793 | |
10514
760e12774430
better pause mechanism and faster uninit support by Vladimir I. Umnov <uvi@ezmail.ru>
alex
parents:
10366
diff
changeset
|
794 if (alsa_can_pause) { |
760e12774430
better pause mechanism and faster uninit support by Vladimir I. Umnov <uvi@ezmail.ru>
alex
parents:
10366
diff
changeset
|
795 if ((err = snd_pcm_pause(alsa_handler, 0)) < 0) |
760e12774430
better pause mechanism and faster uninit support by Vladimir I. Umnov <uvi@ezmail.ru>
alex
parents:
10366
diff
changeset
|
796 { |
760e12774430
better pause mechanism and faster uninit support by Vladimir I. Umnov <uvi@ezmail.ru>
alex
parents:
10366
diff
changeset
|
797 printf("alsa-resume: pcm resume error: %s\n", snd_strerror(err)); |
760e12774430
better pause mechanism and faster uninit support by Vladimir I. Umnov <uvi@ezmail.ru>
alex
parents:
10366
diff
changeset
|
798 return; |
760e12774430
better pause mechanism and faster uninit support by Vladimir I. Umnov <uvi@ezmail.ru>
alex
parents:
10366
diff
changeset
|
799 } |
760e12774430
better pause mechanism and faster uninit support by Vladimir I. Umnov <uvi@ezmail.ru>
alex
parents:
10366
diff
changeset
|
800 if (verbose) |
760e12774430
better pause mechanism and faster uninit support by Vladimir I. Umnov <uvi@ezmail.ru>
alex
parents:
10366
diff
changeset
|
801 printf("alsa-resume: resume supported by hardware\n"); |
760e12774430
better pause mechanism and faster uninit support by Vladimir I. Umnov <uvi@ezmail.ru>
alex
parents:
10366
diff
changeset
|
802 } else { |
760e12774430
better pause mechanism and faster uninit support by Vladimir I. Umnov <uvi@ezmail.ru>
alex
parents:
10366
diff
changeset
|
803 if ((err = snd_pcm_prepare(alsa_handler)) < 0) |
760e12774430
better pause mechanism and faster uninit support by Vladimir I. Umnov <uvi@ezmail.ru>
alex
parents:
10366
diff
changeset
|
804 { |
760e12774430
better pause mechanism and faster uninit support by Vladimir I. Umnov <uvi@ezmail.ru>
alex
parents:
10366
diff
changeset
|
805 printf("alsa-resume: pcm prepare error: %s\n", snd_strerror(err)); |
760e12774430
better pause mechanism and faster uninit support by Vladimir I. Umnov <uvi@ezmail.ru>
alex
parents:
10366
diff
changeset
|
806 return; |
760e12774430
better pause mechanism and faster uninit support by Vladimir I. Umnov <uvi@ezmail.ru>
alex
parents:
10366
diff
changeset
|
807 } |
1050 | 808 } |
809 } | |
810 | |
811 /* stop playing and empty buffers (for seeking/pause) */ | |
812 static void reset() | |
813 { | |
814 int err; | |
815 | |
9587 | 816 if ((err = snd_pcm_drop(alsa_handler)) < 0) |
817 { | |
818 printf("alsa-reset: pcm drop error: %s\n", snd_strerror(err)); | |
819 return; | |
1050 | 820 } |
9587 | 821 if ((err = snd_pcm_prepare(alsa_handler)) < 0) |
822 { | |
823 printf("alsa-reset: pcm prepare error: %s\n", snd_strerror(err)); | |
824 return; | |
825 } | |
826 return; | |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
827 } |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
828 |
6749 | 829 #ifdef USE_POLL |
830 static int wait_for_poll(snd_pcm_t *handle, struct pollfd *ufds, unsigned int count) | |
831 { | |
832 unsigned short revents; | |
833 | |
834 while (1) { | |
835 poll(ufds, count, -1); | |
836 snd_pcm_poll_descriptors_revents(handle, ufds, count, &revents); | |
837 if (revents & POLLERR) | |
838 return -EIO; | |
839 if (revents & POLLOUT) | |
840 return 0; | |
841 } | |
842 } | |
843 #endif | |
844 | |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
845 #ifndef timersub |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
846 #define timersub(a, b, result) \ |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
847 do { \ |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
848 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
849 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
850 if ((result)->tv_usec < 0) { \ |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
851 --(result)->tv_sec; \ |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
852 (result)->tv_usec += 1000000; \ |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
853 } \ |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
854 } while (0) |
1129 | 855 #endif |
1050 | 856 |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
857 /* I/O error handler */ |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
858 static int xrun(u_char *str_mode) |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
859 { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
860 int err; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
861 snd_pcm_status_t *status; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
862 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
863 snd_pcm_status_alloca(&status); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
864 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
865 if ((err = snd_pcm_status(alsa_handler, status))<0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
866 printf("status error: %s", snd_strerror(err)); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
867 return(0); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
868 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
869 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
870 if (snd_pcm_status_get_state(status) == SND_PCM_STATE_XRUN) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
871 struct timeval now, diff, tstamp; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
872 gettimeofday(&now, 0); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
873 snd_pcm_status_get_trigger_tstamp(status, &tstamp); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
874 timersub(&now, &tstamp, &diff); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
875 printf("alsa-%s: xrun of at least %.3f msecs. resetting stream\n", |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
876 str_mode, |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
877 diff.tv_sec * 1000 + diff.tv_usec / 1000.0); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
878 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
879 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
880 if ((err = snd_pcm_prepare(alsa_handler))<0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
881 printf("xrun: prepare error: %s", snd_strerror(err)); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
882 return(0); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
883 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
884 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
885 return(1); /* ok, data should be accepted again */ |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
886 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
887 |
8036 | 888 static int play_normal(void* data, int len); |
889 static int play_mmap(void* data, int len); | |
890 | |
6749 | 891 static int play(void* data, int len, int flags) |
892 { | |
893 int result; | |
894 if (ao_mmap) | |
895 result = play_mmap(data, len); | |
896 else | |
897 result = play_normal(data, len); | |
898 | |
899 return result; | |
900 } | |
901 | |
1050 | 902 /* |
903 plays 'len' bytes of 'data' | |
904 returns: number of bytes played | |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
905 modified last at 29.06.02 by jp |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
906 thanxs for marius <marius@rospot.com> for giving us the light ;) |
1050 | 907 */ |
6193
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
908 |
6749 | 909 static int play_normal(void* data, int len) |
1050 | 910 { |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
911 |
7657
dda97c5190d7
fixed ao_data.bps - patch by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7077
diff
changeset
|
912 //bytes_per_sample is always 4 for 2 chn S16_LE |
dda97c5190d7
fixed ao_data.bps - patch by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7077
diff
changeset
|
913 int num_frames = len / bytes_per_sample; |
8346
368019e0153a
The enclosed patch should fix problems associated with playing 8-bit wide
arpi
parents:
8036
diff
changeset
|
914 char *output_samples = (char *)data; |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
915 snd_pcm_sframes_t res = 0; |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
916 |
8346
368019e0153a
The enclosed patch should fix problems associated with playing 8-bit wide
arpi
parents:
8036
diff
changeset
|
917 //fprintf(stderr,"alsa-play: frames=%i, len=%i\n",num_frames,len); |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
918 |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
919 if (!alsa_handler) { |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
920 printf("alsa-play: device configuration error"); |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
921 return 0; |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
922 } |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
923 |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
924 while (num_frames > 0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
925 |
6749 | 926 res = snd_pcm_writei(alsa_handler, (void *)output_samples, num_frames); |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
927 |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
928 if (res == -EAGAIN) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
929 snd_pcm_wait(alsa_handler, 1000); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
930 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
931 else if (res == -EPIPE) { /* underrun */ |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
932 if (xrun("play") <= 0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
933 printf("alsa-play: xrun reset error"); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
934 return(0); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
935 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
936 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
937 else if (res == -ESTRPIPE) { /* suspend */ |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
938 printf("alsa-play: pcm in suspend mode. trying to resume\n"); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
939 while ((res = snd_pcm_resume(alsa_handler)) == -EAGAIN) |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
940 sleep(1); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
941 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
942 else if (res < 0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
943 printf("alsa-play: unknown status, trying to reset soundcard\n"); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
944 if ((res = snd_pcm_prepare(alsa_handler)) < 0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
945 printf("alsa-play: snd prepare error"); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
946 return(0); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
947 break; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
948 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
949 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
950 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
951 if (res > 0) { |
8346
368019e0153a
The enclosed patch should fix problems associated with playing 8-bit wide
arpi
parents:
8036
diff
changeset
|
952 |
368019e0153a
The enclosed patch should fix problems associated with playing 8-bit wide
arpi
parents:
8036
diff
changeset
|
953 /* output_samples += ao_data.channels * res; */ |
368019e0153a
The enclosed patch should fix problems associated with playing 8-bit wide
arpi
parents:
8036
diff
changeset
|
954 output_samples += res * bytes_per_sample; |
368019e0153a
The enclosed patch should fix problems associated with playing 8-bit wide
arpi
parents:
8036
diff
changeset
|
955 |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
956 num_frames -= res; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
957 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
958 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
959 } //end while |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
960 |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
961 if (res < 0) { |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
962 printf("alsa-play: write error %s", snd_strerror(res)); |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
963 return 0; |
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
964 } |
10623
abdb28a904c8
no channels moving, autosubdievice, nonsupported fix by Vladimir I. Umnov <uvi@ezmail.ru>, removed braindeaded startup message
joyping
parents:
10605
diff
changeset
|
965 return res < 0 ? (int)res : len - len % bytes_per_sample; |
1050 | 966 } |
967 | |
6749 | 968 /* mmap-mode mainly based on descriptions by Joshua Haberman <joshua@haberman.com> |
969 * 'An overview of the ALSA API' http://people.debian.org/~joshua/x66.html | |
970 * and some help by Paul Davis <pbd@op.net> */ | |
971 | |
972 static int play_mmap(void* data, int len) | |
973 { | |
974 snd_pcm_sframes_t commitres, frames_available; | |
975 snd_pcm_uframes_t frames_transmit, size, offset; | |
976 const snd_pcm_channel_area_t *area; | |
977 void *outbuffer; | |
978 int err, result; | |
979 | |
980 #ifdef USE_POLL //seems not really be needed | |
981 struct pollfd *ufds; | |
982 int count; | |
983 | |
984 count = snd_pcm_poll_descriptors_count (alsa_handler); | |
985 ufds = malloc(sizeof(struct pollfd) * count); | |
986 snd_pcm_poll_descriptors(alsa_handler, ufds, count); | |
987 | |
988 //first wait_for_poll | |
989 if (err = (wait_for_poll(alsa_handler, ufds, count) < 0)) { | |
990 if (snd_pcm_state(alsa_handler) == SND_PCM_STATE_XRUN || | |
991 snd_pcm_state(alsa_handler) == SND_PCM_STATE_SUSPENDED) { | |
992 xrun("play"); | |
993 } | |
994 } | |
995 #endif | |
996 | |
997 outbuffer = alloca(ao_data.buffersize); | |
998 | |
999 //don't trust get_space() ;) | |
7657
dda97c5190d7
fixed ao_data.bps - patch by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7077
diff
changeset
|
1000 frames_available = snd_pcm_avail_update(alsa_handler) * bytes_per_sample; |
6749 | 1001 if (frames_available < 0) |
1002 xrun("play"); | |
1003 | |
1004 if (frames_available < 4) { | |
1005 if (first) { | |
1006 first = 0; | |
1007 snd_pcm_start(alsa_handler); | |
1008 } | |
1009 else { //FIXME should break and return 0? | |
1010 snd_pcm_wait(alsa_handler, -1); | |
1011 first = 1; | |
1012 } | |
1013 } | |
1014 | |
1015 /* len is simply the available bufferspace got by get_space() | |
7657
dda97c5190d7
fixed ao_data.bps - patch by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7077
diff
changeset
|
1016 * but real avail_buffer in frames is ab/bytes_per_sample */ |
dda97c5190d7
fixed ao_data.bps - patch by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7077
diff
changeset
|
1017 size = len / bytes_per_sample; |
6749 | 1018 |
1019 //if (verbose) | |
7657
dda97c5190d7
fixed ao_data.bps - patch by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7077
diff
changeset
|
1020 //printf("len: %i size %i, f_avail %i, bps %i ...\n", len, size, frames_available, bytes_per_sample); |
6749 | 1021 |
1022 frames_transmit = size; | |
1023 | |
1024 /* prepare areas and set sw-pointers | |
1025 * frames_transmit returns the real available buffer-size | |
1026 * sometimes != frames_available cause of ringbuffer 'emulation' */ | |
1027 snd_pcm_mmap_begin(alsa_handler, &area, &offset, &frames_transmit); | |
1028 | |
1029 /* this is specific to interleaved streams (or non-interleaved | |
1030 * streams with only one channel) */ | |
1031 outbuffer = ((char *) area->addr + (area->first + area->step * offset) / 8); //8 | |
1032 | |
1033 //write data | |
7657
dda97c5190d7
fixed ao_data.bps - patch by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7077
diff
changeset
|
1034 memcpy(outbuffer, data, (frames_transmit * bytes_per_sample)); |
6749 | 1035 |
1036 commitres = snd_pcm_mmap_commit(alsa_handler, offset, frames_transmit); | |
1037 | |
1038 if (commitres < 0 || commitres != frames_transmit) { | |
1039 if (snd_pcm_state(alsa_handler) == SND_PCM_STATE_XRUN || | |
1040 snd_pcm_state(alsa_handler) == SND_PCM_STATE_SUSPENDED) { | |
1041 xrun("play"); | |
1042 } | |
1043 } | |
1044 | |
1045 //if (verbose) | |
1046 //printf("mmap ft: %i, cres: %i\n", frames_transmit, commitres); | |
1047 | |
1048 /* err = snd_pcm_area_copy(&area, offset, &data, offset, len, alsa_format); */ | |
1049 /* if (err < 0) { */ | |
1050 /* printf("area-copy-error\n"); */ | |
1051 /* return 0; */ | |
1052 /* } */ | |
1053 | |
1054 | |
1055 //calculate written frames! | |
7657
dda97c5190d7
fixed ao_data.bps - patch by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7077
diff
changeset
|
1056 result = commitres * bytes_per_sample; |
6749 | 1057 |
1058 | |
1059 /* if (verbose) { */ | |
1060 /* if (len == result) */ | |
1061 /* printf("result: %i, frames written: %i ...\n", result, frames_transmit); */ | |
1062 /* else */ | |
1063 /* printf("result: %i, frames written: %i, result != len ...\n", result, frames_transmit); */ | |
1064 /* } */ | |
1065 | |
1066 //mplayer doesn't like -result | |
1067 if (result < 0) | |
1068 result = 0; | |
1069 | |
1070 #ifdef USE_POLL | |
1071 free(ufds); | |
1072 #endif | |
1073 | |
1074 return result; | |
1075 } | |
1076 | |
1050 | 1077 /* how many byes are free in the buffer */ |
1078 static int get_space() | |
1079 { | |
1080 snd_pcm_status_t *status; | |
1081 int ret; | |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1082 char *str_status; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1083 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1084 //snd_pcm_sframes_t avail_frames = 0; |
1050 | 1085 |
1086 if ((ret = snd_pcm_status_malloc(&status)) < 0) | |
1087 { | |
1088 printf("alsa-space: memory allocation error: %s\n", snd_strerror(ret)); | |
1089 return(0); | |
1090 } | |
1091 | |
1092 if ((ret = snd_pcm_status(alsa_handler, status)) < 0) | |
1093 { | |
1094 printf("alsa-space: cannot get pcm status: %s\n", snd_strerror(ret)); | |
1095 return(0); | |
1096 } | |
1097 | |
1098 switch(snd_pcm_status_get_state(status)) | |
1099 { | |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1100 case SND_PCM_STATE_OPEN: |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1101 str_status = "open"; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1102 case SND_PCM_STATE_PREPARED: |
6749 | 1103 if (str_status != "open") { |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1104 str_status = "prepared"; |
6749 | 1105 first = 1; |
7657
dda97c5190d7
fixed ao_data.bps - patch by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7077
diff
changeset
|
1106 ret = snd_pcm_status_get_avail(status) * bytes_per_sample; |
6749 | 1107 if (ret == 0) //ugly workaround for hang in mmap-mode |
1108 ret = 10; | |
1109 break; | |
1110 } | |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1111 case SND_PCM_STATE_RUNNING: |
7657
dda97c5190d7
fixed ao_data.bps - patch by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7077
diff
changeset
|
1112 ret = snd_pcm_status_get_avail(status) * bytes_per_sample; |
dda97c5190d7
fixed ao_data.bps - patch by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7077
diff
changeset
|
1113 //avail_frames = snd_pcm_avail_update(alsa_handler) * bytes_per_sample; |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1114 if (str_status != "open" && str_status != "prepared") |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1115 str_status = "running"; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1116 break; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1117 case SND_PCM_STATE_PAUSED: |
8027 | 1118 if (verbose>0) printf("alsa-space: paused"); |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1119 str_status = "paused"; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1120 ret = 0; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1121 break; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1122 case SND_PCM_STATE_XRUN: |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1123 xrun("space"); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1124 str_status = "xrun"; |
6749 | 1125 first = 1; |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1126 ret = 0; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1127 break; |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1128 default: |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1129 str_status = "undefined"; |
7657
dda97c5190d7
fixed ao_data.bps - patch by Tobias Diedrich <td@sim.uni-hannover.de>
arpi
parents:
7077
diff
changeset
|
1130 ret = snd_pcm_status_get_avail(status) * bytes_per_sample; |
6749 | 1131 if (ret <= 0) { |
1132 xrun("space"); | |
1133 } | |
1050 | 1134 } |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1135 |
8027 | 1136 if (verbose>0 && str_status != "running") |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1137 printf("alsa-space: free space = %i, status=%i, %s --\n", ret, status, str_status); |
1050 | 1138 snd_pcm_status_free(status); |
1129 | 1139 |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1140 if (ret < 0) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1141 printf("negative value!!\n"); |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
1142 ret = 0; |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1143 } |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1144 |
8874 | 1145 // workaround for too small value returned |
1146 if (ret < MIN_CHUNK_SIZE) | |
1147 ret = 0; | |
1148 | |
1050 | 1149 return(ret); |
1150 } | |
1151 | |
3095 | 1152 /* delay in seconds between first and last sample in buffer */ |
1153 static float get_delay() | |
1050 | 1154 { |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1155 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1156 if (alsa_handler) { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1157 |
1050 | 1158 snd_pcm_status_t *status; |
3095 | 1159 float ret; |
1050 | 1160 |
1161 if ((ret = snd_pcm_status_malloc(&status)) < 0) | |
1162 { | |
1163 printf("alsa-delay: memory allocation error: %s\n", snd_strerror(ret)); | |
1164 return(0); | |
1165 } | |
1166 | |
1167 if ((ret = snd_pcm_status(alsa_handler, status)) < 0) | |
1168 { | |
1169 printf("alsa-delay: cannot get pcm status: %s\n", snd_strerror(ret)); | |
1170 return(0); | |
1171 } | |
1172 | |
1173 switch(snd_pcm_status_get_state(status)) | |
1174 { | |
1175 case SND_PCM_STATE_OPEN: | |
1176 case SND_PCM_STATE_PREPARED: | |
1177 case SND_PCM_STATE_RUNNING: | |
3095 | 1178 ret = (float)snd_pcm_status_get_delay(status)/(float)ao_data.samplerate; |
1050 | 1179 break; |
1180 default: | |
1181 ret = 0; | |
1182 } | |
1183 | |
1184 snd_pcm_status_free(status); | |
1129 | 1185 |
1186 if (ret < 0) | |
6589
1595ca898d3b
cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents:
6194
diff
changeset
|
1187 ret = 0; |
1050 | 1188 return(ret); |
6633
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1189 |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1190 } else { |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1191 return(0); |
769246a4eb41
cVS: ---------------------------------------------------------------------
joyping
parents:
6589
diff
changeset
|
1192 } |
1050 | 1193 } |