当前位置: 首页>>代码示例>>C++>>正文


C++ snd_hctl_elem_read函数代码示例

本文整理汇总了C++中snd_hctl_elem_read函数的典型用法代码示例。如果您正苦于以下问题:C++ snd_hctl_elem_read函数的具体用法?C++ snd_hctl_elem_read怎么用?C++ snd_hctl_elem_read使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了snd_hctl_elem_read函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: put_infos

int put_infos(int vol_min, int vol_max,
    snd_hctl_elem_t *volume_elem, snd_hctl_elem_t *mute_elem,
    snd_ctl_elem_value_t *volume_ctl, snd_ctl_elem_value_t *mute_ctl,
    char *format)
{
    int volume;
    int volume_percent;
    bool mute_switch;
    char switch_state[4];

    snd_hctl_elem_read(volume_elem, volume_ctl);
    snd_hctl_elem_read(mute_elem, mute_ctl);

    volume = (int)snd_ctl_elem_value_get_integer(volume_ctl, 0);
    mute_switch = (bool)snd_ctl_elem_value_get_boolean(mute_ctl, 0);

    volume_percent = (int)(100.0f * ((float)volume - vol_min) / (vol_max - vol_min));

    if (mute_switch == true)
        sprintf(switch_state, "on");
    else
        sprintf(switch_state, "off");

    if (strstr(format, "%s") == NULL)
        printf(format, volume_percent);
    else if (strstr(format, "%i") == NULL)
        printf(format, switch_state);
    else
        printf(format, switch_state, volume_percent);
    printf("\n");
    fflush(stdout);

    return EXIT_SUCCESS;
}
开发者ID:baskerville,项目名称:sutils,代码行数:34,代码来源:volume.c

示例2: elem_read_enum

static int elem_read_enum(selem_none_t *s)
{
	snd_ctl_elem_value_t *ctl;
	unsigned int idx;
	int err;
	int type;
	selem_ctl_t *c;
	type = CTL_GLOBAL_ENUM;
	if ( (s->selem.caps & (SM_CAP_CENUM | SM_CAP_PENUM)) == (SM_CAP_CENUM | SM_CAP_PENUM) )
		type = CTL_GLOBAL_ENUM;
	else if (s->selem.caps & SM_CAP_PENUM)
		type = CTL_PLAYBACK_ENUM;
	else if (s->selem.caps & SM_CAP_CENUM)
		type = CTL_CAPTURE_ENUM;
	c = &s->ctls[type];
	snd_ctl_elem_value_alloca(&ctl);
	if ((err = snd_hctl_elem_read(c->elem, ctl)) < 0)
		return err;
	for (idx = 0; idx < s->str[0].channels; idx++) {
		unsigned int idx1 = idx;
		if (idx >= c->values)
			idx1 = 0;
		s->str[0].vol[idx] = snd_ctl_elem_value_get_enumerated(ctl, idx1);
	}
	return 0;
}
开发者ID:KeTao,项目名称:alsa-lib,代码行数:26,代码来源:simple_none.c

示例3: set_enum_item_ops

static int set_enum_item_ops(snd_mixer_elem_t *elem,
			     snd_mixer_selem_channel_id_t channel,
			     unsigned int item)
{
	selem_none_t *s = snd_mixer_elem_get_private(elem);
	snd_ctl_elem_value_t *ctl;
	snd_hctl_elem_t *helem;
	int err;
	int type;

	if ((unsigned int) channel >= s->str[0].channels) {
		return -EINVAL;
	}
	type = CTL_GLOBAL_ENUM;
	helem = s->ctls[type].elem;
	if (!helem) {
		type = CTL_PLAYBACK_ENUM;
		helem = s->ctls[type].elem;
	}
	if (!helem) {
		type = CTL_CAPTURE_ENUM;
		helem = s->ctls[type].elem;
	}
	assert(helem);
	if (item >= (unsigned int)s->ctls[type].max) {
		return -EINVAL;
	}
	snd_ctl_elem_value_alloca(&ctl);
	err = snd_hctl_elem_read(helem, ctl);
	if (err < 0) {
		return err;
	}
	snd_ctl_elem_value_set_enumerated(ctl, channel, item);
	return snd_hctl_elem_write(helem, ctl);
}
开发者ID:KeTao,项目名称:alsa-lib,代码行数:35,代码来源:simple_none.c

