mirror of
				https://github.com/alsa-project/alsa-lib.git
				synced 2025-11-03 09:01:52 -05:00 
			
		
		
		
	Add snd_pcm_parse_control_id()
Added a new function snd_pcm_parse_control_id() for the user controls. This can be used in external plugins, too.
This commit is contained in:
		
							parent
							
								
									227441b2c8
								
							
						
					
					
						commit
						73008debc3
					
				
					 3 changed files with 192 additions and 116 deletions
				
			
		| 
						 | 
				
			
			@ -91,8 +91,6 @@ static unsigned short preset_dB_value[PRESET_RESOLUTION] = {
 | 
			
		|||
	0xdbd5, 0xe0ab, 0xe59c, 0xeaa9, 0xefd3, 0xf519, 0xfa7d, 0xffff,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif /* DOC_HIDDEN */
 | 
			
		||||
 | 
			
		||||
/* (32bit x 16bit) >> 16 */
 | 
			
		||||
typedef union {
 | 
			
		||||
	int i;
 | 
			
		||||
| 
						 | 
				
			
			@ -118,6 +116,7 @@ static inline int MULTI_DIV_int(int a, unsigned short b)
 | 
			
		|||
/* (16bit x 16bit) >> 16 */
 | 
			
		||||
#define MULTI_DIV_short(src,scale) (((int)(src) * (scale)) >> VOL_SCALE_SHIFT)
 | 
			
		||||
 | 
			
		||||
#endif /* DOC_HIDDEN */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * apply volumue attenuation
 | 
			
		||||
| 
						 | 
				
			
			@ -662,118 +661,9 @@ int snd_pcm_softvol_open(snd_pcm_t **pcmp, const char *name,
 | 
			
		|||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * parse card index and id for the softvol control
 | 
			
		||||
 */
 | 
			
		||||
static int parse_control_id(snd_config_t *conf, snd_ctl_elem_id_t *ctl_id, int *cardp,
 | 
			
		||||
			    int *cchannelsp)
 | 
			
		||||
{
 | 
			
		||||
	snd_config_iterator_t i, next;
 | 
			
		||||
	int iface = SND_CTL_ELEM_IFACE_MIXER;
 | 
			
		||||
	const char *name = NULL;
 | 
			
		||||
	long index = 0;
 | 
			
		||||
	long device = -1;
 | 
			
		||||
	long subdevice = -1;
 | 
			
		||||
	int err;
 | 
			
		||||
 | 
			
		||||
	*cardp = -1;
 | 
			
		||||
	*cchannelsp = 2;
 | 
			
		||||
	snd_config_for_each(i, next, conf) {
 | 
			
		||||
		snd_config_t *n = snd_config_iterator_entry(i);
 | 
			
		||||
		const char *id;
 | 
			
		||||
		if (snd_config_get_id(n, &id) < 0)
 | 
			
		||||
			continue;
 | 
			
		||||
		if (strcmp(id, "comment") == 0)
 | 
			
		||||
			continue;
 | 
			
		||||
		if (strcmp(id, "card") == 0) {
 | 
			
		||||
			const char *str;
 | 
			
		||||
			long v;
 | 
			
		||||
			if ((err = snd_config_get_integer(n, &v)) < 0) {
 | 
			
		||||
				if ((err = snd_config_get_string(n, &str)) < 0) {
 | 
			
		||||
					SNDERR("Invalid field %s", id);
 | 
			
		||||
					goto _err;
 | 
			
		||||
				}
 | 
			
		||||
				*cardp = snd_card_get_index(str);
 | 
			
		||||
				if (*cardp < 0) {
 | 
			
		||||
					SNDERR("Cannot get index for %s", str);
 | 
			
		||||
					err = *cardp;
 | 
			
		||||
					goto _err;
 | 
			
		||||
				}
 | 
			
		||||
			} else
 | 
			
		||||
				*cardp = v;
 | 
			
		||||
			continue;
 | 
			
		||||
		}
 | 
			
		||||
		if (strcmp(id, "iface") == 0 || strcmp(id, "interface") == 0) {
 | 
			
		||||
			if ((err = snd_config_get_bool(n)) < 0)
 | 
			
		||||
				goto _err;
 | 
			
		||||
			iface = err;
 | 
			
		||||
			continue;
 | 
			
		||||
		}
 | 
			
		||||
		if (strcmp(id, "name") == 0) {
 | 
			
		||||
			if ((err = snd_config_get_string(n, &name)) < 0) {
 | 
			
		||||
				SNDERR("field %s is not a string", id);
 | 
			
		||||
				goto _err;
 | 
			
		||||
			}
 | 
			
		||||
			continue;
 | 
			
		||||
		}
 | 
			
		||||
		if (strcmp(id, "index") == 0) {
 | 
			
		||||
			if ((err = snd_config_get_integer(n, &index)) < 0) {
 | 
			
		||||
				SNDERR("field %s is not an integer", id);
 | 
			
		||||
				goto _err;
 | 
			
		||||
			}
 | 
			
		||||
			continue;
 | 
			
		||||
		}
 | 
			
		||||
		if (strcmp(id, "device") == 0) {
 | 
			
		||||
			if ((err = snd_config_get_integer(n, &device)) < 0) {
 | 
			
		||||
				SNDERR("field %s is not an integer", id);
 | 
			
		||||
				goto _err;
 | 
			
		||||
			}
 | 
			
		||||
			continue;
 | 
			
		||||
		}
 | 
			
		||||
		if (strcmp(id, "subdevice") == 0) {
 | 
			
		||||
			if ((err = snd_config_get_integer(n, &subdevice)) < 0) {
 | 
			
		||||
				SNDERR("field %s is not an integer", id);
 | 
			
		||||
				goto _err;
 | 
			
		||||
			}
 | 
			
		||||
			continue;
 | 
			
		||||
		}
 | 
			
		||||
		if (strcmp(id, "count") == 0) {
 | 
			
		||||
			long v;
 | 
			
		||||
			if ((err = snd_config_get_integer(n, &v)) < 0) {
 | 
			
		||||
				SNDERR("field %s is not an integer", id);
 | 
			
		||||
				goto _err;
 | 
			
		||||
			}
 | 
			
		||||
			if (v < 1 || v > 2) {
 | 
			
		||||
				SNDERR("Invalid count %ld", v);
 | 
			
		||||
				goto _err;
 | 
			
		||||
			}
 | 
			
		||||
			*cchannelsp = v;
 | 
			
		||||
			continue;
 | 
			
		||||
		}
 | 
			
		||||
		SNDERR("Unknown field %s", id);
 | 
			
		||||
		return -EINVAL;
 | 
			
		||||
	}
 | 
			
		||||
	if (name == NULL) {
 | 
			
		||||
		SNDERR("Missing control name");
 | 
			
		||||
		err = -EINVAL;
 | 
			
		||||
		goto _err;
 | 
			
		||||
	}
 | 
			
		||||
	if (device < 0)
 | 
			
		||||
		device = 0;
 | 
			
		||||
	if (subdevice < 0)
 | 
			
		||||
		subdevice = 0;
 | 
			
		||||
 | 
			
		||||
	snd_ctl_elem_id_set_interface(ctl_id, iface);
 | 
			
		||||
	snd_ctl_elem_id_set_name(ctl_id, name);
 | 
			
		||||
	snd_ctl_elem_id_set_index(ctl_id, index);
 | 
			
		||||
	snd_ctl_elem_id_set_device(ctl_id, device);
 | 
			
		||||
	snd_ctl_elem_id_set_subdevice(ctl_id, subdevice);
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
 | 
			
		||||
 _err:
 | 
			
		||||
	return err;
 | 
			
		||||
}
 | 
			
		||||
/* in pcm_misc.c */
 | 
			
		||||
int snd_pcm_parse_control_id(snd_config_t *conf, snd_ctl_elem_id_t *ctl_id, int *cardp,
 | 
			
		||||
			     int *cchannelsp, int *hwctlp);
 | 
			
		||||
 | 
			
		||||
/*! \page pcm_plugins
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -802,7 +692,7 @@ pcm.name {
 | 
			
		|||
        }
 | 
			
		||||
        control {
 | 
			
		||||
	        name STR        # control element id string
 | 
			
		||||
		[card INT]      # control card index
 | 
			
		||||
		[card STR]      # control card index
 | 
			
		||||
		[iface STR]     # interface of the element
 | 
			
		||||
		[index INT]     # index of the element
 | 
			
		||||
		[device INT]    # device number of the element
 | 
			
		||||
| 
						 | 
				
			
			@ -919,7 +809,7 @@ int _snd_pcm_softvol_open(snd_pcm_t **pcmp, const char *name,
 | 
			
		|||
	if (err < 0)
 | 
			
		||||
		return err;
 | 
			
		||||
	snd_ctl_elem_id_alloca(&ctl_id);
 | 
			
		||||
	if ((err = parse_control_id(control, ctl_id, &card, &cchannels)) < 0) {
 | 
			
		||||
	if ((err = snd_pcm_parse_control_id(control, ctl_id, &card, &cchannels, NULL)) < 0) {
 | 
			
		||||
		snd_pcm_close(spcm);
 | 
			
		||||
		return err;
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue