annotate libao2/ao_alsa1x.c @ 1575:2766b0d3863d

osd problem with YV12 fixed
author folke
date Fri, 17 Aug 2001 14:31:03 +0000
parents bf18175dfad7
children 3c390543302c
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>
1180
c50cd5db2359 added warning message
al3x
parents: 1146
diff changeset
5
c50cd5db2359 added warning message
al3x
parents: 1146
diff changeset
6 Don't use this buggy driver, ALSA-0.9.x emulates OSS very well...
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
7 */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
8
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
9 #include <errno.h>
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
10 #include <sys/asoundlib.h>
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
11
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
12 #include "../config.h"
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
13
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
14 #include "audio_out.h"
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
15 #include "audio_out_internal.h"
1058
cab5ba9ffc6c fixed AFMT_ stuff (inclue afmt.h)
arpi_esp
parents: 1050
diff changeset
16 #include "afmt.h"
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
17
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
18 extern int verbose;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
19
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
20 static ao_info_t info =
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
21 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
22 "ALSA-0.9.x audio output",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
23 "alsa9",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
24 "Alex Beregszaszi <alex@naxine.org>",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
25 "under developement"
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
26 };
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
27
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
28 LIBAO_EXTERN(alsa9)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
29
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
30 /* global variables:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
31 ao_samplerate
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
32 ao_channels
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
33 ao_format
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
34 ao_bps
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
35 ao_outburst
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
36 ao_buffersize
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
37 */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
38
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
39 static snd_pcm_t *alsa_handler;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
40 static snd_pcm_format_t alsa_format;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
41 static snd_pcm_hw_params_t *alsa_hwparams;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
42 static snd_pcm_sw_params_t *alsa_swparams;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
43 static char *alsa_device;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
44 #define ALSA_DEVICE_SIZE 48
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
45
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
46 static int alsa_fragsize = 8192; /* 4096 */
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
47 static int alsa_fragcount = 8;
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
48
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
49 /* to set/get/query special features/parameters */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
50 static int control(int cmd, int arg)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
51 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
52 switch(cmd)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
53 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
54 case AOCONTROL_GET_DEVICE:
1146
a84610bb5476 hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents: 1129
diff changeset
55 return((char *)alsa_device); /* egy kicsit brutalis, dehat :) */
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
56 case AOCONTROL_SET_DEVICE:
1146
a84610bb5476 hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents: 1129
diff changeset
57 {
a84610bb5476 hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents: 1129
diff changeset
58 int ret;
a84610bb5476 hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents: 1129
diff changeset
59
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
60 strncpy(alsa_device, (char *)arg, ALSA_DEVICE_SIZE);
1146
a84610bb5476 hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents: 1129
diff changeset
61 uninit();
a84610bb5476 hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents: 1129
diff changeset
62 ret = init(ao_samplerate, ao_channels, ao_format, 0);
a84610bb5476 hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents: 1129
diff changeset
63 if (ret == 0)
a84610bb5476 hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents: 1129
diff changeset
64 return(CONTROL_ERROR);
a84610bb5476 hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents: 1129
diff changeset
65 else
a84610bb5476 hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents: 1129
diff changeset
66 return(CONTROL_OK);
a84610bb5476 hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents: 1129
diff changeset
67 }
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
68 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
69 return(CONTROL_UNKNOWN);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
70 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
71
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
72 #undef start
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
73 #define buffersize
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
74 #undef buffertime
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
75 #define set_period
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
76 #undef sw_params
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
77 #undef set_start_mode
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
78
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
79 /*
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
80 open & setup audio device
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
81 return: 1=success 0=fail
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
82 */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
83 static int init(int rate_hz, int channels, int format, int flags)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
84 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
85 int err;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
86 int cards = -1;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
87 snd_pcm_info_t *alsa_info;
1180
c50cd5db2359 added warning message
al3x
parents: 1146
diff changeset
88
c50cd5db2359 added warning message
al3x
parents: 1146
diff changeset
89 printf("alsa-init: Don't use this buggy driver, ALSA-0.9.x emulates OSS very well...\n");
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
90
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
91 printf("alsa-init: requested format: %d Hz, %d channels, %s\n", rate_hz,
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
92 channels, audio_out_format_name(format));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
93
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
94 alsa_handler = NULL;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
95
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
96 if (verbose)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
97 printf("alsa-init: compiled for ALSA-%s (%d)\n", SND_LIB_VERSION_STR,
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
98 SND_LIB_VERSION);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
99
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
100 if ((err = snd_card_next(&cards)) < 0 || cards < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
101 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
102 printf("alsa-init: no soundcards found: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
103 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
104 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
105
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
106 ao_samplerate = rate_hz;
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
107 ao_bps = channels; /* really this is bytes per frame so bad varname */
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
108 ao_format = format;
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
109 ao_channels = channels;
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
110 ao_outburst = OUTBURST;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
111 ao_buffersize = 16384;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
112
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
113 switch (format)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
114 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
115 case AFMT_S8:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
116 alsa_format = SND_PCM_FORMAT_S8;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
117 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
118 case AFMT_U8:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
119 alsa_format = SND_PCM_FORMAT_U8;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
120 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
121 case AFMT_U16_LE:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
122 alsa_format = SND_PCM_FORMAT_U16_LE;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
123 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
124 case AFMT_U16_BE:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
125 alsa_format = SND_PCM_FORMAT_U16_BE;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
126 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
127 case AFMT_S16_LE:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
128 alsa_format = SND_PCM_FORMAT_S16_LE;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
129 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
130 case AFMT_S16_BE:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
131 alsa_format = SND_PCM_FORMAT_S16_BE;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
132 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
133 default:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
134 alsa_format = SND_PCM_FORMAT_MPEG;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
135 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
136 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
137
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
138 switch(alsa_format)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
139 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
140 case SND_PCM_FORMAT_S16_LE:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
141 case SND_PCM_FORMAT_U16_LE:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
142 ao_bps *= 2;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
143 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
144 case -1:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
145 printf("alsa-init: invalid format (%s) requested - output disabled\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
146 audio_out_format_name(format));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
147 return(0);
1115
a16b569f2702 -Wall style cleanups, TEST IT, it can be working by others
al3x
parents: 1058
diff changeset
148 default:
a16b569f2702 -Wall style cleanups, TEST IT, it can be working by others
al3x
parents: 1058
diff changeset
149 break;
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
150 }
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
151
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
152 if ((err = snd_pcm_info_malloc(&alsa_info)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
153 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
154 printf("alsa-init: memory allocation error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
155 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
156 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
157
1207
bf18175dfad7 ao_subdevice support added
al3x
parents: 1180
diff changeset
158 if (ao_subdevice != NULL)
bf18175dfad7 ao_subdevice support added
al3x
parents: 1180
diff changeset
159 alsa_device = ao_subdevice;
bf18175dfad7 ao_subdevice support added
al3x
parents: 1180
diff changeset
160
1146
a84610bb5476 hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents: 1129
diff changeset
161 if (alsa_device == NULL)
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
162 {
1146
a84610bb5476 hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents: 1129
diff changeset
163 if ((alsa_device = malloc(ALSA_DEVICE_SIZE)) == NULL)
a84610bb5476 hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents: 1129
diff changeset
164 {
a84610bb5476 hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents: 1129
diff changeset
165 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
166 return(0);
a84610bb5476 hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents: 1129
diff changeset
167 }
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
168
1146
a84610bb5476 hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents: 1129
diff changeset
169 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
170 snd_pcm_info_get_device(alsa_info),
a84610bb5476 hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents: 1129
diff changeset
171 snd_pcm_info_get_subdevice(alsa_info));
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
172
1146
a84610bb5476 hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents: 1129
diff changeset
173 snd_pcm_info_free(alsa_info);
a84610bb5476 hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents: 1129
diff changeset
174 }
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
175
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
176 printf("alsa-init: %d soundcard%s found, using: %s\n", cards+1,
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
177 (cards >= 0) ? "" : "s", alsa_device);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
178
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
179 if ((err = snd_pcm_open(&alsa_handler, alsa_device, SND_PCM_STREAM_PLAYBACK,
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
180 0)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
181 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
182 printf("alsa-init: playback open error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
183 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
184 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
185
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
186 snd_pcm_hw_params_malloc(&alsa_hwparams);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
187 snd_pcm_sw_params_malloc(&alsa_swparams);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
188
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
189 if ((err = snd_pcm_hw_params_any(alsa_handler, alsa_hwparams)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
190 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
191 printf("alsa-init: unable to get initial parameters: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
192 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
193 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
194 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
195
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
196 if ((err = snd_pcm_hw_params_set_access(alsa_handler, alsa_hwparams,
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
197 SND_PCM_ACCESS_RW_INTERLEAVED)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
198 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
199 printf("alsa-init: unable to set access type: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
200 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
201 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
202 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
203
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
204 if ((err = snd_pcm_hw_params_set_format(alsa_handler, alsa_hwparams,
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
205 alsa_format)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
206 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
207 printf("alsa-init: unable to set format: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
208 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
209 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
210 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
211
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
212 if ((err = snd_pcm_hw_params_set_channels(alsa_handler, alsa_hwparams,
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
213 ao_channels)) < 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 printf("alsa-init: unable to set channels: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
216 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
217 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
218 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
219
1129
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
220 if ((err = snd_pcm_hw_params_set_rate(alsa_handler, alsa_hwparams,
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
221 ao_samplerate, 0)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
222 {
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
223 printf("alsa-init: unable to set samplerate: %s\n",
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
224 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
225 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
226 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
227
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
228 #ifdef set_period
1115
a16b569f2702 -Wall style cleanups, TEST IT, it can be working by others
al3x
parents: 1058
diff changeset
229 {
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
230 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
231 {
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
232 printf("alsa-init: unable to set periodsize: %s\n",
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
233 snd_strerror(err));
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
234 return(0);
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
235 }
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
236 if ((err = snd_pcm_hw_params_set_periods(alsa_handler, alsa_hwparams, alsa_fragcount, 0)) < 0)
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
237 {
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
238 printf("alsa-init: unable to set periods: %s\n",
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
239 snd_strerror(err));
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
240 return(0);
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
241 }
1115
a16b569f2702 -Wall style cleanups, TEST IT, it can be working by others
al3x
parents: 1058
diff changeset
242 }
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
243 #endif
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
244 #ifdef buffersize
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
245 if ((err = snd_pcm_hw_params_get_buffer_size(alsa_hwparams)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
246 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
247 printf("alsa-init: unable to get buffer size: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
248 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
249 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
250 } else
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
251 {
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
252 ao_buffersize = err;
1146
a84610bb5476 hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents: 1129
diff changeset
253 if (verbose)
a84610bb5476 hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents: 1129
diff changeset
254 printf("alsa-init: got buffersize %i\n", ao_buffersize);
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
255 }
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
256 #endif
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
257
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
258 #ifdef buffertime
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
259 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
260 int alsa_buffer_time = 60;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
261
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
262 if ((err = snd_pcm_hw_params_set_buffer_time_near(alsa_handler, alsa_hwparams,
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
263 alsa_buffer_time, 0)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
264 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
265 printf("alsa-init: unable to set buffer time near: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
266 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
267 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
268 } else
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
269 alsa_buffer_time = err;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
270
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
271 if ((err = snd_pcm_hw_params_set_period_time_near(alsa_handler, alsa_hwparams,
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
272 alsa_buffer_time/ao_bps, 0)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
273 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
274 printf("alsa-init: unable to set period time: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
275 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
276 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
277 }
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
278 printf("alsa-init: buffer_time: %d, period_time :%d\n",
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
279 alsa_buffer_time, err);
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
280 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
281 #endif
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
282
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
283 if ((err = snd_pcm_hw_params(alsa_handler, alsa_hwparams)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
284 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
285 printf("alsa-init: unable to set parameters: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
286 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
287 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
288 }
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
289
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
290 #ifdef sw_params
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
291 if ((err = snd_pcm_sw_params_current(alsa_handler, alsa_swparams)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
292 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
293 printf("alsa-init: unable to get parameters: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
294 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
295 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
296 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
297
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
298 #ifdef set_start_mode
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
299 if ((err = snd_pcm_sw_params_set_start_mode(alsa_handler, alsa_swparams,
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
300 SND_PCM_START_DATA)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
301 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
302 printf("alsa-init: unable to set start mode: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
303 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
304 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
305 }
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
306 #endif
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
307
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
308 if ((err = snd_pcm_sw_params(alsa_handler, alsa_swparams)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
309 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
310 printf("alsa-init: unable to set parameters: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
311 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
312 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
313 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
314
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
315 // snd_pcm_sw_params_default(alsa_handler, alsa_swparams);
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
316 #endif
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
317 if ((err = snd_pcm_prepare(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
318 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
319 printf("alsa-init: pcm prepare error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
320 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
321 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
322
1115
a16b569f2702 -Wall style cleanups, TEST IT, it can be working by others
al3x
parents: 1058
diff changeset
323 #ifdef start
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
324 if ((err = snd_pcm_start(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
325 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
326 printf("alsa-init: pcm start error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
327 if (err != -EPIPE)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
328 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
329 if ((err = snd_pcm_start(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
330 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
331 printf("alsa-init: pcm start error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
332 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
333 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
334 }
1115
a16b569f2702 -Wall style cleanups, TEST IT, it can be working by others
al3x
parents: 1058
diff changeset
335 #endif
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
336 printf("AUDIO: %d Hz/%d channels/%d bpf/%d bytes buffer/%s\n",
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
337 ao_samplerate, ao_channels, ao_bps, ao_buffersize,
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
338 snd_pcm_format_description(alsa_format));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
339 return(1);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
340 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
341
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
342 /* close audio device */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
343 static void uninit()
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
344 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
345 int err;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
346
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
347 if (alsa_device != NULL)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
348 free(alsa_device);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
349
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
350 snd_pcm_hw_params_free(alsa_hwparams);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
351 snd_pcm_sw_params_free(alsa_swparams);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
352
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
353 if ((err = snd_pcm_drain(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
354 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
355 printf("alsa-uninit: pcm drain error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
356 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
357 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
358
1129
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
359 #ifdef start
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
360 if ((err = snd_pcm_reset(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
361 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
362 printf("alsa-uninit: pcm reset error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
363 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
364 }
1129
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
365 #endif
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
366
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
367 if ((err = snd_pcm_close(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
368 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
369 printf("alsa-uninit: pcm close error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
370 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
371 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
372 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
373
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
374 static void audio_pause()
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
375 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
376 int err;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
377
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
378 if ((err = snd_pcm_drain(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
379 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
380 printf("alsa-pause: pcm drain error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
381 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
382 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
383
1129
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
384 #ifdef reset
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
385 if ((err = snd_pcm_reset(alsa_handler)) < 0)
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-pause: pcm reset error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
388 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
389 }
1129
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
390 #endif
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
391 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
392
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
393 static void audio_resume()
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
394 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
395 int err;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
396
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
397 if ((err = snd_pcm_prepare(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
398 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
399 printf("alsa-resume: pcm prepare error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
400 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
401 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
402
1129
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
403 #ifdef start
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
404 if ((err = snd_pcm_start(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
405 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
406 printf("alsa-resume: pcm start error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
407 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
408 }
1129
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
409 #endif
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
410 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
411
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
412 /* stop playing and empty buffers (for seeking/pause) */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
413 static void reset()
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
414 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
415 int err;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
416
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
417 if ((err = snd_pcm_drain(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
418 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
419 printf("alsa-reset: pcm drain error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
420 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
421 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
422
1129
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
423 #ifdef start
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
424 if ((err = snd_pcm_reset(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
425 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
426 printf("alsa-reset: pcm reset error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
427 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
428 }
1129
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
429 #endif
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
430
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
431 if ((err = snd_pcm_prepare(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
432 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
433 printf("alsa-reset: pcm prepare error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
434 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
435 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
436
1129
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
437 #ifdef start
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
438 if ((err = snd_pcm_start(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
439 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
440 printf("alsa-reset: pcm start error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
441 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
442 }
1129
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
443 #endif
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
444 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
445
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
446 /*
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
447 plays 'len' bytes of 'data'
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
448 returns: number of bytes played
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
449 */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
450 static int play(void* data, int len, int flags)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
451 {
1115
a16b569f2702 -Wall style cleanups, TEST IT, it can be working by others
al3x
parents: 1058
diff changeset
452 int got_len;
a16b569f2702 -Wall style cleanups, TEST IT, it can be working by others
al3x
parents: 1058
diff changeset
453
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
454 if ((got_len = snd_pcm_writei(alsa_handler, data, (len/ao_bps))) != (len/ao_bps))
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
455 {
1115
a16b569f2702 -Wall style cleanups, TEST IT, it can be working by others
al3x
parents: 1058
diff changeset
456 if (got_len == -EPIPE) /* underrun? */
1050
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-play: alsa underrun, resetting stream\n");
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
459 if ((got_len = snd_pcm_prepare(alsa_handler)) < 0)
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
460 {
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
461 printf("alsa-play: playback prepare error: %s\n", snd_strerror(got_len));
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
462 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
463 }
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
464 if ((got_len = snd_pcm_writei(alsa_handler, data, (len/ao_bps))) != (len/ao_bps))
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
465 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
466 printf("alsa-play: write error after reset: %s - giving up\n",
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
467 snd_strerror(got_len));
1050
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 return(len); /* 2nd write was ok */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
471 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
472 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
473 return(len);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
474 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
475
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
476 /* how many byes are free in the buffer */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
477 static int get_space()
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
478 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
479 snd_pcm_status_t *status;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
480 int ret;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
481
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
482 if ((ret = snd_pcm_status_malloc(&status)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
483 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
484 printf("alsa-space: memory allocation error: %s\n", snd_strerror(ret));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
485 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
486 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
487
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
488 if ((ret = snd_pcm_status(alsa_handler, status)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
489 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
490 printf("alsa-space: cannot get pcm status: %s\n", snd_strerror(ret));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
491 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
492 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
493
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
494 switch(snd_pcm_status_get_state(status))
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
495 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
496 case SND_PCM_STATE_OPEN:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
497 case SND_PCM_STATE_PREPARED:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
498 case SND_PCM_STATE_RUNNING:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
499 ret = snd_pcm_status_get_avail(status) * ao_bps;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
500 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
501 default:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
502 ret = 0;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
503 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
504
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
505 snd_pcm_status_free(status);
1129
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
506
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
507 if (ret < 0)
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
508 ret = 0;
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
509 return(ret);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
510 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
511
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
512 /* how many unplayed bytes are in the buffer */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
513 static int get_delay()
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
514 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
515 snd_pcm_status_t *status;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
516 int ret;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
517
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
518 if ((ret = snd_pcm_status_malloc(&status)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
519 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
520 printf("alsa-delay: memory allocation error: %s\n", snd_strerror(ret));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
521 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
522 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
523
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
524 if ((ret = snd_pcm_status(alsa_handler, status)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
525 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
526 printf("alsa-delay: cannot get pcm status: %s\n", snd_strerror(ret));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
527 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
528 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
529
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
530 switch(snd_pcm_status_get_state(status))
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
531 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
532 case SND_PCM_STATE_OPEN:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
533 case SND_PCM_STATE_PREPARED:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
534 case SND_PCM_STATE_RUNNING:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
535 ret = snd_pcm_status_get_delay(status) * ao_bps;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
536 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
537 default:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
538 ret = 0;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
539 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
540
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
541 snd_pcm_status_free(status);
1129
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
542
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
543 if (ret < 0)
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
544 ret = 0;
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
545 return(ret);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
546 }