示例4: _phoneui_utils_sound_volume_mute_changed_cb

static int
_phoneui_utils_sound_volume_mute_changed_cb(snd_hctl_elem_t *elem, unsigned int mask)
{
	snd_ctl_elem_value_t *control;
	enum SoundControlType type;
	int mute;


        if (mask == SND_CTL_EVENT_MASK_REMOVE)
                return 0;
        if (mask & SND_CTL_EVENT_MASK_VALUE) {
                snd_ctl_elem_value_alloca(&control);
                snd_hctl_elem_read(elem, control);
                type = _phoneui_utils_sound_volume_mute_element_to_type(elem);
                if (type != CONTROL_END) {
			mute = phoneui_utils_sound_volume_mute_get(type);
			g_debug("Got alsa mute change for control type '%d', new value: %d",
				type, mute);
			if (_phoneui_utils_sound_volume_mute_changed_callback) {
				_phoneui_utils_sound_volume_mute_changed_callback(type, mute, _phoneui_utils_sound_volume_mute_changed_userdata);
			}
		}
        }
	return 0;
}
开发者ID:shr-project,项目名称:libphone-ui,代码行数:25,代码来源:phoneui-utils-sound.c

示例5: phoneui_utils_sound_volume_raw_get

long
phoneui_utils_sound_volume_raw_get(enum SoundControlType type)
{
	int err;
	long value;
	unsigned int i,count;

	snd_ctl_elem_value_t *control;
	snd_ctl_elem_value_alloca(&control);

	snd_hctl_elem_t *elem;

	count = controls[STATE_INDEX][type].count;
	elem = controls[STATE_INDEX][type].element;
	if (!elem || !count) {
		return 0;
	}

	err = snd_hctl_elem_read(elem, control);
	if (err < 0) {
		g_warning("%s", snd_strerror(err));
		return -1;
	}

	value = 0;
	/* FIXME: possible long overflow */
	for (i = 0 ; i < count ; i++) {
		value += snd_ctl_elem_value_get_integer(control, i);
	}
	value /= count;

	return value;
}
开发者ID:shr-project,项目名称:libphone-ui,代码行数:33,代码来源:phoneui-utils-sound.c

示例6: snd_ctl_elem_id_alloca

bool CAESinkALSA::GetELD(snd_hctl_t *hctl, int device, CAEDeviceInfo& info, bool& badHDMI)
{
  badHDMI = false;

  snd_ctl_elem_id_t    *id;
  snd_ctl_elem_info_t  *einfo;
  snd_ctl_elem_value_t *control;
  snd_hctl_elem_t      *elem;

  snd_ctl_elem_id_alloca(&id);
  memset(id, 0, snd_ctl_elem_id_sizeof());

  snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_PCM);
  snd_ctl_elem_id_set_name     (id, "ELD" );
  snd_ctl_elem_id_set_device   (id, device);
  elem = snd_hctl_find_elem(hctl, id);
  if (!elem)
    return false;

  snd_ctl_elem_info_alloca(&einfo);
  memset(einfo, 0, snd_ctl_elem_info_sizeof());

  if (snd_hctl_elem_info(elem, einfo) < 0)
    return false;

  if (!snd_ctl_elem_info_is_readable(einfo))
    return false;

  if (snd_ctl_elem_info_get_type(einfo) != SND_CTL_ELEM_TYPE_BYTES)
    return false;

  snd_ctl_elem_value_alloca(&control);
  memset(control, 0, snd_ctl_elem_value_sizeof());

  if (snd_hctl_elem_read(elem, control) < 0)
    return false;

  int dataLength = snd_ctl_elem_info_get_count(einfo);
  /* if there is no ELD data, then its a bad HDMI device, either nothing attached OR an invalid nVidia HDMI device
   * OR the driver doesn't properly support ELD (notably ATI/AMD, 2012-05) */
  if (!dataLength)
    badHDMI = true;
  else
    CAEELDParser::Parse(
      (const uint8_t*)snd_ctl_elem_value_get_bytes(control),
      dataLength,
      info
    );

  info.m_deviceType = AE_DEVTYPE_HDMI;
  return true;
}
开发者ID:CharlieMarshall,项目名称:xbmc,代码行数:52,代码来源:AESinkALSA.cpp

