2 * Copyright (C) 2015 Robin Gareus <robin@gareus.org>
3 * Copyright (C) 2013 Paul Davis
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <alsa/asoundlib.h>
21 #include "pbd/convert.h"
22 #include "ardouralsautil/deviceinfo.h"
27 ARDOUR::get_alsa_device_parameters (const char* device_name, const bool play, ALSADeviceInfo *nfo)
30 snd_pcm_hw_params_t *hw_params;
36 err = snd_pcm_open (&pcm, device_name,
37 play ? SND_PCM_STREAM_PLAYBACK : SND_PCM_STREAM_CAPTURE,
41 fprintf (stderr, "ALSA: Cannot open device '%s': %s\n", device_name, snd_strerror (err));
45 snd_pcm_hw_params_alloca (&hw_params);
46 err = snd_pcm_hw_params_any (pcm, hw_params);
48 errmsg = "Cannot get hardware parameters";
52 err = snd_pcm_hw_params_get_channels_max (hw_params, &nfo->max_channels);
54 errmsg = "Cannot get maximum channels count";
58 err = snd_pcm_hw_params_get_rate_min (hw_params, &nfo->min_rate, NULL);
60 errmsg = "Cannot get minimum rate";
63 err = snd_pcm_hw_params_get_rate_max (hw_params, &nfo->max_rate, NULL);
65 errmsg = "Cannot get maximum rate";
69 err = snd_pcm_hw_params_get_buffer_size_min (hw_params, &nfo->min_size);
71 errmsg = "Cannot get minimum buffer size";
74 err = snd_pcm_hw_params_get_buffer_size_max (hw_params, &nfo->max_size);
76 errmsg = "Cannot get maximum buffer size";
84 fprintf (stderr, "ALSA: %s: %s\n", errmsg.c_str(), snd_strerror (err));