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