pcm: hw: change rate range syntax
Allow three configuration types:
rate 48000 # single rate
rate [ 48000 ] # single rate (2nd)
rate [ 44100 48000 ] # range
Fixes: https://github.com/alsa-project/alsa-lib/pull/191
Fixes: ac04cb63 ("hw: add "min_rate" and "max_rate" as alternatives to single "rate" parameter")
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Jaroslav Kysela
1 year, 11 months ago
354 | 354 | } |
355 | 355 | if (hw->rates.min > 0) { |
356 | 356 | err = _snd_pcm_hw_param_set_minmax(params, SND_PCM_HW_PARAM_RATE, |
357 | #if 1 // TODO: find out which arguments are correct | |
358 | 357 | hw->rates.min, 0, hw->rates.max + 1, -1); |
359 | #else | |
360 | hw->rates.min, 0, hw->rates.max, 0); | |
361 | #endif | |
362 | if (err < 0) | |
358 | ||
363 | 359 | return err; |
364 | 360 | } |
365 | 361 | |
1772 | 1768 | [format STR] # Restrict only to the given format |
1773 | 1769 | [channels INT] # Restrict only to the given channels |
1774 | 1770 | [rate INT] # Restrict only to the given rate |
1771 | or [rate [INT INT]] # Restrict only to the given rate range (min max) | |
1775 | 1772 | [chmap MAP] # Override channel maps; MAP is a string array |
1776 | 1773 | } |
1777 | 1774 | \endcode |
1805 | 1802 | long card = -1, device = 0, subdevice = -1; |
1806 | 1803 | const char *str; |
1807 | 1804 | int err, sync_ptr_ioctl = 0; |
1808 | int rate = 0, channels = 0, min_rate = 0, max_rate = 0; | |
1805 | int min_rate = 0, max_rate = 0, channels = 0; | |
1809 | 1806 | snd_pcm_format_t format = SND_PCM_FORMAT_UNKNOWN; |
1810 | 1807 | snd_config_t *n; |
1811 | 1808 | int nonblock = 1; /* non-block per default */ |
1864 | 1861 | } |
1865 | 1862 | if (strcmp(id, "rate") == 0) { |
1866 | 1863 | long val; |
1867 | err = snd_config_get_integer(n, &val); | |
1868 | if (err < 0) { | |
1869 | SNDERR("Invalid type for %s", id); | |
1870 | goto fail; | |
1864 | if (snd_config_get_type(n) == SND_CONFIG_TYPE_COMPOUND && | |
1865 | snd_config_is_array(n)) { | |
1866 | snd_config_t *m; | |
1867 | err = snd_config_search(n, "0", &m); | |
1868 | if (err < 0) { | |
1869 | SNDERR("array expected for rate compound"); | |
1870 | goto fail; | |
1871 | } | |
1872 | err = snd_config_get_integer(m, &val); | |
1873 | if (err < 0) { | |
1874 | SNDERR("Invalid type for rate.0"); | |
1875 | goto fail; | |
1876 | } | |
1877 | min_rate = max_rate = val; | |
1878 | err = snd_config_search(n, "1", &m); | |
1879 | if (err >= 0) { | |
1880 | err = snd_config_get_integer(m, &val); | |
1881 | if (err < 0) { | |
1882 | SNDERR("Invalid type for rate.0"); | |
1883 | goto fail; | |
1884 | } | |
1885 | max_rate = val; | |
1886 | } | |
1887 | } else { | |
1888 | err = snd_config_get_integer(n, &val); | |
1889 | if (err < 0) { | |
1890 | SNDERR("Invalid type for %s", id); | |
1891 | goto fail; | |
1892 | } | |
1893 | min_rate = max_rate = val; | |
1871 | 1894 | } |
1872 | rate = val; | |
1873 | 1895 | continue; |
1874 | 1896 | } |
1875 | 1897 | if (strcmp(id, "min_rate") == 0) { |
1957 | 1979 | hw->format = format; |
1958 | 1980 | if (channels > 0) |
1959 | 1981 | hw->channels = channels; |
1960 | if ((min_rate == 0) && (max_rate == 0)) { | |
1961 | min_rate = rate; | |
1962 | max_rate = rate; | |
1963 | } | |
1964 | 1982 | if (min_rate > 0) { |
1965 | 1983 | hw->rates.min = min_rate; |
1966 | 1984 | hw->rates.max = max_rate; |