示例7: elem_write_switch

static int elem_write_switch(selem_none_t *s, int dir, selem_ctl_type_t type)
{
	snd_ctl_elem_value_t *ctl;
	unsigned int idx;
	int err;
	selem_ctl_t *c = &s->ctls[type];
	snd_ctl_elem_value_alloca(&ctl);
	if ((err = snd_hctl_elem_read(c->elem, ctl)) < 0)
		return err;
	for (idx = 0; idx < c->values; idx++)
		snd_ctl_elem_value_set_integer(ctl, idx, !!(s->str[dir].sw & (1 << idx)));
	if ((err = snd_hctl_elem_write(c->elem, ctl)) < 0)
		return err;
	return 0;
}
开发者ID:KeTao,项目名称:alsa-lib,代码行数:15,代码来源:simple_none.c

示例8: elem_write_switch_constant

static int elem_write_switch_constant(selem_none_t *s, selem_ctl_type_t type, int val)
{
	snd_ctl_elem_value_t *ctl;
	unsigned int idx;
	int err;
	selem_ctl_t *c = &s->ctls[type];
	snd_ctl_elem_value_alloca(&ctl);
	if ((err = snd_hctl_elem_read(c->elem, ctl)) < 0)
		return err;
	for (idx = 0; idx < c->values; idx++)
		snd_ctl_elem_value_set_integer(ctl, idx, !!val);
	if ((err = snd_hctl_elem_write(c->elem, ctl)) < 0)
		return err;
	return 0;
}
开发者ID:KeTao,项目名称:alsa-lib,代码行数:15,代码来源:simple_none.c

示例9: elem_write_volume

static int elem_write_volume(selem_none_t *s, int dir, selem_ctl_type_t type)
{
	snd_ctl_elem_value_t *ctl;
	unsigned int idx;
	int err;
	selem_ctl_t *c = &s->ctls[type];
	snd_ctl_elem_value_alloca(&ctl);
	if ((err = snd_hctl_elem_read(c->elem, ctl)) < 0)
		return err;
	for (idx = 0; idx < c->values; idx++)
		snd_ctl_elem_value_set_integer(ctl, idx, from_user(s, dir, c, s->str[dir].vol[idx]));
	if ((err = snd_hctl_elem_write(c->elem, ctl)) < 0)
		return err;
	return 0;
}
开发者ID:KeTao,项目名称:alsa-lib,代码行数:15,代码来源:simple_none.c

示例10: elem_read_volume

static int elem_read_volume(selem_none_t *s, int dir, selem_ctl_type_t type)
{
	snd_ctl_elem_value_t *ctl;
	unsigned int idx;
	int err;
	selem_ctl_t *c = &s->ctls[type];
	snd_ctl_elem_value_alloca(&ctl);
	if ((err = snd_hctl_elem_read(c->elem, ctl)) < 0)
		return err;
	for (idx = 0; idx < s->str[dir].channels; idx++) {
		unsigned int idx1 = idx;
		if (idx >= c->values)
			idx1 = 0;
		s->str[dir].vol[idx] = to_user(s, dir, c, snd_ctl_elem_value_get_integer(ctl, idx1));
	}
	return 0;
}
开发者ID:KeTao,项目名称:alsa-lib,代码行数:17,代码来源:simple_none.c

示例11: elem_read_route

static int elem_read_route(selem_none_t *s, int dir, selem_ctl_type_t type)
{
	snd_ctl_elem_value_t *ctl;
	unsigned int idx;
	int err;
	selem_ctl_t *c = &s->ctls[type];
	snd_ctl_elem_value_alloca(&ctl);
	if ((err = snd_hctl_elem_read(c->elem, ctl)) < 0)
		return err;
	for (idx = 0; idx < s->str[dir].channels; idx++) {
		unsigned int idx1 = idx;
		if (idx >= c->values)
			idx1 = 0;
		if (!snd_ctl_elem_value_get_integer(ctl, idx1 * c->values + idx1))
			s->str[dir].sw &= ~(1 << idx);
	}
	return 0;
}
开发者ID:KeTao,项目名称:alsa-lib,代码行数:18,代码来源:simple_none.c

示例12: get_enum_item_ops

static int get_enum_item_ops(snd_mixer_elem_t *elem,
			     snd_mixer_selem_channel_id_t channel,
			     unsigned int *itemp)
{
	selem_none_t *s = snd_mixer_elem_get_private(elem);
	snd_ctl_elem_value_t *ctl;
	snd_hctl_elem_t *helem;
	int err;

	if ((unsigned int) channel >= s->str[0].channels)
		return -EINVAL;
	helem = s->ctls[CTL_GLOBAL_ENUM].elem;
	if (!helem) helem = s->ctls[CTL_PLAYBACK_ENUM].elem;
	if (!helem) helem = s->ctls[CTL_CAPTURE_ENUM].elem;
	assert(helem);
	snd_ctl_elem_value_alloca(&ctl);
	err = snd_hctl_elem_read(helem, ctl);
	if (! err)
		*itemp = snd_ctl_elem_value_get_enumerated(ctl, channel);
	return err;
}
开发者ID:KeTao,项目名称:alsa-lib,代码行数:21,代码来源:simple_none.c

示例13: utils_alsa_get_route

/*
 Get the current value of the routing control
 */
static unsigned int utils_alsa_get_route()
{
	int err;
	snd_ctl_elem_value_t *control;
	
	if(utils_alsa_init() || !utils_alsa_route_elem || !utils_alsa_route_elem_id)
		return -1;
	debug("utils_alsa_get_route: start ...\n");

	snd_ctl_elem_value_alloca(&control);
	snd_ctl_elem_value_set_id(control, utils_alsa_route_elem_id);  

	if((err=snd_hctl_elem_read(utils_alsa_route_elem, control))){
		error("utils_alsa_get_route: read failed: %s\n", snd_strerror(err));
		return -1;
	}
	
	unsigned int v=snd_ctl_elem_value_get_enumerated(control, 0);
	debug("utils_alsa_get_route: read value=%ud\n", v);

	return v;
}
开发者ID:amipro,项目名称:sphone,代码行数:25,代码来源:utils.c

示例14: phoneui_utils_sound_volume_mute_get

int
phoneui_utils_sound_volume_mute_get(enum SoundControlType type)
{
	int err;

	snd_ctl_elem_value_t *control;
	snd_ctl_elem_value_alloca(&control);

	snd_hctl_elem_t *elem;


	elem = controls[STATE_INDEX][type].mute_element;
	if (!elem) {
		return -1;
	}

	err = snd_hctl_elem_read(elem, control);
	if (err < 0) {
		g_warning("%s", snd_strerror(err));
		return -1;
	}

	return !snd_ctl_elem_value_get_boolean(control, 0);
}
开发者ID:shr-project,项目名称:libphone-ui,代码行数:24,代码来源:phoneui-utils-sound.c

示例15: selem_write_main

