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


C++ snd_mixer_open函数代码示例

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


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

示例1: LOG

bool AlsaMixer::Init( const char* card )
{
	LOG( Logger::LOG_DEBUG, "AlsaMixer::Init( %s )", card);
	int err = 0;
	bool success = false;

	if ( (err = snd_mixer_open(&_handle, 0)) < 0 ) {
		LOG( Logger::LOG_ERROR, "Mixer %s open error: %s", card, snd_strerror(err));
		_handle = NULL;
		goto end;
	}
	if( (err = snd_mixer_attach(_handle, card)) < 0) {
		LOG( Logger::LOG_ERROR, "Mixer %s attach error: %s", card, snd_strerror(err));
		goto end;
	}
	if ((err = snd_mixer_selem_register(_handle, NULL, NULL)) < 0) {
		LOG( Logger::LOG_ERROR, "Mixer register error: %s", snd_strerror(err));
		goto end;
	}
	if ((err = snd_mixer_load(_handle)) < 0) {
		LOG( Logger::LOG_ERROR, "Mixer %s load error: %s", card, snd_strerror(err));
		goto end;
	}
	success = true;
 end:
	if( !success )
	{
		if( _handle ) {
			snd_mixer_close(_handle);
			_handle = NULL;
		}
	}
	return success;
}
开发者ID:Schiiiiins,项目名称:lcu1,代码行数:34,代码来源:AlsaMixer.cpp

示例2: init_alsa

/**
 * init_alsa
 * must be called before other alsa functions
 * only needs to be called once
 * initializes alsa handle
 */
void
init_alsa()
{
        snd_mixer_open(&alsa, 0);
        snd_mixer_attach(alsa, SOUNDCARD);
        snd_mixer_selem_register(alsa, NULL, NULL);
        snd_mixer_load(alsa);

        if (alsa == NULL)
        {
                fprintf(stderr, "error opening sound card " SOUNDCARD);
                return;
        }

        snd_mixer_selem_id_t *sid;
        snd_mixer_selem_id_alloca(&sid);
        snd_mixer_selem_id_set_index(sid, 0);
        snd_mixer_selem_id_set_name(sid, ALSAMIXER);
        alsamixer = snd_mixer_find_selem(alsa, sid);

        if (alsamixer == NULL)
        {
                fprintf(stderr, "error opening alsa mixer " ALSAMIXER);
                return;
        }
}
开发者ID:mjheagle8,项目名称:status,代码行数:32,代码来源:alsa.c

示例3: get_volume

/**
 *  @brief Get the Volume for the master channel.
 *
 *    This function uses the Alsa API to get the volume
 *    for the master channel.
 *
 *  @param [out] ptr pointer to long, output will be between 0 and 99.
 *  @return Void.
 */
void get_volume(long *ptr){
  long min, max;
  snd_mixer_t *handle;
  snd_mixer_selem_id_t *sid;
  const char *card = "default";
  //const char *selem_name = "Master";
  const char *selem_name = "DAC2 Digital Course";

  snd_mixer_open(&handle, 0);
  snd_mixer_attach(handle, card);
  snd_mixer_selem_register(handle, NULL, NULL);
  snd_mixer_load(handle);

  snd_mixer_selem_id_alloca(&sid);
  snd_mixer_selem_id_set_index(sid, 0);
  snd_mixer_selem_id_set_name(sid, selem_name);
  snd_mixer_elem_t* elem = snd_mixer_find_selem(handle, sid);

  snd_mixer_selem_get_playback_volume_range(elem, &min, &max);
  printd("Volume range <%lu,%lu>\n", min, max);
  snd_mixer_selem_get_playback_volume(elem,0,ptr);
  printd("volume val = %lu\n",*ptr);
  *ptr /= (max / 100);
  snd_mixer_close(handle);
}
开发者ID:jsleeman,项目名称:Embedded-Group-Work,代码行数:34,代码来源:volume.c

示例4: set_volume

void set_volume(int vol)
{
	long min, max;
	snd_mixer_t *handlev;
	snd_mixer_selem_id_t *sid;
	const char *card = "default";
	const char *selem_name = "Master";

	if (vol < 1 || vol > 100) {
		printf("ERROR: Volume out of range [0,100] %%\n");
		printf("\tSetting volume to 50%%...\n");
		vol = 50;
	}

	snd_mixer_open(&handlev, 0);
	snd_mixer_attach(handlev, card);
	snd_mixer_selem_register(handlev, NULL, NULL);
	snd_mixer_load(handlev);

	snd_mixer_selem_id_alloca(&sid);
	snd_mixer_selem_id_set_index(sid, 0);
	snd_mixer_selem_id_set_name(sid, selem_name);
	snd_mixer_elem_t *elem = snd_mixer_find_selem(handlev, sid);

	snd_mixer_selem_get_playback_volume_range(elem, &min, &max);
	snd_mixer_selem_set_playback_volume_all(elem, vol * max / 100 + min);

	snd_mixer_close(handlev);
}
开发者ID:ivan-gomez,项目名称:drivers-gdl,代码行数:29,代码来源:player.c

示例5: setVolume

void setVolume(int level)
{
    int volume;
    snd_mixer_t *mixer_handle;

    if (snd_mixer_open (&mixer_handle, card, device) < 0) {
        slogf( _SLOG_SETCODE(_SLOGC_AUDIO, 0), _SLOG_CRITICAL, "Unable to open mixer\n");
        return;
    }

    snd_mixer_group_read(mixer_handle, &group);

    volume = (float)(group.max - group.min) * ( level / 100.0) + group.min;

    if (group.channels & SND_MIXER_CHN_MASK_FRONT_LEFT)
        group.volume.names.front_left = volume;
    if (group.channels & SND_MIXER_CHN_MASK_REAR_LEFT)
        group.volume.names.rear_left = volume;
    if (group.channels & SND_MIXER_CHN_MASK_FRONT_CENTER)
        group.volume.names.front_center = volume;
    if (group.channels & SND_MIXER_CHN_MASK_FRONT_RIGHT)
        group.volume.names.front_right = volume;
    if (group.channels & SND_MIXER_CHN_MASK_REAR_RIGHT)
        group.volume.names.rear_right = volume;
    if (group.channels & SND_MIXER_CHN_MASK_WOOFER)
        group.volume.names.woofer = volume;
    snd_mixer_group_write(mixer_handle, &group);

    snd_mixer_close (mixer_handle);
}
开发者ID:brycepfrimmer,项目名称:Core-Native-Community-Samples,代码行数:30,代码来源:audiopcm.c

示例6: open_mixer

/**
 * Opens the mixer, attaches the alsa card to it,
 * registers the mixer simple element class and
 * loads the mixer elements.
 *
 * @param card HCTL name
 * @param opts Options container
 * @param level mixer level
 * @return the mixer handle, or NULL on failure
 */
static snd_mixer_t *
open_mixer(const char *card, struct snd_mixer_selem_regopt *opts, int level)
{
    int err;
    snd_mixer_t *mixer = NULL;

    DEBUG_PRINT("Card %s: opening mixer", card);

    if ((err = snd_mixer_open(&mixer, 0)) < 0) {
        DEBUG_PRINT("Card %s: mixer open error: %s", card, snd_strerror(err));
        return NULL;
    }
    if (level == 0 && (err = snd_mixer_attach(mixer, card)) < 0) {
        DEBUG_PRINT("Card %s: mixer attach error: %s", card,
                    snd_strerror(err));
        snd_mixer_close(mixer);
        return NULL;
    }
    if ((err = snd_mixer_selem_register(
                   mixer, level > 0 ? opts : NULL, NULL)) < 0) {
        DEBUG_PRINT("Card %s: mixer register error: %s", card,
                    snd_strerror(err));
        snd_mixer_close(mixer);
        return NULL;
    }
    if ((err = snd_mixer_load(mixer)) < 0) {
        DEBUG_PRINT("Card %s: mixer load error: %s", card, snd_strerror(err));
        snd_mixer_close(mixer);
        return NULL;
    }

    return mixer;
}
开发者ID:aarizkuren,项目名称:pnmixer,代码行数:43,代码来源:alsa.c

示例7: volume_up

int volume_up(int vol_min, int vol_max)
{
    long min, max;
    snd_mixer_t *handle;
    snd_mixer_selem_id_t *sid;
    const char *card = "default";
    const char *selem_name = "Master";


    snd_mixer_open(&handle, 0);
    snd_mixer_attach(handle, card);
    snd_mixer_selem_register(handle, NULL, NULL);
    snd_mixer_load(handle);

    snd_mixer_selem_id_alloca(&sid);
    snd_mixer_selem_id_set_index(sid, 0);
    snd_mixer_selem_id_set_name(sid, selem_name);
    snd_mixer_elem_t* elem = snd_mixer_find_selem(handle, sid);

    snd_mixer_selem_get_playback_volume_range(elem, &min, &max);
    
    for (int i = vol_min; i<vol_max; i++) {
      
      int v = i*max /100;
      snd_mixer_selem_set_playback_volume_all(elem, v);
      //printf("min = %d, max= %d, volume = %d\n", min, max, volume);
      usleep(50000);
    }
    snd_mixer_close(handle);
}
开发者ID:alg0hm,项目名称:7x7,代码行数:30,代码来源:volume.c

示例8: volume_set

int volume_set(int volume)
{
    long min, max;
    snd_mixer_t *handle;
    snd_mixer_selem_id_t *sid;
    const char *card = "default";
    //const char *selem_name = "Master";
    const char *selem_name = "Digital";


    snd_mixer_open(&handle, 0);
    snd_mixer_attach(handle, card);
    snd_mixer_selem_register(handle, NULL, NULL);
    snd_mixer_load(handle);

    snd_mixer_selem_id_alloca(&sid);
    snd_mixer_selem_id_set_index(sid, 0);
    snd_mixer_selem_id_set_name(sid, selem_name);
    snd_mixer_elem_t* elem = snd_mixer_find_selem(handle, sid);

    snd_mixer_selem_get_playback_volume_range(elem, &min, &max);
    
      
    int v = volume*max /100;
    snd_mixer_selem_set_playback_volume_all(elem, v);
    snd_mixer_close(handle);
    return v;
}
开发者ID:alg0hm,项目名称:7x7,代码行数:28,代码来源:volume.c

示例9: snd_card_get_index

mixerVolume::mixerVolume(const char *name, const char *card, long volume) {
	snd_mixer_selem_id_t *sid = NULL;
	elem = NULL;
	handle = NULL;
	min = 0;
	max = 100;
	char cardId[10];

	if (!name || !card)
		return;

	int cx = snd_card_get_index(card);
	if (cx < 0 || cx > 31)
		return;
	snprintf(cardId, sizeof(cardId), "hw:%i", cx);

	if (0 > snd_mixer_open(&handle, 0))
		return;
	if (0 > snd_mixer_attach(handle, cardId))
		return;
	if (0 > snd_mixer_selem_register(handle, NULL, NULL))
		return;
	if (0 > snd_mixer_load(handle))
		return;
	snd_mixer_selem_id_alloca(&sid);
	if (!sid)
		return;
	snd_mixer_selem_id_set_index(sid, 0);
	snd_mixer_selem_id_set_name(sid, name);
	elem = snd_mixer_find_selem(handle, sid);
	if (elem) {
		snd_mixer_selem_get_playback_volume_range(elem, &min, &max);
		setVolume(volume);
	}
}
开发者ID:FFTEAM,项目名称:DDT-libstb-hal-cst-next,代码行数:35,代码来源:audio_mixer.cpp

示例10: set_volume

void set_volume(GtkAdjustment *adjustment, gpointer user_data)
{
  int value = (int) 100 - gtk_adjustment_get_value(adjustment);
  g_debug("Setting master volume to: %d", value);

  if(value == 0)
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(s_mute), TRUE);
  else
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(s_mute), FALSE);

  long min, max;
  snd_mixer_t *mix;
  snd_mixer_selem_id_t *sid;
  const char *card = "default";
  const char *selem_name = "Master";

  snd_mixer_open(&mix, 0);
  snd_mixer_attach(mix, card);
  snd_mixer_selem_register(mix, NULL, NULL);
  snd_mixer_load(mix);

  snd_mixer_selem_id_alloca(&sid);
  snd_mixer_selem_id_set_index(sid, 0);
  snd_mixer_selem_id_set_name(sid, selem_name);
  snd_mixer_elem_t* elem = snd_mixer_find_selem(mix, sid);

  snd_mixer_selem_get_playback_volume_range(elem, &min, &max);
  snd_mixer_selem_set_playback_volume_all(elem, value * max / 100);

  snd_mixer_close(mix);

}
开发者ID:tom2901,项目名称:desktop,代码行数:32,代码来源:volume.c

示例11: get_master_volume

static long get_master_volume()
{
    snd_mixer_t *handle;
    snd_mixer_open(&handle, 0);
    snd_mixer_attach(handle, Y50_CTL_NAME);
    snd_mixer_selem_register(handle, NULL, NULL);
    snd_mixer_load(handle);

    snd_mixer_selem_id_t *master_sid;
    const char *master_selem_name = "Master";

    snd_mixer_selem_id_alloca(&master_sid);
    snd_mixer_selem_id_set_index(master_sid, 0);
    snd_mixer_selem_id_set_name(master_sid, master_selem_name);
    snd_mixer_elem_t* elem = snd_mixer_find_selem(handle, master_sid);

    long min, max;
    snd_mixer_selem_get_playback_volume_range(elem, &min, &max);

    long volume;
    snd_mixer_selem_get_playback_volume(elem, SND_MIXER_SCHN_MONO, &volume);

    snd_mixer_close(handle);

    return volume * 100 / max;
}
开发者ID:polter-rnd,项目名称:y50-subwoofer,代码行数:26,代码来源:y50-subwoofer.c

示例12: initMixer

int initMixer()
{
  int result;
  if ((result = snd_mixer_open( &mixerFd, 0)) < 0) {
        printf("sucks1!\n");
        mixerFd = NULL;
        return result;
    }
    
    if ((result = snd_mixer_attach( mixerFd, "default")) < 0) {
        printf("snd_mixer_attach error");
        snd_mixer_close(mixerFd);
        mixerFd = NULL;
        return result;
    }
    if ((result = snd_mixer_selem_register( mixerFd, NULL, NULL)) < 0) {
        printf("snd_mixer_selem_register error");
        snd_mixer_close(mixerFd);
        mixerFd = NULL;
        return result;
    }
    if ((result = snd_mixer_load( mixerFd)) < 0) {
        printf("snd_mixer_load error");
        snd_mixer_close(mixerFd);
        mixerFd = NULL;
        return result;
    }
    return result;
}
开发者ID:trollsid,项目名称:qtextended-device-ezx,代码行数:29,代码来源:ezxaudioplugin.cpp

示例13: snd_mixer_open

char *get_vol(char *buf) {
	long max = 0, min = 0, vol = 0;
	int mute = 0;

	snd_mixer_t *handle;
	snd_mixer_elem_t *pcm_mixer, *mas_mixer;
	snd_mixer_selem_id_t *vol_info, *mute_info;

	snd_mixer_open(&handle, 0);
	snd_mixer_attach(handle, "default");
	snd_mixer_selem_register(handle, NULL, NULL);
	snd_mixer_load(handle);
	snd_mixer_selem_id_malloc(&vol_info);
	snd_mixer_selem_id_malloc(&mute_info);
	snd_mixer_selem_id_set_name(vol_info, VOL_CH);
	snd_mixer_selem_id_set_name(mute_info, VOL_CH);
	pcm_mixer = snd_mixer_find_selem(handle, vol_info);
	mas_mixer = snd_mixer_find_selem(handle, mute_info);
	snd_mixer_selem_get_playback_volume_range((snd_mixer_elem_t *)pcm_mixer, &min, &max);
	snd_mixer_selem_get_playback_volume((snd_mixer_elem_t *)pcm_mixer, SND_MIXER_SCHN_MONO, &vol);
	snd_mixer_selem_get_playback_switch(mas_mixer, SND_MIXER_SCHN_MONO, &mute);
	sprintf(buf, !(mute) ? VOL_MUTE_S : VOL_S, (int)vol * 100 / (int)max);
	if(vol_info)
		snd_mixer_selem_id_free(vol_info);
	if(mute_info)
		snd_mixer_selem_id_free(mute_info);
	if(handle)
		snd_mixer_close(handle);
	return buf;
}
开发者ID:SushiDesu,项目名称:dwmstat,代码行数:30,代码来源:dwmstat.c

示例14: snd_mixer_open

void AlsaPMO::SetVolume(int32 left, int32 right)
{
   int   err;
   snd_mixer_t *pMixer;

   err = snd_mixer_open(&pMixer, m_iCard, 0);
   if (err < 0)
      return;

   if (m_iChannel >= 0)
   {
      err = snd_mixer_group_read(pMixer, &m_group);
      if (err < 0)
         return;

      left = (int)((double)(m_group.max - m_group.min) * 
               (double)left * 0.01) + m_group.min;
      right = (int)((double)(m_group.max - m_group.min) * 
               (double)right * 0.01) + m_group.min;
      for (int chn = 0; chn <= SND_MIXER_CHN_LAST; chn++) {
          if (!(m_group.channels & (1<<chn)))
              continue;

          if (chn == 0)
              m_group.volume.values[chn] = left;
          else
          if (chn == 1)
              m_group.volume.values[chn] = right;
          else
              m_group.volume.values[chn] = (left + right) / 2;
      }
      snd_mixer_group_write(pMixer, &m_group);
   }
   snd_mixer_close(pMixer);
} 
开发者ID:mayhem,项目名称:freeamp,代码行数:35,代码来源:alsapmo.cpp

示例15: mixer_init

static int mixer_init(char *name, char *iname)
{
	int n, i;
	struct pollfd *fds;

	if (snd_mixer_open(&mixer, 0) < 0) {
		fprintf(stderr, "can't open mixer\n");
		exit(1);
	}
	snd_mixer_attach(mixer, "default");
	snd_mixer_selem_register(mixer, NULL, NULL);
	snd_mixer_load(mixer);

	get_element(name, 1, &ch[0]);
	get_element(iname, 0, &ch[1]);
	
	n = snd_mixer_poll_descriptors_count(mixer);
	fds = calloc(n, sizeof(struct pollfd));
	snd_mixer_poll_descriptors(mixer, fds, n);

	for (i = 0; i < n; i++) {
		GIOChannel* channel = g_io_channel_unix_new( fds[i].fd );
		g_io_add_watch(channel, G_IO_IN|G_IO_HUP, on_mixer_event, NULL);
		g_io_channel_unref(channel);
	}
	return 0;
}
开发者ID:pzanoni,项目名称:tray,代码行数:27,代码来源:mixer.c


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