111{
113 if (strcmp(cfg, "help") == 0) {
116 }
117 int rc;
118 snd_pcm_hw_params_t *
params;
120 int dir;
121 const char *
name =
"default";
122 char *opts = NULL;
123 int format;
124 char *tmp = NULL;
125
127
128 if (strlen(cfg) > 0) {
129 tmp = strdup(cfg);
130 if (strncmp(tmp, "opts=", strlen("opts")) == 0) {
131 opts = tmp + strlen("opts=");
132 } else {
134 if (strstr(tmp, ":opts=") != NULL) {
135 opts = strstr(tmp, ":opts=") + strlen(":opts=");
136 *strstr(tmp, ":opts=") = '\0';
137 }
138 }
139 }
140
146
147
149
150 if (opts) {
151 char *
item, *save_ptr;
152 while ((
item = strtok_r(opts,
":", &save_ptr)) != NULL) {
153 if (strncmp(
item,
"frames=", strlen(
"frames=")) == 0) {
155 } else {
156 fprintf(stderr,
"[ALSA cap.] Unknown option: %s\n",
item);
158 }
159 opts = NULL;
160 }
161 }
162
163
165 SND_PCM_STREAM_CAPTURE, 0);
166 if (rc < 0) {
167 fprintf(stderr,
MOD_NAME "unable to open pcm device: %s\n",
168 snd_strerror(rc));
170 }
172
173
174 snd_pcm_hw_params_alloca(&
params);
175
176
178 if (rc < 0) {
179 fprintf(stderr,
MOD_NAME "unable to set default parameters: %s\n",
180 snd_strerror(rc));
182 }
183
184
189 }
190
195 break;
196 }
197 }
200 "Cannot find suitable sample format. ");
202 }
203 }
204
210 }
211 }
212
213 if (!snd_pcm_hw_params_test_access(s->
handle,
params, SND_PCM_ACCESS_RW_INTERLEAVED)) {
215 }
else if (!snd_pcm_hw_params_test_access(s->
handle,
params, SND_PCM_ACCESS_RW_NONINTERLEAVED)) {
218 "available only when capturing mono!\n");
220 } else {
222 }
223 } else {
226
227 }
228
229
230
231
233 s->
non_interleaved ? SND_PCM_ACCESS_RW_NONINTERLEAVED : SND_PCM_ACCESS_RW_INTERLEAVED);
234 if (rc < 0) {
235 fprintf(stderr,
MOD_NAME "unable to set interleaved mode: %s\n",
236 snd_strerror(rc));
238 }
239
240
243 format);
244 if (rc < 0) {
245 fprintf(stderr,
MOD_NAME "unable to set capture format: %s\n",
246 snd_strerror(rc));
248 }
249
250
252 rc = snd_pcm_hw_params_set_rate_resample(s->
handle,
254 if(rc < 0) {
255 fprintf(stderr,
MOD_NAME "Warning: Unable to set resampling: %s\n",
256 snd_strerror(rc));
257 }
258
259
261 dir = 0;
264 if (rc < 0) {
265 fprintf(stderr, "[ALSA cap.] unable to set sampling rate (%s %d): %s\n",
266 dir == 0 ? "=" : (dir == -1 ? "<" : ">"),
267 val, snd_strerror(rc));
269 }
270
271
273 if (rc < 0) {
276 } else {
277 fprintf(stderr,
MOD_NAME "unable to set channel count: %s\n",
278 snd_strerror(rc));
280 }
281 }
282
283
284
285
286
287 dir = 0;
288 rc = snd_pcm_hw_params_set_period_size_near(s->
handle,
290 if (rc < 0) {
291 fprintf(stderr, "[ALSA cap.] unable to set frame period (%ld): %s\n",
292 s->
frames, snd_strerror(rc));
293 }
294
295
297 if (rc < 0) {
298 fprintf(stderr,
MOD_NAME "unable to set hw parameters: %s\n",
299 snd_strerror(rc));
301 }
302
303
304 snd_pcm_hw_params_get_period_size(
params, &s->
frames, &dir);
307
309
314
315 free(tmp);
316 return s;
317
319 free(s);
320 free(tmp);
321 return NULL;
322}
static const snd_pcm_format_t bps_to_snd_fmts[]
static int get_rate_near(snd_pcm_t *handle, snd_pcm_hw_params_t *params, unsigned int approx_val)
static void print_alsa_device_info(snd_pcm_t *handle, const char *module_name)
#define DEFAULT_SAMPLE_RATE
static const int bps_preference[]
static void audio_cap_alsa_help(void)
void log_msg(int level, const char *format,...)
void bug_msg(int level, const char *format,...)
prints the error with the advice to report the bug
#define LOG_LEVEL_NOTICE
information that may be interesting
#define LOG_LEVEL_ERROR
general errors
unsigned int audio_capture_bps
unsigned int audio_capture_sample_rate
static struct @19 params[100]
unsigned int audio_capture_channels
#define DEFAULT_AUDIO_CAPTURE_CHANNELS
unsigned int min_device_channels