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