Mercurial > mplayer.hg
annotate libao2/ao_alsa9.c @ 6193:2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
author | alex |
---|---|
date | Sun, 26 May 2002 12:23:19 +0000 |
parents | d9641a4e7dbb |
children | 156144ee6810 |
rev | line source |
---|---|
1050 | 1 /* |
2 ao_alsa9 - ALSA-0.9.x output plugin for MPlayer | |
3 | |
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 |
2209 | 6 modified for better alsa-0.9.0beta8a-support by Joy Winter <joy@pingfm.org> |
6193
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
7 additional AC3 passthrough support by Andy Lo A Foe <andy@alsaplayer.org> |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
8 |
2209 | 9 This driver is still at alpha stage. |
10 If you want stable sound-support use the OSS emulation instead. | |
11 | |
12 Any bugreports regarding to this driver are welcome either to the mplayer-user-mailinglist or directly to the authors. | |
1050 | 13 */ |
14 | |
15 #include <errno.h> | |
5855
c21948cd027d
fix for latest alsa (sys/asoundlib.h has been moved to alsa/asoundlib.h)
pl
parents:
5790
diff
changeset
|
16 |
5857 | 17 #include "../config.h" |
18 | |
5855
c21948cd027d
fix for latest alsa (sys/asoundlib.h has been moved to alsa/asoundlib.h)
pl
parents:
5790
diff
changeset
|
19 #if HAVE_SYS_ASOUNDLIB_H |
1050 | 20 #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
|
21 #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
|
22 #include <alsa/asoundlib.h> |
c21948cd027d
fix for latest alsa (sys/asoundlib.h has been moved to alsa/asoundlib.h)
pl
parents:
5790
diff
changeset
|
23 #else |
c21948cd027d
fix for latest alsa (sys/asoundlib.h has been moved to alsa/asoundlib.h)
pl
parents:
5790
diff
changeset
|
24 #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
|
25 #endif |
1050 | 26 |
27 #include "audio_out.h" | |
28 #include "audio_out_internal.h" | |
1058 | 29 #include "afmt.h" |
1050 | 30 |
31 extern int verbose; | |
32 | |
33 static ao_info_t info = | |
34 { | |
35 "ALSA-0.9.x audio output", | |
36 "alsa9", | |
2209 | 37 "Alex Beregszaszi <alex@naxine.org>, Joy Winter <joy@pingfm.org>", |
1050 | 38 "under developement" |
39 }; | |
40 | |
41 LIBAO_EXTERN(alsa9) | |
42 | |
43 | |
44 static snd_pcm_t *alsa_handler; | |
45 static snd_pcm_format_t alsa_format; | |
46 static snd_pcm_hw_params_t *alsa_hwparams; | |
47 static snd_pcm_sw_params_t *alsa_swparams; | |
48 static char *alsa_device; | |
2209 | 49 #define ALSA_DEVICE_SIZE 48 |
1050 | 50 |
2209 | 51 static int alsa_fragsize = 8192; /* possible 4096, original 8192 */ |
52 static int alsa_fragcount = 8; | |
53 | |
54 static int chunk_size = -1; | |
55 static int start_delay = 1; | |
1128 | 56 |
6193
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
57 snd_pcm_t * |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
58 spdif_init(int acard, int adevice) |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
59 { |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
60 //char *pcm_name = "hw:0,2"; /* first card second device */ |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
61 char pcm_name[255]; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
62 static snd_aes_iec958_t spdif; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
63 snd_pcm_info_t *info; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
64 snd_pcm_t *handler; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
65 snd_pcm_format_t format = SND_PCM_FORMAT_S16_LE; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
66 unsigned int channels = 2; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
67 unsigned int rate = 48000; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
68 int err, c; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
69 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
70 if (err = snprintf(&pcm_name[0], 11, "hw:%1d,%1d", acard, adevice) <= 0) |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
71 { |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
72 return NULL; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
73 } |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
74 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
75 if ((err = snd_pcm_open(&handler, pcm_name, SND_PCM_STREAM_PLAYBACK, 0)) < 0) |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
76 { |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
77 fprintf(stderr, "open: %s\n", snd_strerror(err)); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
78 return NULL; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
79 } |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
80 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
81 snd_pcm_info_alloca(&info); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
82 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
83 if ((err = snd_pcm_info(handler, info)) < 0) { |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
84 fprintf(stderr, "info: %s\n", snd_strerror(err)); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
85 snd_pcm_close(handler); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
86 return NULL; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
87 } |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
88 printf("device: %d, subdevice: %d\n", snd_pcm_info_get_device(info), |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
89 snd_pcm_info_get_subdevice(info)); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
90 { |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
91 snd_ctl_elem_value_t *ctl; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
92 snd_ctl_t *ctl_handler; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
93 char ctl_name[12]; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
94 int ctl_card; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
95 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
96 spdif.status[0] = IEC958_AES0_NONAUDIO | |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
97 IEC958_AES0_CON_EMPHASIS_NONE; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
98 spdif.status[1] = IEC958_AES1_CON_ORIGINAL | |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
99 IEC958_AES1_CON_PCM_CODER; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
100 spdif.status[2] = 0; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
101 spdif.status[3] = IEC958_AES3_CON_FS_48000; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
102 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
103 snd_ctl_elem_value_alloca(&ctl); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
104 snd_ctl_elem_value_set_interface(ctl, SND_CTL_ELEM_IFACE_PCM); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
105 snd_ctl_elem_value_set_device(ctl, snd_pcm_info_get_device(info)); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
106 snd_ctl_elem_value_set_subdevice(ctl, snd_pcm_info_get_subdevice(info)); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
107 snd_ctl_elem_value_set_name(ctl, SND_CTL_NAME_IEC958("", PLAYBACK,PCM_STREAM)); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
108 snd_ctl_elem_value_set_iec958(ctl, &spdif); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
109 ctl_card = snd_pcm_info_get_card(info); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
110 if (ctl_card < 0) { |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
111 fprintf(stderr, "Unable to setup the IEC958 (S/PDIF) interface - PCM has no assigned card"); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
112 goto __diga_end; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
113 } |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
114 sprintf(ctl_name, "hw:%d", ctl_card); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
115 printf("hw:%d\n", ctl_card); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
116 if ((err = snd_ctl_open(&ctl_handler, ctl_name, 0)) < 0) { |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
117 fprintf(stderr, "Unable to open the control interface '%s': %s", ctl_name, snd_strerror(err)); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
118 goto __diga_end; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
119 } |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
120 if ((err = snd_ctl_elem_write(ctl_handler, ctl)) < 0) { |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
121 fprintf(stderr, "Unable to update the IEC958 control: %s", snd_strerror(err)); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
122 goto __diga_end; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
123 } |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
124 snd_ctl_close(ctl_handler); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
125 __diga_end: |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
126 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
127 } |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
128 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
129 { |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
130 snd_pcm_hw_params_t *params; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
131 snd_pcm_sw_params_t *swparams; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
132 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
133 snd_pcm_hw_params_alloca(¶ms); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
134 snd_pcm_sw_params_alloca(&swparams); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
135 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
136 err = snd_pcm_hw_params_any(handler, params); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
137 if (err < 0) { |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
138 fprintf(stderr, "Broken configuration for this PCM: no configurations available"); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
139 return NULL; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
140 } |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
141 err = snd_pcm_hw_params_set_access(handler, params, |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
142 SND_PCM_ACCESS_RW_INTERLEAVED); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
143 if (err < 0) { |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
144 fprintf(stderr, "Access tyep not available"); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
145 return NULL; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
146 } |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
147 err = snd_pcm_hw_params_set_format(handler, params, format); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
148 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
149 if (err < 0) { |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
150 fprintf(stderr, "Sample format non available"); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
151 return NULL; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
152 } |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
153 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
154 err = snd_pcm_hw_params_set_channels(handler, params, channels); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
155 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
156 if (err < 0) { |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
157 fprintf(stderr, "Channels count non avaible"); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
158 return NULL; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
159 } |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
160 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
161 err = snd_pcm_hw_params_set_rate_near(handler, params, rate, 0); assert(err >= 0); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
162 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
163 err = snd_pcm_hw_params(handler, params); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
164 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
165 if (err < 0) { |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
166 fprintf(stderr, "Cannot set buffer size\n"); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
167 return NULL; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
168 } |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
169 snd_pcm_sw_params_current(handler, swparams); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
170 } |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
171 return handler; |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
172 } |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
173 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
174 |
1050 | 175 /* to set/get/query special features/parameters */ |
176 static int control(int cmd, int arg) | |
177 { | |
178 switch(cmd) | |
179 { | |
180 case AOCONTROL_GET_DEVICE: | |
1146
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
181 return((char *)alsa_device); /* egy kicsit brutalis, dehat :) */ |
1050 | 182 case AOCONTROL_SET_DEVICE: |
1146
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
183 { |
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
184 int ret; |
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
185 |
1050 | 186 strncpy(alsa_device, (char *)arg, ALSA_DEVICE_SIZE); |
1146
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
187 uninit(); |
3095 | 188 ret = init(ao_data.samplerate, ao_data.channels, ao_data.format, 0); |
1146
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
189 if (ret == 0) |
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
190 return(CONTROL_ERROR); |
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
191 else |
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
192 return(CONTROL_OK); |
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
193 } |
1050 | 194 } |
195 return(CONTROL_UNKNOWN); | |
196 } | |
197 | |
2209 | 198 #undef start /* orig. undef */ |
3135 | 199 #define buffsize |
2209 | 200 #define buffertime /* orig. undef? */ |
1128 | 201 #define set_period |
2209 | 202 #define sw_params /* orig. undef */ |
203 #undef set_start_mode /* orig. undef */ | |
1128 | 204 |
1050 | 205 /* |
206 open & setup audio device | |
207 return: 1=success 0=fail | |
208 */ | |
209 static int init(int rate_hz, int channels, int format, int flags) | |
210 { | |
211 int err; | |
212 int cards = -1; | |
213 snd_pcm_info_t *alsa_info; | |
1180 | 214 |
2209 | 215 size_t xfer_align; //new |
216 snd_pcm_uframes_t start_threshold, stop_threshold; //new | |
1050 | 217 |
2209 | 218 printf("alsa-init: this driver is still at alpha-stage. if you want stable sound support use the OSS emulation instead.\n"); |
1050 | 219 printf("alsa-init: requested format: %d Hz, %d channels, %s\n", rate_hz, |
220 channels, audio_out_format_name(format)); | |
221 | |
222 alsa_handler = NULL; | |
223 | |
224 if (verbose) | |
2059 | 225 printf("alsa-init: compiled for ALSA-%s\n", SND_LIB_VERSION_STR); |
1050 | 226 |
227 if ((err = snd_card_next(&cards)) < 0 || cards < 0) | |
228 { | |
229 printf("alsa-init: no soundcards found: %s\n", snd_strerror(err)); | |
230 return(0); | |
231 } | |
232 | |
3095 | 233 ao_data.samplerate = rate_hz; |
234 ao_data.bps = channels; /* really this is bytes per frame so bad varname */ | |
235 ao_data.format = format; | |
236 ao_data.channels = channels; | |
237 ao_data.outburst = OUTBURST; | |
238 ao_data.buffersize = 16384; | |
1050 | 239 |
240 switch (format) | |
241 { | |
242 case AFMT_S8: | |
243 alsa_format = SND_PCM_FORMAT_S8; | |
244 break; | |
245 case AFMT_U8: | |
246 alsa_format = SND_PCM_FORMAT_U8; | |
247 break; | |
248 case AFMT_U16_LE: | |
249 alsa_format = SND_PCM_FORMAT_U16_LE; | |
250 break; | |
251 case AFMT_U16_BE: | |
252 alsa_format = SND_PCM_FORMAT_U16_BE; | |
253 break; | |
5790 | 254 #ifndef WORDS_BIGENDIAN |
255 case AFMT_AC3: | |
256 #endif | |
1050 | 257 case AFMT_S16_LE: |
258 alsa_format = SND_PCM_FORMAT_S16_LE; | |
259 break; | |
5790 | 260 #ifdef WORDS_BIGENDIAN |
261 case AFMT_AC3: | |
262 #endif | |
1050 | 263 case AFMT_S16_BE: |
264 alsa_format = SND_PCM_FORMAT_S16_BE; | |
265 break; | |
266 default: | |
267 alsa_format = SND_PCM_FORMAT_MPEG; | |
268 break; | |
269 } | |
270 | |
271 switch(alsa_format) | |
272 { | |
273 case SND_PCM_FORMAT_S16_LE: | |
274 case SND_PCM_FORMAT_U16_LE: | |
3095 | 275 ao_data.bps *= 2; |
1050 | 276 break; |
277 case -1: | |
278 printf("alsa-init: invalid format (%s) requested - output disabled\n", | |
279 audio_out_format_name(format)); | |
280 return(0); | |
1115
a16b569f2702
-Wall style cleanups, TEST IT, it can be working by others
al3x
parents:
1058
diff
changeset
|
281 default: |
a16b569f2702
-Wall style cleanups, TEST IT, it can be working by others
al3x
parents:
1058
diff
changeset
|
282 break; |
1050 | 283 } |
1128 | 284 |
1050 | 285 if ((err = snd_pcm_info_malloc(&alsa_info)) < 0) |
286 { | |
287 printf("alsa-init: memory allocation error: %s\n", snd_strerror(err)); | |
288 return(0); | |
289 } | |
290 | |
3129 | 291 if (ao_subdevice != NULL) |
292 alsa_device = ao_subdevice; | |
1207 | 293 |
1146
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
294 if (alsa_device == NULL) |
1050 | 295 { |
1146
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
296 if ((alsa_device = malloc(ALSA_DEVICE_SIZE)) == NULL) |
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
297 { |
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
298 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
|
299 return(0); |
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
300 } |
1050 | 301 |
1146
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
302 snprintf(alsa_device, ALSA_DEVICE_SIZE, "hw:%d,%d", |
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
303 snd_pcm_info_get_device(alsa_info), |
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
304 snd_pcm_info_get_subdevice(alsa_info)); |
1050 | 305 |
1146
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
306 snd_pcm_info_free(alsa_info); |
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
307 } |
1050 | 308 |
309 printf("alsa-init: %d soundcard%s found, using: %s\n", cards+1, | |
310 (cards >= 0) ? "" : "s", alsa_device); | |
311 | |
6193
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
312 if (format == AFMT_AC3) { |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
313 // Try to initialize the SPDIF interface |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
314 alsa_handler = spdif_init(0, 2); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
315 } |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
316 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
317 if (!alsa_handler) { |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
318 if ((err = snd_pcm_open(&alsa_handler, alsa_device, SND_PCM_STREAM_PLAYBACK, |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
319 0)) < 0) |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
320 { |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
321 printf("alsa-init: playback open error: %s\n", snd_strerror(err)); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
322 return(0); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
323 } |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
324 } |
1050 | 325 |
326 snd_pcm_hw_params_malloc(&alsa_hwparams); | |
2209 | 327 snd_pcm_sw_params_alloca(&alsa_swparams); |
1050 | 328 if ((err = snd_pcm_hw_params_any(alsa_handler, alsa_hwparams)) < 0) |
329 { | |
330 printf("alsa-init: unable to get initial parameters: %s\n", | |
331 snd_strerror(err)); | |
332 return(0); | |
333 } | |
334 | |
335 if ((err = snd_pcm_hw_params_set_access(alsa_handler, alsa_hwparams, | |
336 SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) | |
337 { | |
338 printf("alsa-init: unable to set access type: %s\n", | |
339 snd_strerror(err)); | |
340 return(0); | |
341 } | |
342 | |
343 if ((err = snd_pcm_hw_params_set_format(alsa_handler, alsa_hwparams, | |
344 alsa_format)) < 0) | |
345 { | |
346 printf("alsa-init: unable to set format: %s\n", | |
347 snd_strerror(err)); | |
348 return(0); | |
349 } | |
350 | |
351 if ((err = snd_pcm_hw_params_set_channels(alsa_handler, alsa_hwparams, | |
3095 | 352 ao_data.channels)) < 0) |
1050 | 353 { |
354 printf("alsa-init: unable to set channels: %s\n", | |
355 snd_strerror(err)); | |
356 return(0); | |
357 } | |
358 | |
3095 | 359 if ((err = snd_pcm_hw_params_set_rate_near(alsa_handler, alsa_hwparams, ao_data.samplerate, 0)) < 0) |
2209 | 360 /* was originally only snd_pcm_hw_params_set_rate jp*/ |
2059 | 361 { |
362 printf("alsa-init: unable to set samplerate-2: %s\n", | |
363 snd_strerror(err)); | |
2209 | 364 //snd_pcm_hw_params_dump(alsa_hwparams, errlog); jp |
2059 | 365 return(0); |
366 } | |
1050 | 367 |
1128 | 368 #ifdef set_period |
1115
a16b569f2702
-Wall style cleanups, TEST IT, it can be working by others
al3x
parents:
1058
diff
changeset
|
369 { |
1128 | 370 if ((err = snd_pcm_hw_params_set_period_size(alsa_handler, alsa_hwparams, alsa_fragsize / 4, 0)) < 0) |
371 { | |
372 printf("alsa-init: unable to set periodsize: %s\n", | |
373 snd_strerror(err)); | |
374 return(0); | |
375 } | |
2209 | 376 if ((err = snd_pcm_hw_params_set_periods(alsa_handler, alsa_hwparams, alsa_fragcount, 0)) < 0) |
377 { | |
378 printf("alsa-init: unable to set periods: %s\n", | |
379 snd_strerror(err)); | |
380 return(0); | |
381 } | |
1115
a16b569f2702
-Wall style cleanups, TEST IT, it can be working by others
al3x
parents:
1058
diff
changeset
|
382 } |
1128 | 383 #endif |
3135 | 384 #ifdef buffsize |
1050 | 385 if ((err = snd_pcm_hw_params_get_buffer_size(alsa_hwparams)) < 0) |
386 { | |
387 printf("alsa-init: unable to get buffer size: %s\n", | |
388 snd_strerror(err)); | |
389 return(0); | |
390 } else | |
1128 | 391 { |
3095 | 392 ao_data.buffersize = err; |
1146
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
393 if (verbose) |
3095 | 394 printf("alsa-init: got buffersize %i\n", ao_data.buffersize); |
1128 | 395 } |
1050 | 396 #endif |
397 | |
398 #ifdef buffertime | |
399 { | |
2209 | 400 int alsa_buffer_time = 500000; /* original 60 */ |
1050 | 401 |
2059 | 402 if ((err = snd_pcm_hw_params_set_buffer_time_near(alsa_handler, alsa_hwparams, alsa_buffer_time, 0)) < 0) |
1050 | 403 { |
404 printf("alsa-init: unable to set buffer time near: %s\n", | |
405 snd_strerror(err)); | |
406 return(0); | |
407 } else | |
408 alsa_buffer_time = err; | |
409 | |
2209 | 410 if ((err = snd_pcm_hw_params_set_period_time_near(alsa_handler, alsa_hwparams, alsa_buffer_time/4, 0)) < 0) |
3095 | 411 /* original: alsa_buffer_time/ao_data.bps */ |
1050 | 412 { |
413 printf("alsa-init: unable to set period time: %s\n", | |
414 snd_strerror(err)); | |
415 return(0); | |
416 } | |
1128 | 417 printf("alsa-init: buffer_time: %d, period_time :%d\n", |
418 alsa_buffer_time, err); | |
1050 | 419 } |
420 #endif | |
421 | |
422 if ((err = snd_pcm_hw_params(alsa_handler, alsa_hwparams)) < 0) | |
423 { | |
424 printf("alsa-init: unable to set parameters: %s\n", | |
425 snd_strerror(err)); | |
426 return(0); | |
427 } | |
1128 | 428 |
429 #ifdef sw_params | |
2209 | 430 { |
431 chunk_size = snd_pcm_hw_params_get_period_size(alsa_hwparams, 0); | |
3095 | 432 start_threshold = (double) ao_data.samplerate * start_delay / 1000000; |
2209 | 433 xfer_align = snd_pcm_sw_params_get_xfer_align(alsa_swparams); |
434 | |
1050 | 435 if ((err = snd_pcm_sw_params_current(alsa_handler, alsa_swparams)) < 0) |
436 { | |
437 printf("alsa-init: unable to get parameters: %s\n", | |
438 snd_strerror(err)); | |
439 return(0); | |
2209 | 440 } |
441 | |
442 if ((err = snd_pcm_sw_params_set_avail_min(alsa_handler, alsa_swparams, chunk_size)) < 0) | |
443 { | |
444 printf("alsa-init: unable to set avail_min %s\n",snd_strerror(err)); | |
445 return(0); | |
446 } | |
447 | |
448 | |
449 | |
450 if ((err = snd_pcm_sw_params_set_start_threshold(alsa_handler, alsa_swparams, start_threshold)) < 0) | |
451 { | |
452 printf("alsa-init: unable to set start_threshold %s\n",snd_strerror(err)); | |
453 return(0); | |
454 } | |
455 } | |
456 // if ((err = snd_pcm_sw_params_set_xfer_align(alsa_handler, alsa_swparams, xfer_align)) < 0) | |
457 //{ | |
458 // printf("alsa-init: unable to set xfer_align: %s\n", | |
459 // snd_strerror(err)); | |
460 // return(0); | |
461 //} | |
1050 | 462 |
1128 | 463 #ifdef set_start_mode |
1050 | 464 if ((err = snd_pcm_sw_params_set_start_mode(alsa_handler, alsa_swparams, |
465 SND_PCM_START_DATA)) < 0) | |
466 { | |
467 printf("alsa-init: unable to set start mode: %s\n", | |
468 snd_strerror(err)); | |
469 return(0); | |
470 } | |
1128 | 471 #endif |
1050 | 472 |
473 if ((err = snd_pcm_sw_params(alsa_handler, alsa_swparams)) < 0) | |
474 { | |
475 printf("alsa-init: unable to set parameters: %s\n", | |
476 snd_strerror(err)); | |
477 return(0); | |
478 } | |
479 | |
1128 | 480 // snd_pcm_sw_params_default(alsa_handler, alsa_swparams); |
481 #endif | |
1050 | 482 if ((err = snd_pcm_prepare(alsa_handler)) < 0) |
483 { | |
484 printf("alsa-init: pcm prepare error: %s\n", snd_strerror(err)); | |
485 return(0); | |
486 } | |
487 | |
1115
a16b569f2702
-Wall style cleanups, TEST IT, it can be working by others
al3x
parents:
1058
diff
changeset
|
488 #ifdef start |
1050 | 489 if ((err = snd_pcm_start(alsa_handler)) < 0) |
490 { | |
491 printf("alsa-init: pcm start error: %s\n", snd_strerror(err)); | |
492 if (err != -EPIPE) | |
493 return(0); | |
494 if ((err = snd_pcm_start(alsa_handler)) < 0) | |
495 { | |
496 printf("alsa-init: pcm start error: %s\n", snd_strerror(err)); | |
497 return(0); | |
498 } | |
499 } | |
1115
a16b569f2702
-Wall style cleanups, TEST IT, it can be working by others
al3x
parents:
1058
diff
changeset
|
500 #endif |
1128 | 501 printf("AUDIO: %d Hz/%d channels/%d bpf/%d bytes buffer/%s\n", |
3095 | 502 ao_data.samplerate, ao_data.channels, ao_data.bps, ao_data.buffersize, |
1050 | 503 snd_pcm_format_description(alsa_format)); |
504 return(1); | |
505 } | |
506 | |
507 /* close audio device */ | |
508 static void uninit() | |
509 { | |
510 int err; | |
511 | |
512 if (alsa_device != NULL) | |
513 free(alsa_device); | |
514 | |
515 snd_pcm_hw_params_free(alsa_hwparams); | |
516 | |
517 if ((err = snd_pcm_drain(alsa_handler)) < 0) | |
518 { | |
519 printf("alsa-uninit: pcm drain error: %s\n", snd_strerror(err)); | |
520 return; | |
521 } | |
522 | |
1129 | 523 #ifdef start |
1050 | 524 if ((err = snd_pcm_reset(alsa_handler)) < 0) |
525 { | |
526 printf("alsa-uninit: pcm reset error: %s\n", snd_strerror(err)); | |
527 return; | |
528 } | |
1129 | 529 #endif |
1050 | 530 |
531 if ((err = snd_pcm_close(alsa_handler)) < 0) | |
532 { | |
533 printf("alsa-uninit: pcm close error: %s\n", snd_strerror(err)); | |
534 return; | |
535 } | |
536 } | |
537 | |
538 static void audio_pause() | |
539 { | |
540 int err; | |
541 | |
542 if ((err = snd_pcm_drain(alsa_handler)) < 0) | |
543 { | |
544 printf("alsa-pause: pcm drain error: %s\n", snd_strerror(err)); | |
545 return; | |
546 } | |
547 | |
1129 | 548 #ifdef reset |
1050 | 549 if ((err = snd_pcm_reset(alsa_handler)) < 0) |
550 { | |
551 printf("alsa-pause: pcm reset error: %s\n", snd_strerror(err)); | |
552 return; | |
553 } | |
1129 | 554 #endif |
1050 | 555 } |
556 | |
557 static void audio_resume() | |
558 { | |
559 int err; | |
560 | |
561 if ((err = snd_pcm_prepare(alsa_handler)) < 0) | |
562 { | |
563 printf("alsa-resume: pcm prepare error: %s\n", snd_strerror(err)); | |
564 return; | |
565 } | |
566 | |
1129 | 567 #ifdef start |
1050 | 568 if ((err = snd_pcm_start(alsa_handler)) < 0) |
569 { | |
570 printf("alsa-resume: pcm start error: %s\n", snd_strerror(err)); | |
571 return; | |
572 } | |
1129 | 573 #endif |
1050 | 574 } |
575 | |
576 /* stop playing and empty buffers (for seeking/pause) */ | |
577 static void reset() | |
578 { | |
579 int err; | |
580 | |
581 if ((err = snd_pcm_drain(alsa_handler)) < 0) | |
582 { | |
583 printf("alsa-reset: pcm drain error: %s\n", snd_strerror(err)); | |
584 return; | |
585 } | |
586 | |
1129 | 587 #ifdef start |
1050 | 588 if ((err = snd_pcm_reset(alsa_handler)) < 0) |
589 { | |
590 printf("alsa-reset: pcm reset error: %s\n", snd_strerror(err)); | |
591 return; | |
592 } | |
1129 | 593 #endif |
1050 | 594 |
595 if ((err = snd_pcm_prepare(alsa_handler)) < 0) | |
596 { | |
597 printf("alsa-reset: pcm prepare error: %s\n", snd_strerror(err)); | |
598 return; | |
599 } | |
600 | |
1129 | 601 #ifdef start |
1050 | 602 if ((err = snd_pcm_start(alsa_handler)) < 0) |
603 { | |
604 printf("alsa-reset: pcm start error: %s\n", snd_strerror(err)); | |
605 return; | |
606 } | |
1129 | 607 #endif |
1050 | 608 } |
609 | |
610 /* | |
611 plays 'len' bytes of 'data' | |
612 returns: number of bytes played | |
613 */ | |
6193
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
614 |
1050 | 615 static int play(void* data, int len, int flags) |
616 { | |
1115
a16b569f2702
-Wall style cleanups, TEST IT, it can be working by others
al3x
parents:
1058
diff
changeset
|
617 int got_len; |
6193
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
618 |
2059 | 619 got_len = snd_pcm_writei(alsa_handler, data, len / 4); |
620 | |
3095 | 621 //if ((got_len = snd_pcm_writei(alsa_handler, data, (len/ao_data.bps))) != (len/ao_data.bps)) { |
2209 | 622 //SHOULD BE FIXED |
1115
a16b569f2702
-Wall style cleanups, TEST IT, it can be working by others
al3x
parents:
1058
diff
changeset
|
623 if (got_len == -EPIPE) /* underrun? */ |
1050 | 624 { |
625 printf("alsa-play: alsa underrun, resetting stream\n"); | |
1128 | 626 if ((got_len = snd_pcm_prepare(alsa_handler)) < 0) |
1050 | 627 { |
1128 | 628 printf("alsa-play: playback prepare error: %s\n", snd_strerror(got_len)); |
1050 | 629 return(0); |
630 } | |
3095 | 631 if ((got_len = snd_pcm_writei(alsa_handler, data, (len/ao_data.bps))) != (len/ao_data.bps)) |
1050 | 632 { |
633 printf("alsa-play: write error after reset: %s - giving up\n", | |
1128 | 634 snd_strerror(got_len)); |
1050 | 635 return(0); |
636 } | |
637 return(len); /* 2nd write was ok */ | |
638 } | |
639 return(len); | |
2209 | 640 //} |
1050 | 641 } |
642 | |
643 /* how many byes are free in the buffer */ | |
644 static int get_space() | |
645 { | |
646 snd_pcm_status_t *status; | |
647 int ret; | |
648 | |
649 if ((ret = snd_pcm_status_malloc(&status)) < 0) | |
650 { | |
651 printf("alsa-space: memory allocation error: %s\n", snd_strerror(ret)); | |
652 return(0); | |
653 } | |
654 | |
655 if ((ret = snd_pcm_status(alsa_handler, status)) < 0) | |
656 { | |
657 printf("alsa-space: cannot get pcm status: %s\n", snd_strerror(ret)); | |
658 return(0); | |
659 } | |
660 | |
661 switch(snd_pcm_status_get_state(status)) | |
662 { | |
663 case SND_PCM_STATE_OPEN: | |
664 case SND_PCM_STATE_PREPARED: | |
665 case SND_PCM_STATE_RUNNING: | |
3095 | 666 ret = snd_pcm_status_get_avail(status) * ao_data.bps; |
1050 | 667 break; |
668 default: | |
669 ret = 0; | |
670 } | |
671 | |
672 snd_pcm_status_free(status); | |
1129 | 673 |
674 if (ret < 0) | |
675 ret = 0; | |
1050 | 676 return(ret); |
677 } | |
678 | |
3095 | 679 /* delay in seconds between first and last sample in buffer */ |
680 static float get_delay() | |
1050 | 681 { |
682 snd_pcm_status_t *status; | |
3095 | 683 float ret; |
1050 | 684 |
685 if ((ret = snd_pcm_status_malloc(&status)) < 0) | |
686 { | |
687 printf("alsa-delay: memory allocation error: %s\n", snd_strerror(ret)); | |
688 return(0); | |
689 } | |
690 | |
691 if ((ret = snd_pcm_status(alsa_handler, status)) < 0) | |
692 { | |
693 printf("alsa-delay: cannot get pcm status: %s\n", snd_strerror(ret)); | |
694 return(0); | |
695 } | |
696 | |
697 switch(snd_pcm_status_get_state(status)) | |
698 { | |
699 case SND_PCM_STATE_OPEN: | |
700 case SND_PCM_STATE_PREPARED: | |
701 case SND_PCM_STATE_RUNNING: | |
3095 | 702 ret = (float)snd_pcm_status_get_delay(status)/(float)ao_data.samplerate; |
1050 | 703 break; |
704 default: | |
705 ret = 0; | |
706 } | |
707 | |
708 snd_pcm_status_free(status); | |
1129 | 709 |
710 if (ret < 0) | |
711 ret = 0; | |
1050 | 712 return(ret); |
713 } |