Mercurial > mplayer.hg
annotate libao2/ao_alsa9.c @ 6459:f82b8063f3e7
Suppress garbage at the end of some subtitles.
author | kmkaplan |
---|---|
date | Mon, 17 Jun 2002 19:11:22 +0000 |
parents | 156144ee6810 |
children | 1595ca898d3b |
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 return(CONTROL_UNKNOWN); | |
179 } | |
180 | |
2209 | 181 #undef start /* orig. undef */ |
3135 | 182 #define buffsize |
2209 | 183 #define buffertime /* orig. undef? */ |
1128 | 184 #define set_period |
2209 | 185 #define sw_params /* orig. undef */ |
186 #undef set_start_mode /* orig. undef */ | |
1128 | 187 |
1050 | 188 /* |
189 open & setup audio device | |
190 return: 1=success 0=fail | |
191 */ | |
192 static int init(int rate_hz, int channels, int format, int flags) | |
193 { | |
194 int err; | |
195 int cards = -1; | |
196 snd_pcm_info_t *alsa_info; | |
1180 | 197 |
2209 | 198 size_t xfer_align; //new |
199 snd_pcm_uframes_t start_threshold, stop_threshold; //new | |
1050 | 200 |
2209 | 201 printf("alsa-init: this driver is still at alpha-stage. if you want stable sound support use the OSS emulation instead.\n"); |
1050 | 202 printf("alsa-init: requested format: %d Hz, %d channels, %s\n", rate_hz, |
203 channels, audio_out_format_name(format)); | |
204 | |
205 alsa_handler = NULL; | |
206 | |
207 if (verbose) | |
2059 | 208 printf("alsa-init: compiled for ALSA-%s\n", SND_LIB_VERSION_STR); |
1050 | 209 |
210 if ((err = snd_card_next(&cards)) < 0 || cards < 0) | |
211 { | |
212 printf("alsa-init: no soundcards found: %s\n", snd_strerror(err)); | |
213 return(0); | |
214 } | |
215 | |
3095 | 216 ao_data.samplerate = rate_hz; |
217 ao_data.bps = channels; /* really this is bytes per frame so bad varname */ | |
218 ao_data.format = format; | |
219 ao_data.channels = channels; | |
220 ao_data.outburst = OUTBURST; | |
221 ao_data.buffersize = 16384; | |
1050 | 222 |
223 switch (format) | |
224 { | |
225 case AFMT_S8: | |
226 alsa_format = SND_PCM_FORMAT_S8; | |
227 break; | |
228 case AFMT_U8: | |
229 alsa_format = SND_PCM_FORMAT_U8; | |
230 break; | |
231 case AFMT_U16_LE: | |
232 alsa_format = SND_PCM_FORMAT_U16_LE; | |
233 break; | |
234 case AFMT_U16_BE: | |
235 alsa_format = SND_PCM_FORMAT_U16_BE; | |
236 break; | |
5790 | 237 #ifndef WORDS_BIGENDIAN |
238 case AFMT_AC3: | |
239 #endif | |
1050 | 240 case AFMT_S16_LE: |
241 alsa_format = SND_PCM_FORMAT_S16_LE; | |
242 break; | |
5790 | 243 #ifdef WORDS_BIGENDIAN |
244 case AFMT_AC3: | |
245 #endif | |
1050 | 246 case AFMT_S16_BE: |
247 alsa_format = SND_PCM_FORMAT_S16_BE; | |
248 break; | |
249 default: | |
250 alsa_format = SND_PCM_FORMAT_MPEG; | |
251 break; | |
252 } | |
253 | |
254 switch(alsa_format) | |
255 { | |
256 case SND_PCM_FORMAT_S16_LE: | |
257 case SND_PCM_FORMAT_U16_LE: | |
3095 | 258 ao_data.bps *= 2; |
1050 | 259 break; |
260 case -1: | |
261 printf("alsa-init: invalid format (%s) requested - output disabled\n", | |
262 audio_out_format_name(format)); | |
263 return(0); | |
1115
a16b569f2702
-Wall style cleanups, TEST IT, it can be working by others
al3x
parents:
1058
diff
changeset
|
264 default: |
a16b569f2702
-Wall style cleanups, TEST IT, it can be working by others
al3x
parents:
1058
diff
changeset
|
265 break; |
1050 | 266 } |
1128 | 267 |
1050 | 268 if ((err = snd_pcm_info_malloc(&alsa_info)) < 0) |
269 { | |
270 printf("alsa-init: memory allocation error: %s\n", snd_strerror(err)); | |
271 return(0); | |
272 } | |
273 | |
3129 | 274 if (ao_subdevice != NULL) |
275 alsa_device = ao_subdevice; | |
1207 | 276 |
1146
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
277 if (alsa_device == NULL) |
1050 | 278 { |
1146
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
279 if ((alsa_device = malloc(ALSA_DEVICE_SIZE)) == NULL) |
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
280 { |
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
281 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
|
282 return(0); |
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
283 } |
1050 | 284 |
1146
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
285 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
|
286 snd_pcm_info_get_device(alsa_info), |
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
287 snd_pcm_info_get_subdevice(alsa_info)); |
1050 | 288 |
1146
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
289 snd_pcm_info_free(alsa_info); |
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
290 } |
1050 | 291 |
292 printf("alsa-init: %d soundcard%s found, using: %s\n", cards+1, | |
293 (cards >= 0) ? "" : "s", alsa_device); | |
294 | |
6193
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
295 if (format == AFMT_AC3) { |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
296 // 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
|
297 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
|
298 } |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
299 |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
300 if (!alsa_handler) { |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
301 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
|
302 0)) < 0) |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
303 { |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
304 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
|
305 return(0); |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
306 } |
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
307 } |
1050 | 308 |
309 snd_pcm_hw_params_malloc(&alsa_hwparams); | |
2209 | 310 snd_pcm_sw_params_alloca(&alsa_swparams); |
1050 | 311 if ((err = snd_pcm_hw_params_any(alsa_handler, alsa_hwparams)) < 0) |
312 { | |
313 printf("alsa-init: unable to get initial parameters: %s\n", | |
314 snd_strerror(err)); | |
315 return(0); | |
316 } | |
317 | |
318 if ((err = snd_pcm_hw_params_set_access(alsa_handler, alsa_hwparams, | |
319 SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) | |
320 { | |
321 printf("alsa-init: unable to set access type: %s\n", | |
322 snd_strerror(err)); | |
323 return(0); | |
324 } | |
325 | |
326 if ((err = snd_pcm_hw_params_set_format(alsa_handler, alsa_hwparams, | |
327 alsa_format)) < 0) | |
328 { | |
329 printf("alsa-init: unable to set format: %s\n", | |
330 snd_strerror(err)); | |
331 return(0); | |
332 } | |
333 | |
334 if ((err = snd_pcm_hw_params_set_channels(alsa_handler, alsa_hwparams, | |
3095 | 335 ao_data.channels)) < 0) |
1050 | 336 { |
337 printf("alsa-init: unable to set channels: %s\n", | |
338 snd_strerror(err)); | |
339 return(0); | |
340 } | |
341 | |
3095 | 342 if ((err = snd_pcm_hw_params_set_rate_near(alsa_handler, alsa_hwparams, ao_data.samplerate, 0)) < 0) |
2209 | 343 /* was originally only snd_pcm_hw_params_set_rate jp*/ |
2059 | 344 { |
345 printf("alsa-init: unable to set samplerate-2: %s\n", | |
346 snd_strerror(err)); | |
2209 | 347 //snd_pcm_hw_params_dump(alsa_hwparams, errlog); jp |
2059 | 348 return(0); |
349 } | |
1050 | 350 |
1128 | 351 #ifdef set_period |
1115
a16b569f2702
-Wall style cleanups, TEST IT, it can be working by others
al3x
parents:
1058
diff
changeset
|
352 { |
1128 | 353 if ((err = snd_pcm_hw_params_set_period_size(alsa_handler, alsa_hwparams, alsa_fragsize / 4, 0)) < 0) |
354 { | |
355 printf("alsa-init: unable to set periodsize: %s\n", | |
356 snd_strerror(err)); | |
357 return(0); | |
358 } | |
2209 | 359 if ((err = snd_pcm_hw_params_set_periods(alsa_handler, alsa_hwparams, alsa_fragcount, 0)) < 0) |
360 { | |
361 printf("alsa-init: unable to set periods: %s\n", | |
362 snd_strerror(err)); | |
363 return(0); | |
364 } | |
1115
a16b569f2702
-Wall style cleanups, TEST IT, it can be working by others
al3x
parents:
1058
diff
changeset
|
365 } |
1128 | 366 #endif |
3135 | 367 #ifdef buffsize |
1050 | 368 if ((err = snd_pcm_hw_params_get_buffer_size(alsa_hwparams)) < 0) |
369 { | |
370 printf("alsa-init: unable to get buffer size: %s\n", | |
371 snd_strerror(err)); | |
372 return(0); | |
373 } else | |
1128 | 374 { |
3095 | 375 ao_data.buffersize = err; |
1146
a84610bb5476
hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents:
1129
diff
changeset
|
376 if (verbose) |
3095 | 377 printf("alsa-init: got buffersize %i\n", ao_data.buffersize); |
1128 | 378 } |
1050 | 379 #endif |
380 | |
381 #ifdef buffertime | |
382 { | |
2209 | 383 int alsa_buffer_time = 500000; /* original 60 */ |
1050 | 384 |
2059 | 385 if ((err = snd_pcm_hw_params_set_buffer_time_near(alsa_handler, alsa_hwparams, alsa_buffer_time, 0)) < 0) |
1050 | 386 { |
387 printf("alsa-init: unable to set buffer time near: %s\n", | |
388 snd_strerror(err)); | |
389 return(0); | |
390 } else | |
391 alsa_buffer_time = err; | |
392 | |
2209 | 393 if ((err = snd_pcm_hw_params_set_period_time_near(alsa_handler, alsa_hwparams, alsa_buffer_time/4, 0)) < 0) |
3095 | 394 /* original: alsa_buffer_time/ao_data.bps */ |
1050 | 395 { |
396 printf("alsa-init: unable to set period time: %s\n", | |
397 snd_strerror(err)); | |
398 return(0); | |
399 } | |
1128 | 400 printf("alsa-init: buffer_time: %d, period_time :%d\n", |
401 alsa_buffer_time, err); | |
1050 | 402 } |
403 #endif | |
404 | |
405 if ((err = snd_pcm_hw_params(alsa_handler, alsa_hwparams)) < 0) | |
406 { | |
407 printf("alsa-init: unable to set parameters: %s\n", | |
408 snd_strerror(err)); | |
409 return(0); | |
410 } | |
1128 | 411 |
412 #ifdef sw_params | |
2209 | 413 { |
414 chunk_size = snd_pcm_hw_params_get_period_size(alsa_hwparams, 0); | |
3095 | 415 start_threshold = (double) ao_data.samplerate * start_delay / 1000000; |
2209 | 416 xfer_align = snd_pcm_sw_params_get_xfer_align(alsa_swparams); |
417 | |
1050 | 418 if ((err = snd_pcm_sw_params_current(alsa_handler, alsa_swparams)) < 0) |
419 { | |
420 printf("alsa-init: unable to get parameters: %s\n", | |
421 snd_strerror(err)); | |
422 return(0); | |
2209 | 423 } |
424 | |
425 if ((err = snd_pcm_sw_params_set_avail_min(alsa_handler, alsa_swparams, chunk_size)) < 0) | |
426 { | |
427 printf("alsa-init: unable to set avail_min %s\n",snd_strerror(err)); | |
428 return(0); | |
429 } | |
430 | |
431 | |
432 | |
433 if ((err = snd_pcm_sw_params_set_start_threshold(alsa_handler, alsa_swparams, start_threshold)) < 0) | |
434 { | |
435 printf("alsa-init: unable to set start_threshold %s\n",snd_strerror(err)); | |
436 return(0); | |
437 } | |
438 } | |
439 // if ((err = snd_pcm_sw_params_set_xfer_align(alsa_handler, alsa_swparams, xfer_align)) < 0) | |
440 //{ | |
441 // printf("alsa-init: unable to set xfer_align: %s\n", | |
442 // snd_strerror(err)); | |
443 // return(0); | |
444 //} | |
1050 | 445 |
1128 | 446 #ifdef set_start_mode |
1050 | 447 if ((err = snd_pcm_sw_params_set_start_mode(alsa_handler, alsa_swparams, |
448 SND_PCM_START_DATA)) < 0) | |
449 { | |
450 printf("alsa-init: unable to set start mode: %s\n", | |
451 snd_strerror(err)); | |
452 return(0); | |
453 } | |
1128 | 454 #endif |
1050 | 455 |
456 if ((err = snd_pcm_sw_params(alsa_handler, alsa_swparams)) < 0) | |
457 { | |
458 printf("alsa-init: unable to set parameters: %s\n", | |
459 snd_strerror(err)); | |
460 return(0); | |
461 } | |
462 | |
1128 | 463 // snd_pcm_sw_params_default(alsa_handler, alsa_swparams); |
464 #endif | |
1050 | 465 if ((err = snd_pcm_prepare(alsa_handler)) < 0) |
466 { | |
467 printf("alsa-init: pcm prepare error: %s\n", snd_strerror(err)); | |
468 return(0); | |
469 } | |
470 | |
1115
a16b569f2702
-Wall style cleanups, TEST IT, it can be working by others
al3x
parents:
1058
diff
changeset
|
471 #ifdef start |
1050 | 472 if ((err = snd_pcm_start(alsa_handler)) < 0) |
473 { | |
474 printf("alsa-init: pcm start error: %s\n", snd_strerror(err)); | |
475 if (err != -EPIPE) | |
476 return(0); | |
477 if ((err = snd_pcm_start(alsa_handler)) < 0) | |
478 { | |
479 printf("alsa-init: pcm start error: %s\n", snd_strerror(err)); | |
480 return(0); | |
481 } | |
482 } | |
1115
a16b569f2702
-Wall style cleanups, TEST IT, it can be working by others
al3x
parents:
1058
diff
changeset
|
483 #endif |
1128 | 484 printf("AUDIO: %d Hz/%d channels/%d bpf/%d bytes buffer/%s\n", |
3095 | 485 ao_data.samplerate, ao_data.channels, ao_data.bps, ao_data.buffersize, |
1050 | 486 snd_pcm_format_description(alsa_format)); |
487 return(1); | |
488 } | |
489 | |
490 /* close audio device */ | |
491 static void uninit() | |
492 { | |
493 int err; | |
494 | |
495 if (alsa_device != NULL) | |
496 free(alsa_device); | |
497 | |
498 snd_pcm_hw_params_free(alsa_hwparams); | |
499 | |
500 if ((err = snd_pcm_drain(alsa_handler)) < 0) | |
501 { | |
502 printf("alsa-uninit: pcm drain error: %s\n", snd_strerror(err)); | |
503 return; | |
504 } | |
505 | |
1129 | 506 #ifdef start |
1050 | 507 if ((err = snd_pcm_reset(alsa_handler)) < 0) |
508 { | |
509 printf("alsa-uninit: pcm reset error: %s\n", snd_strerror(err)); | |
510 return; | |
511 } | |
1129 | 512 #endif |
1050 | 513 |
514 if ((err = snd_pcm_close(alsa_handler)) < 0) | |
515 { | |
516 printf("alsa-uninit: pcm close error: %s\n", snd_strerror(err)); | |
517 return; | |
518 } | |
519 } | |
520 | |
521 static void audio_pause() | |
522 { | |
523 int err; | |
524 | |
525 if ((err = snd_pcm_drain(alsa_handler)) < 0) | |
526 { | |
527 printf("alsa-pause: pcm drain error: %s\n", snd_strerror(err)); | |
528 return; | |
529 } | |
530 | |
1129 | 531 #ifdef reset |
1050 | 532 if ((err = snd_pcm_reset(alsa_handler)) < 0) |
533 { | |
534 printf("alsa-pause: pcm reset error: %s\n", snd_strerror(err)); | |
535 return; | |
536 } | |
1129 | 537 #endif |
1050 | 538 } |
539 | |
540 static void audio_resume() | |
541 { | |
542 int err; | |
543 | |
544 if ((err = snd_pcm_prepare(alsa_handler)) < 0) | |
545 { | |
546 printf("alsa-resume: pcm prepare error: %s\n", snd_strerror(err)); | |
547 return; | |
548 } | |
549 | |
1129 | 550 #ifdef start |
1050 | 551 if ((err = snd_pcm_start(alsa_handler)) < 0) |
552 { | |
553 printf("alsa-resume: pcm start error: %s\n", snd_strerror(err)); | |
554 return; | |
555 } | |
1129 | 556 #endif |
1050 | 557 } |
558 | |
559 /* stop playing and empty buffers (for seeking/pause) */ | |
560 static void reset() | |
561 { | |
562 int err; | |
563 | |
564 if ((err = snd_pcm_drain(alsa_handler)) < 0) | |
565 { | |
566 printf("alsa-reset: pcm drain error: %s\n", snd_strerror(err)); | |
567 return; | |
568 } | |
569 | |
1129 | 570 #ifdef start |
1050 | 571 if ((err = snd_pcm_reset(alsa_handler)) < 0) |
572 { | |
573 printf("alsa-reset: pcm reset error: %s\n", snd_strerror(err)); | |
574 return; | |
575 } | |
1129 | 576 #endif |
1050 | 577 |
578 if ((err = snd_pcm_prepare(alsa_handler)) < 0) | |
579 { | |
580 printf("alsa-reset: pcm prepare error: %s\n", snd_strerror(err)); | |
581 return; | |
582 } | |
583 | |
1129 | 584 #ifdef start |
1050 | 585 if ((err = snd_pcm_start(alsa_handler)) < 0) |
586 { | |
587 printf("alsa-reset: pcm start error: %s\n", snd_strerror(err)); | |
588 return; | |
589 } | |
1129 | 590 #endif |
1050 | 591 } |
592 | |
593 /* | |
594 plays 'len' bytes of 'data' | |
595 returns: number of bytes played | |
596 */ | |
6193
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
597 |
1050 | 598 static int play(void* data, int len, int flags) |
599 { | |
1115
a16b569f2702
-Wall style cleanups, TEST IT, it can be working by others
al3x
parents:
1058
diff
changeset
|
600 int got_len; |
6193
2fd9ec444098
AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents:
5857
diff
changeset
|
601 |
2059 | 602 got_len = snd_pcm_writei(alsa_handler, data, len / 4); |
603 | |
3095 | 604 //if ((got_len = snd_pcm_writei(alsa_handler, data, (len/ao_data.bps))) != (len/ao_data.bps)) { |
2209 | 605 //SHOULD BE FIXED |
1115
a16b569f2702
-Wall style cleanups, TEST IT, it can be working by others
al3x
parents:
1058
diff
changeset
|
606 if (got_len == -EPIPE) /* underrun? */ |
1050 | 607 { |
608 printf("alsa-play: alsa underrun, resetting stream\n"); | |
1128 | 609 if ((got_len = snd_pcm_prepare(alsa_handler)) < 0) |
1050 | 610 { |
1128 | 611 printf("alsa-play: playback prepare error: %s\n", snd_strerror(got_len)); |
1050 | 612 return(0); |
613 } | |
3095 | 614 if ((got_len = snd_pcm_writei(alsa_handler, data, (len/ao_data.bps))) != (len/ao_data.bps)) |
1050 | 615 { |
616 printf("alsa-play: write error after reset: %s - giving up\n", | |
1128 | 617 snd_strerror(got_len)); |
1050 | 618 return(0); |
619 } | |
620 return(len); /* 2nd write was ok */ | |
621 } | |
622 return(len); | |
2209 | 623 //} |
1050 | 624 } |
625 | |
626 /* how many byes are free in the buffer */ | |
627 static int get_space() | |
628 { | |
629 snd_pcm_status_t *status; | |
630 int ret; | |
631 | |
632 if ((ret = snd_pcm_status_malloc(&status)) < 0) | |
633 { | |
634 printf("alsa-space: memory allocation error: %s\n", snd_strerror(ret)); | |
635 return(0); | |
636 } | |
637 | |
638 if ((ret = snd_pcm_status(alsa_handler, status)) < 0) | |
639 { | |
640 printf("alsa-space: cannot get pcm status: %s\n", snd_strerror(ret)); | |
641 return(0); | |
642 } | |
643 | |
644 switch(snd_pcm_status_get_state(status)) | |
645 { | |
646 case SND_PCM_STATE_OPEN: | |
647 case SND_PCM_STATE_PREPARED: | |
648 case SND_PCM_STATE_RUNNING: | |
3095 | 649 ret = snd_pcm_status_get_avail(status) * ao_data.bps; |
1050 | 650 break; |
651 default: | |
652 ret = 0; | |
653 } | |
654 | |
655 snd_pcm_status_free(status); | |
1129 | 656 |
657 if (ret < 0) | |
658 ret = 0; | |
1050 | 659 return(ret); |
660 } | |
661 | |
3095 | 662 /* delay in seconds between first and last sample in buffer */ |
663 static float get_delay() | |
1050 | 664 { |
665 snd_pcm_status_t *status; | |
3095 | 666 float ret; |
1050 | 667 |
668 if ((ret = snd_pcm_status_malloc(&status)) < 0) | |
669 { | |
670 printf("alsa-delay: memory allocation error: %s\n", snd_strerror(ret)); | |
671 return(0); | |
672 } | |
673 | |
674 if ((ret = snd_pcm_status(alsa_handler, status)) < 0) | |
675 { | |
676 printf("alsa-delay: cannot get pcm status: %s\n", snd_strerror(ret)); | |
677 return(0); | |
678 } | |
679 | |
680 switch(snd_pcm_status_get_state(status)) | |
681 { | |
682 case SND_PCM_STATE_OPEN: | |
683 case SND_PCM_STATE_PREPARED: | |
684 case SND_PCM_STATE_RUNNING: | |
3095 | 685 ret = (float)snd_pcm_status_get_delay(status)/(float)ao_data.samplerate; |
1050 | 686 break; |
687 default: | |
688 ret = 0; | |
689 } | |
690 | |
691 snd_pcm_status_free(status); | |
1129 | 692 |
693 if (ret < 0) | |
694 ret = 0; | |
1050 | 695 return(ret); |
696 } |