annotate libao2/ao_alsa1x.c @ 7547:15868399fe22

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