static int selem_write_main(snd_mixer_elem_t *elem)
{
	selem_none_t *s;
	unsigned int idx;
	int err;

	assert(snd_mixer_elem_get_type(elem) == SND_MIXER_ELEM_SIMPLE);
	s = snd_mixer_elem_get_private(elem);

	if (s->ctls[CTL_GLOBAL_ENUM].elem)
		return elem_write_enum(s);

	if (s->ctls[CTL_PLAYBACK_ENUM].elem)
		return elem_write_enum(s);

	if (s->ctls[CTL_CAPTURE_ENUM].elem)
		return elem_write_enum(s);

	if (s->ctls[CTL_SINGLE].elem) {
		if (s->ctls[CTL_SINGLE].type == SND_CTL_ELEM_TYPE_INTEGER)
			err = elem_write_volume(s, SM_PLAY, CTL_SINGLE);
		else
			err = elem_write_switch(s, SM_PLAY, CTL_SINGLE);
		if (err < 0)
			return err;
	}
	if (s->ctls[CTL_GLOBAL_VOLUME].elem) {
		err = elem_write_volume(s, SM_PLAY, CTL_GLOBAL_VOLUME);
		if (err < 0)
			return err;
	}
	if (s->ctls[CTL_GLOBAL_SWITCH].elem) {
		if (s->ctls[CTL_PLAYBACK_SWITCH].elem && s->ctls[CTL_CAPTURE_SWITCH].elem)
			err = elem_write_switch_constant(s, CTL_GLOBAL_SWITCH, 1);
		else
			err = elem_write_switch(s, SM_PLAY, CTL_GLOBAL_SWITCH);
		if (err < 0)
			return err;
	}
	if (s->ctls[CTL_PLAYBACK_VOLUME].elem) {
		err = elem_write_volume(s, SM_PLAY, CTL_PLAYBACK_VOLUME);
		if (err < 0)
			return err;
	}
	if (s->ctls[CTL_PLAYBACK_SWITCH].elem) {
		err = elem_write_switch(s, SM_PLAY, CTL_PLAYBACK_SWITCH);
		if (err < 0)
			return err;
	}
	if (s->ctls[CTL_PLAYBACK_ROUTE].elem) {
		err = elem_write_route(s, SM_PLAY, CTL_PLAYBACK_ROUTE);
		if (err < 0)
			return err;
	}
	if (s->ctls[CTL_CAPTURE_VOLUME].elem) {
		err = elem_write_volume(s, SM_CAPT, CTL_CAPTURE_VOLUME);
		if (err < 0)
			return err;
	}
	if (s->ctls[CTL_CAPTURE_SWITCH].elem) {
		err = elem_write_switch(s, SM_CAPT, CTL_CAPTURE_SWITCH);
		if (err < 0)
			return err;
	}
	if (s->ctls[CTL_CAPTURE_ROUTE].elem) {
		err = elem_write_route(s, SM_CAPT, CTL_CAPTURE_ROUTE);
		if (err < 0)
			return err;
	}
	if (s->ctls[CTL_CAPTURE_SOURCE].elem) {
		snd_ctl_elem_value_t *ctl;
		selem_ctl_t *c = &s->ctls[CTL_CAPTURE_SOURCE];
		snd_ctl_elem_value_alloca(&ctl);
		if ((err = snd_hctl_elem_read(c->elem, ctl)) < 0)
			return err;
		for (idx = 0; idx < c->values; idx++) {
			if (s->str[SM_CAPT].sw & (1 << idx))
				snd_ctl_elem_value_set_enumerated(ctl, idx, s->capture_item);
		}
		if ((err = snd_hctl_elem_write(c->elem, ctl)) < 0)
			return err;
		/* update the element, don't remove */
		err = selem_read(elem);
		if (err < 0)
			return err;
	}
	return 0;
}
开发者ID:KeTao,项目名称:alsa-lib,代码行数:88,代码来源:simple_none.c


注:本文中的snd_hctl_elem_read函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。