annotate libao2/ao_alsa9.c @ 6425:878f31a10c9d

a-v sync solved postprocess added
author arpi
date Fri, 14 Jun 2002 01:25:41 +0000
parents 156144ee6810
children 1595ca898d3b
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
2209
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
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
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
9 This driver is still at alpha stage.
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
10 If you want stable sound-support use the OSS emulation instead.
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
11
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
12 Any bugreports regarding to this driver are welcome either to the mplayer-user-mailinglist or directly to the authors.
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
13 */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
14
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
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
d9641a4e7dbb 10l pl =)
atmos4
parents: 5855
diff changeset
17 #include "../config.h"
d9641a4e7dbb 10l pl =)
atmos4
parents: 5855
diff changeset
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
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
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
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
26
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
27 #include "audio_out.h"
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
28 #include "audio_out_internal.h"
1058
cab5ba9ffc6c fixed AFMT_ stuff (inclue afmt.h)
arpi_esp
parents: 1050
diff changeset
29 #include "afmt.h"
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
30
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
31 extern int verbose;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
32
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
33 static ao_info_t info =
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
34 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
35 "ALSA-0.9.x audio output",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
36 "alsa9",
2209
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
37 "Alex Beregszaszi <alex@naxine.org>, Joy Winter <joy@pingfm.org>",
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
38 "under developement"
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
39 };
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
40
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
41 LIBAO_EXTERN(alsa9)
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 static snd_pcm_t *alsa_handler;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
45 static snd_pcm_format_t alsa_format;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
46 static snd_pcm_hw_params_t *alsa_hwparams;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
47 static snd_pcm_sw_params_t *alsa_swparams;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
48 static char *alsa_device;
2209
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
49 #define ALSA_DEVICE_SIZE 48
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
50
2209
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
51 static int alsa_fragsize = 8192; /* possible 4096, original 8192 */
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
52 static int alsa_fragcount = 8;
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
53
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
54 static int chunk_size = -1;
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
55 static int start_delay = 1;
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
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(&params);
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
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
175 /* to set/get/query special features/parameters */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
176 static int control(int cmd, int arg)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
177 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
178 return(CONTROL_UNKNOWN);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
179 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
180
2209
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
181 #undef start /* orig. undef */
3135
168b7ed7ec55 Parse bug fixed (I hope)
anders
parents: 3129
diff changeset
182 #define buffsize
2209
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
183 #define buffertime /* orig. undef? */
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
184 #define set_period
2209
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
185 #define sw_params /* orig. undef */
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
186 #undef set_start_mode /* orig. undef */
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
187
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
188 /*
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
189 open & setup audio device
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
190 return: 1=success 0=fail
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
191 */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
192 static int init(int rate_hz, int channels, int format, int flags)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
193 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
194 int err;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
195 int cards = -1;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
196 snd_pcm_info_t *alsa_info;
1180
c50cd5db2359 added warning message
al3x
parents: 1146
diff changeset
197
2209
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
198 size_t xfer_align; //new
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
199 snd_pcm_uframes_t start_threshold, stop_threshold; //new
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
200
2209
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
201 printf("alsa-init: this driver is still at alpha-stage. if you want stable sound support use the OSS emulation instead.\n");
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
202 printf("alsa-init: requested format: %d Hz, %d channels, %s\n", rate_hz,
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
203 channels, audio_out_format_name(format));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
204
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
205 alsa_handler = NULL;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
206
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
207 if (verbose)
2059
3c390543302c alsa9 pecs by joy_ping <joy@pingfm.org>
pontscho
parents: 1207
diff changeset
208 printf("alsa-init: compiled for ALSA-%s\n", SND_LIB_VERSION_STR);
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
209
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
210 if ((err = snd_card_next(&cards)) < 0 || cards < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
211 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
212 printf("alsa-init: no soundcards found: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
213 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
214 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
215
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
216 ao_data.samplerate = rate_hz;
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
217 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
218 ao_data.format = format;
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
219 ao_data.channels = channels;
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
220 ao_data.outburst = OUTBURST;
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
221 ao_data.buffersize = 16384;
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
222
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
223 switch (format)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
224 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
225 case AFMT_S8:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
226 alsa_format = SND_PCM_FORMAT_S8;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
227 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
228 case AFMT_U8:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
229 alsa_format = SND_PCM_FORMAT_U8;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
230 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
231 case AFMT_U16_LE:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
232 alsa_format = SND_PCM_FORMAT_U16_LE;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
233 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
234 case AFMT_U16_BE:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
235 alsa_format = SND_PCM_FORMAT_U16_BE;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
236 break;
5790
d141f1e9cc36 AFMT_AC3 autodetect/fallback to S16
arpi
parents: 3135
diff changeset
237 #ifndef WORDS_BIGENDIAN
d141f1e9cc36 AFMT_AC3 autodetect/fallback to S16
arpi
parents: 3135
diff changeset
238 case AFMT_AC3:
d141f1e9cc36 AFMT_AC3 autodetect/fallback to S16
arpi
parents: 3135
diff changeset
239 #endif
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
240 case AFMT_S16_LE:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
241 alsa_format = SND_PCM_FORMAT_S16_LE;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
242 break;
5790
d141f1e9cc36 AFMT_AC3 autodetect/fallback to S16
arpi
parents: 3135
diff changeset
243 #ifdef WORDS_BIGENDIAN
d141f1e9cc36 AFMT_AC3 autodetect/fallback to S16
arpi
parents: 3135
diff changeset
244 case AFMT_AC3:
d141f1e9cc36 AFMT_AC3 autodetect/fallback to S16
arpi
parents: 3135
diff changeset
245 #endif
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
246 case AFMT_S16_BE:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
247 alsa_format = SND_PCM_FORMAT_S16_BE;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
248 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
249 default:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
250 alsa_format = SND_PCM_FORMAT_MPEG;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
251 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
252 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
253
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
254 switch(alsa_format)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
255 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
256 case SND_PCM_FORMAT_S16_LE:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
257 case SND_PCM_FORMAT_U16_LE:
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
258 ao_data.bps *= 2;
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
259 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
260 case -1:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
261 printf("alsa-init: invalid format (%s) requested - output disabled\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
262 audio_out_format_name(format));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
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
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
266 }
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
267
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
268 if ((err = snd_pcm_info_malloc(&alsa_info)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
269 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
270 printf("alsa-init: memory allocation error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
271 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
272 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
273
3129
6d965759dd01 ao_subdevice fixed. 10l...
arpi
parents: 3095
diff changeset
274 if (ao_subdevice != NULL)
6d965759dd01 ao_subdevice fixed. 10l...
arpi
parents: 3095
diff changeset
275 alsa_device = ao_subdevice;
1207
bf18175dfad7 ao_subdevice support added
al3x
parents: 1180
diff changeset
276
1146
a84610bb5476 hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents: 1129
diff changeset
277 if (alsa_device == NULL)
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
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
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
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
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
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
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
291
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
292 printf("alsa-init: %d soundcard%s found, using: %s\n", cards+1,
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
293 (cards >= 0) ? "" : "s", alsa_device);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
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
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
308
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
309 snd_pcm_hw_params_malloc(&alsa_hwparams);
2209
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
310 snd_pcm_sw_params_alloca(&alsa_swparams);
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
311 if ((err = snd_pcm_hw_params_any(alsa_handler, alsa_hwparams)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
312 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
313 printf("alsa-init: unable to get initial parameters: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
314 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
315 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
316 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
317
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
318 if ((err = snd_pcm_hw_params_set_access(alsa_handler, alsa_hwparams,
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
319 SND_PCM_ACCESS_RW_INTERLEAVED)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
320 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
321 printf("alsa-init: unable to set access type: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
322 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
323 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
324 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
325
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
326 if ((err = snd_pcm_hw_params_set_format(alsa_handler, alsa_hwparams,
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
327 alsa_format)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
328 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
329 printf("alsa-init: unable to set format: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
330 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
331 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
332 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
333
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
334 if ((err = snd_pcm_hw_params_set_channels(alsa_handler, alsa_hwparams,
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
335 ao_data.channels)) < 0)
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
336 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
337 printf("alsa-init: unable to set channels: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
338 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
339 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
340 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
341
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
342 if ((err = snd_pcm_hw_params_set_rate_near(alsa_handler, alsa_hwparams, ao_data.samplerate, 0)) < 0)
2209
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
343 /* was originally only snd_pcm_hw_params_set_rate jp*/
2059
3c390543302c alsa9 pecs by joy_ping <joy@pingfm.org>
pontscho
parents: 1207
diff changeset
344 {
3c390543302c alsa9 pecs by joy_ping <joy@pingfm.org>
pontscho
parents: 1207
diff changeset
345 printf("alsa-init: unable to set samplerate-2: %s\n",
3c390543302c alsa9 pecs by joy_ping <joy@pingfm.org>
pontscho
parents: 1207
diff changeset
346 snd_strerror(err));
2209
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
347 //snd_pcm_hw_params_dump(alsa_hwparams, errlog); jp
2059
3c390543302c alsa9 pecs by joy_ping <joy@pingfm.org>
pontscho
parents: 1207
diff changeset
348 return(0);
3c390543302c alsa9 pecs by joy_ping <joy@pingfm.org>
pontscho
parents: 1207
diff changeset
349 }
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
350
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
351 #ifdef set_period
1115
a16b569f2702 -Wall style cleanups, TEST IT, it can be working by others
al3x
parents: 1058
diff changeset
352 {
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
353 if ((err = snd_pcm_hw_params_set_period_size(alsa_handler, alsa_hwparams, alsa_fragsize / 4, 0)) < 0)
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
354 {
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
355 printf("alsa-init: unable to set periodsize: %s\n",
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
356 snd_strerror(err));
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
357 return(0);
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
358 }
2209
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
359 if ((err = snd_pcm_hw_params_set_periods(alsa_handler, alsa_hwparams, alsa_fragcount, 0)) < 0)
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
360 {
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
361 printf("alsa-init: unable to set periods: %s\n",
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
362 snd_strerror(err));
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
363 return(0);
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
364 }
1115
a16b569f2702 -Wall style cleanups, TEST IT, it can be working by others
al3x
parents: 1058
diff changeset
365 }
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
366 #endif
3135
168b7ed7ec55 Parse bug fixed (I hope)
anders
parents: 3129
diff changeset
367 #ifdef buffsize
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
368 if ((err = snd_pcm_hw_params_get_buffer_size(alsa_hwparams)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
369 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
370 printf("alsa-init: unable to get buffer size: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
371 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
372 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
373 } else
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
374 {
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
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
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
377 printf("alsa-init: got buffersize %i\n", ao_data.buffersize);
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
378 }
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
379 #endif
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
380
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
381 #ifdef buffertime
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
382 {
2209
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
383 int alsa_buffer_time = 500000; /* original 60 */
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
384
2059
3c390543302c alsa9 pecs by joy_ping <joy@pingfm.org>
pontscho
parents: 1207
diff changeset
385 if ((err = snd_pcm_hw_params_set_buffer_time_near(alsa_handler, alsa_hwparams, alsa_buffer_time, 0)) < 0)
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
386 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
387 printf("alsa-init: unable to set buffer time near: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
388 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
389 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
390 } else
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
391 alsa_buffer_time = err;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
392
2209
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
393 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
394 /* original: alsa_buffer_time/ao_data.bps */
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
395 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
396 printf("alsa-init: unable to set period time: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
397 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
398 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
399 }
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
400 printf("alsa-init: buffer_time: %d, period_time :%d\n",
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
401 alsa_buffer_time, err);
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
402 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
403 #endif
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
404
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
405 if ((err = snd_pcm_hw_params(alsa_handler, alsa_hwparams)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
406 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
407 printf("alsa-init: unable to set parameters: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
408 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
409 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
410 }
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
411
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
412 #ifdef sw_params
2209
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
413 {
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
414 chunk_size = snd_pcm_hw_params_get_period_size(alsa_hwparams, 0);
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
415 start_threshold = (double) ao_data.samplerate * start_delay / 1000000;
2209
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
416 xfer_align = snd_pcm_sw_params_get_xfer_align(alsa_swparams);
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
417
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
418 if ((err = snd_pcm_sw_params_current(alsa_handler, alsa_swparams)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
419 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
420 printf("alsa-init: unable to get parameters: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
421 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
422 return(0);
2209
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
423 }
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
424
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
425 if ((err = snd_pcm_sw_params_set_avail_min(alsa_handler, alsa_swparams, chunk_size)) < 0)
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
426 {
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
427 printf("alsa-init: unable to set avail_min %s\n",snd_strerror(err));
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
428 return(0);
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
429 }
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
430
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
431
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
432
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
433 if ((err = snd_pcm_sw_params_set_start_threshold(alsa_handler, alsa_swparams, start_threshold)) < 0)
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
434 {
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
435 printf("alsa-init: unable to set start_threshold %s\n",snd_strerror(err));
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
436 return(0);
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
437 }
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
438 }
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
439 // if ((err = snd_pcm_sw_params_set_xfer_align(alsa_handler, alsa_swparams, xfer_align)) < 0)
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
440 //{
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
441 // printf("alsa-init: unable to set xfer_align: %s\n",
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
442 // snd_strerror(err));
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
443 // return(0);
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
444 //}
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
445
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
446 #ifdef set_start_mode
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
447 if ((err = snd_pcm_sw_params_set_start_mode(alsa_handler, alsa_swparams,
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
448 SND_PCM_START_DATA)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
449 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
450 printf("alsa-init: unable to set start mode: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
451 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
452 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
453 }
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
454 #endif
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
455
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
456 if ((err = snd_pcm_sw_params(alsa_handler, alsa_swparams)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
457 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
458 printf("alsa-init: unable to set parameters: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
459 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
460 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
461 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
462
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
463 // snd_pcm_sw_params_default(alsa_handler, alsa_swparams);
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
464 #endif
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
465 if ((err = snd_pcm_prepare(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
466 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
467 printf("alsa-init: pcm prepare error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
468 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
469 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
470
1115
a16b569f2702 -Wall style cleanups, TEST IT, it can be working by others
al3x
parents: 1058
diff changeset
471 #ifdef start
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
472 if ((err = snd_pcm_start(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
473 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
474 printf("alsa-init: pcm start error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
475 if (err != -EPIPE)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
476 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
477 if ((err = snd_pcm_start(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
478 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
479 printf("alsa-init: pcm start error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
480 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
481 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
482 }
1115
a16b569f2702 -Wall style cleanups, TEST IT, it can be working by others
al3x
parents: 1058
diff changeset
483 #endif
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
484 printf("AUDIO: %d Hz/%d channels/%d bpf/%d bytes buffer/%s\n",
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
485 ao_data.samplerate, ao_data.channels, ao_data.bps, ao_data.buffersize,
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
486 snd_pcm_format_description(alsa_format));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
487 return(1);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
488 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
489
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
490 /* close audio device */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
491 static void uninit()
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
492 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
493 int err;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
494
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
495 if (alsa_device != NULL)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
496 free(alsa_device);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
497
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
498 snd_pcm_hw_params_free(alsa_hwparams);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
499
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
500 if ((err = snd_pcm_drain(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
501 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
502 printf("alsa-uninit: pcm drain error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
503 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
504 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
505
1129
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
506 #ifdef start
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
507 if ((err = snd_pcm_reset(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
508 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
509 printf("alsa-uninit: pcm reset error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
510 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
511 }
1129
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
512 #endif
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
513
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
514 if ((err = snd_pcm_close(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
515 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
516 printf("alsa-uninit: pcm close error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
517 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
518 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
519 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
520
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
521 static void audio_pause()
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
522 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
523 int err;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
524
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
525 if ((err = snd_pcm_drain(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
526 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
527 printf("alsa-pause: pcm drain error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
528 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
529 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
530
1129
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
531 #ifdef reset
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
532 if ((err = snd_pcm_reset(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
533 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
534 printf("alsa-pause: pcm reset error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
535 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
536 }
1129
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
537 #endif
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
538 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
539
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
540 static void audio_resume()
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
541 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
542 int err;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
543
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
544 if ((err = snd_pcm_prepare(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
545 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
546 printf("alsa-resume: pcm prepare error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
547 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
548 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
549
1129
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
550 #ifdef start
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
551 if ((err = snd_pcm_start(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
552 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
553 printf("alsa-resume: pcm start error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
554 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
555 }
1129
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
556 #endif
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
557 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
558
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
559 /* stop playing and empty buffers (for seeking/pause) */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
560 static void reset()
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
561 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
562 int err;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
563
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
564 if ((err = snd_pcm_drain(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
565 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
566 printf("alsa-reset: pcm drain error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
567 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
568 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
569
1129
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
570 #ifdef start
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
571 if ((err = snd_pcm_reset(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
572 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
573 printf("alsa-reset: pcm reset error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
574 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
575 }
1129
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
576 #endif
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
577
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
578 if ((err = snd_pcm_prepare(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
579 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
580 printf("alsa-reset: pcm prepare error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
581 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
582 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
583
1129
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
584 #ifdef start
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
585 if ((err = snd_pcm_start(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
586 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
587 printf("alsa-reset: pcm start error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
588 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
589 }
1129
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
590 #endif
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
591 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
592
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
593 /*
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
594 plays 'len' bytes of 'data'
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
595 returns: number of bytes played
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
596 */
6193
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
597
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
598 static int play(void* data, int len, int flags)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
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
3c390543302c alsa9 pecs by joy_ping <joy@pingfm.org>
pontscho
parents: 1207
diff changeset
602 got_len = snd_pcm_writei(alsa_handler, data, len / 4);
3c390543302c alsa9 pecs by joy_ping <joy@pingfm.org>
pontscho
parents: 1207
diff changeset
603
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
604 //if ((got_len = snd_pcm_writei(alsa_handler, data, (len/ao_data.bps))) != (len/ao_data.bps)) {
2209
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
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
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
607 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
608 printf("alsa-play: alsa underrun, resetting stream\n");
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
609 if ((got_len = snd_pcm_prepare(alsa_handler)) < 0)
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
610 {
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
611 printf("alsa-play: playback prepare error: %s\n", snd_strerror(got_len));
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
612 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
613 }
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
614 if ((got_len = snd_pcm_writei(alsa_handler, data, (len/ao_data.bps))) != (len/ao_data.bps))
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
615 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
616 printf("alsa-play: write error after reset: %s - giving up\n",
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
617 snd_strerror(got_len));
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
618 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
619 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
620 return(len); /* 2nd write was ok */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
621 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
622 return(len);
2209
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
623 //}
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
624 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
625
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
626 /* how many byes are free in the buffer */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
627 static int get_space()
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
628 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
629 snd_pcm_status_t *status;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
630 int ret;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
631
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
632 if ((ret = snd_pcm_status_malloc(&status)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
633 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
634 printf("alsa-space: memory allocation error: %s\n", snd_strerror(ret));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
635 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
636 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
637
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
638 if ((ret = snd_pcm_status(alsa_handler, status)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
639 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
640 printf("alsa-space: cannot get pcm status: %s\n", snd_strerror(ret));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
641 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
642 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
643
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
644 switch(snd_pcm_status_get_state(status))
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
645 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
646 case SND_PCM_STATE_OPEN:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
647 case SND_PCM_STATE_PREPARED:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
648 case SND_PCM_STATE_RUNNING:
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
649 ret = snd_pcm_status_get_avail(status) * ao_data.bps;
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
650 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
651 default:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
652 ret = 0;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
653 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
654
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
655 snd_pcm_status_free(status);
1129
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
656
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
657 if (ret < 0)
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
658 ret = 0;
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
659 return(ret);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
660 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
661
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
662 /* delay in seconds between first and last sample in buffer */
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
663 static float get_delay()
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
664 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
665 snd_pcm_status_t *status;
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
666 float ret;
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
667
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
668 if ((ret = snd_pcm_status_malloc(&status)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
669 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
670 printf("alsa-delay: memory allocation error: %s\n", snd_strerror(ret));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
671 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
672 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
673
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
674 if ((ret = snd_pcm_status(alsa_handler, status)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
675 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
676 printf("alsa-delay: cannot get pcm status: %s\n", snd_strerror(ret));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
677 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
678 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
679
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
680 switch(snd_pcm_status_get_state(status))
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
681 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
682 case SND_PCM_STATE_OPEN:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
683 case SND_PCM_STATE_PREPARED:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
684 case SND_PCM_STATE_RUNNING:
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
685 ret = (float)snd_pcm_status_get_delay(status)/(float)ao_data.samplerate;
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
686 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
687 default:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
688 ret = 0;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
689 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
690
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
691 snd_pcm_status_free(status);
1129
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
692
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
693 if (ret < 0)
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
694 ret = 0;
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
695 return(ret);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
696 }