mirror of
				https://github.com/alsa-project/alsa-lib.git
				synced 2025-11-03 09:01:52 -05:00 
			
		
		
		
	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>
This commit is contained in:
		
							parent
							
								
									d85c0d8d46
								
							
						
					
					
						commit
						7f2d6c3aac
					
				
					 1 changed files with 33 additions and 15 deletions
				
			
		| 
						 | 
					@ -355,12 +355,8 @@ static int snd_pcm_hw_hw_refine(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (hw->rates.min > 0) {
 | 
						if (hw->rates.min > 0) {
 | 
				
			||||||
		err = _snd_pcm_hw_param_set_minmax(params, SND_PCM_HW_PARAM_RATE,
 | 
							err = _snd_pcm_hw_param_set_minmax(params, SND_PCM_HW_PARAM_RATE,
 | 
				
			||||||
#if 1 // TODO: find out which arguments are correct
 | 
					 | 
				
			||||||
						   hw->rates.min, 0, hw->rates.max + 1, -1);
 | 
											   hw->rates.min, 0, hw->rates.max + 1, -1);
 | 
				
			||||||
#else
 | 
					
 | 
				
			||||||
						   hw->rates.min, 0, hw->rates.max, 0);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
		if (err < 0)
 | 
					 | 
				
			||||||
			return err;
 | 
								return err;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1773,6 +1769,7 @@ pcm.name {
 | 
				
			||||||
	[format STR]		# Restrict only to the given format
 | 
						[format STR]		# Restrict only to the given format
 | 
				
			||||||
	[channels INT]		# Restrict only to the given channels
 | 
						[channels INT]		# Restrict only to the given channels
 | 
				
			||||||
	[rate INT]		# Restrict only to the given rate
 | 
						[rate INT]		# Restrict only to the given rate
 | 
				
			||||||
 | 
						  or [rate [INT INT]]	# Restrict only to the given rate range (min max)
 | 
				
			||||||
	[chmap MAP]		# Override channel maps; MAP is a string array
 | 
						[chmap MAP]		# Override channel maps; MAP is a string array
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
\endcode
 | 
					\endcode
 | 
				
			||||||
| 
						 | 
					@ -1806,7 +1803,7 @@ int _snd_pcm_hw_open(snd_pcm_t **pcmp, const char *name,
 | 
				
			||||||
	long card = -1, device = 0, subdevice = -1;
 | 
						long card = -1, device = 0, subdevice = -1;
 | 
				
			||||||
	const char *str;
 | 
						const char *str;
 | 
				
			||||||
	int err, sync_ptr_ioctl = 0;
 | 
						int err, sync_ptr_ioctl = 0;
 | 
				
			||||||
	int rate = 0, channels = 0, min_rate = 0, max_rate = 0;
 | 
						int min_rate = 0, max_rate = 0, channels = 0;
 | 
				
			||||||
	snd_pcm_format_t format = SND_PCM_FORMAT_UNKNOWN;
 | 
						snd_pcm_format_t format = SND_PCM_FORMAT_UNKNOWN;
 | 
				
			||||||
	snd_config_t *n;
 | 
						snd_config_t *n;
 | 
				
			||||||
	int nonblock = 1; /* non-block per default */
 | 
						int nonblock = 1; /* non-block per default */
 | 
				
			||||||
| 
						 | 
					@ -1865,12 +1862,37 @@ int _snd_pcm_hw_open(snd_pcm_t **pcmp, const char *name,
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (strcmp(id, "rate") == 0) {
 | 
							if (strcmp(id, "rate") == 0) {
 | 
				
			||||||
			long val;
 | 
								long val;
 | 
				
			||||||
			err = snd_config_get_integer(n, &val);
 | 
								if (snd_config_get_type(n) == SND_CONFIG_TYPE_COMPOUND &&
 | 
				
			||||||
			if (err < 0) {
 | 
								    snd_config_is_array(n)) {
 | 
				
			||||||
				SNDERR("Invalid type for %s", id);
 | 
									snd_config_t *m;
 | 
				
			||||||
				goto fail;
 | 
									err = snd_config_search(n, "0", &m);
 | 
				
			||||||
 | 
									if (err < 0) {
 | 
				
			||||||
 | 
										SNDERR("array expected for rate compound");
 | 
				
			||||||
 | 
										goto fail;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									err = snd_config_get_integer(m, &val);
 | 
				
			||||||
 | 
									if (err < 0) {
 | 
				
			||||||
 | 
										SNDERR("Invalid type for rate.0");
 | 
				
			||||||
 | 
										goto fail;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									min_rate = max_rate = val;
 | 
				
			||||||
 | 
									err = snd_config_search(n, "1", &m);
 | 
				
			||||||
 | 
									if (err >= 0) {
 | 
				
			||||||
 | 
										err = snd_config_get_integer(m, &val);
 | 
				
			||||||
 | 
										if (err < 0) {
 | 
				
			||||||
 | 
											SNDERR("Invalid type for rate.0");
 | 
				
			||||||
 | 
											goto fail;
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										max_rate = val;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									err = snd_config_get_integer(n, &val);
 | 
				
			||||||
 | 
									if (err < 0) {
 | 
				
			||||||
 | 
										SNDERR("Invalid type for %s", id);
 | 
				
			||||||
 | 
										goto fail;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									min_rate = max_rate = val;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			rate = val;
 | 
					 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (strcmp(id, "min_rate") == 0) {
 | 
							if (strcmp(id, "min_rate") == 0) {
 | 
				
			||||||
| 
						 | 
					@ -1958,10 +1980,6 @@ int _snd_pcm_hw_open(snd_pcm_t **pcmp, const char *name,
 | 
				
			||||||
		hw->format = format;
 | 
							hw->format = format;
 | 
				
			||||||
	if (channels > 0)
 | 
						if (channels > 0)
 | 
				
			||||||
		hw->channels = channels;
 | 
							hw->channels = channels;
 | 
				
			||||||
	if ((min_rate == 0) && (max_rate == 0)) {
 | 
					 | 
				
			||||||
		min_rate = rate;
 | 
					 | 
				
			||||||
		max_rate = rate;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if (min_rate > 0) {
 | 
						if (min_rate > 0) {
 | 
				
			||||||
		hw->rates.min = min_rate;
 | 
							hw->rates.min = min_rate;
 | 
				
			||||||
		hw->rates.max = max_rate;
 | 
							hw->rates.max = max_rate;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue