⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 alsamixer.c

📁 ALSA驱动的一些调试测试工具
💻 C
📖 第 1 页 / 共 5 页
字号:
    vleft = mixer_conv(vleft, vmin, vmax, 0, 100);    if (chn_right != SND_MIXER_SCHN_UNKNOWN) {      snd_mixer_selem_get_capture_volume(elem, chn_right, &vright);      vright = mixer_conv(vright, vmin, vmax, 0, 100);    } else {      vright = vleft;    }  }    /* update the focused full bar name   */  if (elem_index == mixer_focus_elem) {    char tmp[50];    /* control muted? */    swl = swr = 1;    extra_info = "";    if (mixer_type[elem_index] & MIXER_ELEM_MUTE_SWITCH) {      snd_mixer_selem_get_playback_switch(elem, chn_left, &swl);      swr = swl;      if (chn_right != SND_MIXER_SCHN_UNKNOWN)	snd_mixer_selem_get_playback_switch(elem, chn_right, &swr);      extra_info = !swl && !swr ? " [Off]" : "";    }    if (type == MIXER_ELEM_ENUM || type == MIXER_ELEM_CAPTURE_ENUM) {      /* FIXME: should show the item names of secondary and later channels... */      unsigned int eidx, length;      tmp[0]=' ';      tmp[1]='[';      if (! snd_mixer_selem_get_enum_item(elem, 0, &eidx) &&	  ! snd_mixer_selem_get_enum_item_name(elem, eidx, sizeof(tmp) - 3, tmp+2)) {	tmp[sizeof(tmp)-2] = 0;	length=strlen(tmp);	tmp[length]=']';	tmp[length+1]=0;	extra_info = tmp;      }    }    if (type != MIXER_ELEM_CAPTURE && snd_mixer_selem_has_playback_volume(elem)) {	long vdbleft, vdbright;	unsigned int length;	if (!snd_mixer_selem_get_playback_dB(elem, chn_left, &vdbleft)) {		char tmpl[10], tmpr[10];		dB_value(tmpl, vdbleft);		if ((chn_right != SND_MIXER_SCHN_UNKNOWN) &&		     (!snd_mixer_selem_get_playback_dB(elem, chn_right, &vdbright))) {			dB_value(tmpr, vdbright);			snprintf(tmp, 48, " [dB gain=%s, %s]", tmpl, tmpr);		} else {			snprintf(tmp, 48, " [dB gain=%s]", tmpl);		}		tmp[sizeof(tmp)-2] = 0;		length=strlen(tmp);		tmp[length+1]=0;		extra_info = tmp;	}    }    if (type == MIXER_ELEM_CAPTURE && snd_mixer_selem_has_capture_volume(elem)) {	long vdbleft, vdbright;	unsigned int length;	if (!snd_mixer_selem_get_capture_dB(elem, chn_left, &vdbleft)) {		char tmpl[10], tmpr[10];		dB_value(tmpl, vdbleft);		if ((chn_right != SND_MIXER_SCHN_UNKNOWN) &&		     (!snd_mixer_selem_get_capture_dB(elem, chn_right, &vdbright))) {			dB_value(tmpr, vdbright);			snprintf(tmp, 48, " [dB gain=%s, %s]", tmpl, tmpr);		} else {			snprintf(tmp, 48, " [dB gain=%s]", tmpl);		}		tmp[sizeof(tmp)-2] = 0;		length=strlen(tmp);		tmp[length+1]=0;		extra_info = tmp;	}    }    display_item_info(elem_index, sid, extra_info);  }  /* get channel bar position   */  if (!mixer_cbar_get_pos (elem_index, &x, &y))    return;  /* channel bar name   */  display_item_name(x, y, elem_index, sid);  y--;    /* enum list? */  if (type == MIXER_ELEM_ENUM || type == MIXER_ELEM_CAPTURE_ENUM) {    display_enum_list(elem, y, x);    return; /* no more to display */  }   /* current channel values   */  mixer_dc (DC_BACK);  mvaddstr (y, x, "         ");  if (mixer_type[elem_index] & MIXER_ELEM_HAS_VOLUME) {    char string[4];    mixer_dc (DC_TEXT);    if (chn_right == SND_MIXER_SCHN_UNKNOWN) {      /* mono */      snprintf (string, sizeof(string), "%ld", vleft);      mvaddstr (y, x + 4 - strlen (string) / 2, string);    } else {      /* stereo */      snprintf (string, sizeof(string), "%ld", vleft);      mvaddstr (y, x + 3 - strlen (string), string);      mixer_dc (DC_CBAR_FRAME);      mvaddch (y, x + 3, '<');      mvaddch (y, x + 4, '>');      mixer_dc (DC_TEXT);      snprintf (string, sizeof(string), "%ld", vright);      mvaddstr (y, x + 5, string);    }  }  y--;    /* capture input?   */  if (mixer_view == VIEW_CAPTURE || mixer_view == VIEW_CHANNELS) {    if ((mixer_type[elem_index] & MIXER_ELEM_CAPTURE_SWITCH) &&	snd_mixer_selem_has_capture_switch(elem)) {      int has_r_sw = chn_right != SND_MIXER_SCHN_UNKNOWN &&	snd_mixer_selem_has_capture_channel(elem, chn_right);      snd_mixer_selem_get_capture_switch(elem, chn_left, &swl);      if (has_r_sw)	snd_mixer_selem_get_capture_switch(elem, chn_right, &swr);      else	swr = swl;      draw_capture_switch(x, y, elem_index, swl, swr);    } else      draw_blank(x, y, 2);    y--;  }  /* mute switch */  if (mixer_view == VIEW_PLAYBACK || mixer_view == VIEW_CHANNELS) {    if (mixer_type[elem_index] & MIXER_ELEM_MUTE_SWITCH) {      snd_mixer_selem_get_playback_switch(elem, chn_left, &swl);      if (chn_right != SND_MIXER_SCHN_UNKNOWN)	snd_mixer_selem_get_playback_switch(elem, chn_right, &swr);      else	swr = swl;      draw_playback_switch(x, y, elem_index, swl, swr);    } else {      mixer_dc (DC_CBAR_FRAME);      mvaddstr (y, x + 2, "    ");      draw_blank(x, y - 1, 2);    }    y -= 2;  }  /* left/right volume bar   */  if (mixer_type[elem_index] & MIXER_ELEM_HAS_VOLUME)    draw_volume_bar(x, y, elem_index, vleft, vright);  else {    if (mixer_view == VIEW_CAPTURE)      mvaddstr (y, x + 2, "    ");    draw_blank(x, y - 1, mixer_cbar_height + 1);  }}static voidmixer_update_cbars (void){  static int o_x = 0;  static int o_y = 0;  int i, x, y;    display_view_info();  if (!mixer_cbar_get_pos (mixer_focus_elem, &x, &y))    {      if (mixer_focus_elem < mixer_first_vis_elem)	mixer_first_vis_elem = mixer_focus_elem;      else if (mixer_focus_elem >= mixer_first_vis_elem + mixer_n_vis_elems)	mixer_first_vis_elem = mixer_focus_elem - mixer_n_vis_elems + 1;      mixer_cbar_get_pos (mixer_focus_elem, &x, &y);    }  if (mixer_first_vis_elem + mixer_n_vis_elems >= mixer_n_view_elems) {     mixer_first_vis_elem = mixer_n_view_elems - mixer_n_vis_elems;     if (mixer_first_vis_elem < 0)       mixer_first_vis_elem = 0;     mixer_cbar_get_pos (mixer_focus_elem, &x, &y);  }  mixer_write_cbar(mixer_focus_elem);  for (i = 0; i < mixer_n_vis_elems; i++) {    if (i + mixer_first_vis_elem >= mixer_n_view_elems)      continue;    mixer_update_cbar (i + mixer_first_vis_elem);  }    /* draw focused cbar   */  if (mixer_have_old_focus)    {      mixer_dc (DC_BACK);      mvaddstr (o_y, o_x, " ");      mvaddstr (o_y, o_x + 9, " ");    }  o_x = x - 1;  o_y = y;  mixer_dc (DC_FOCUS);  mvaddstr (o_y, o_x, "<");  mvaddstr (o_y, o_x + 9, ">");  mixer_have_old_focus = 1;}static voidmixer_draw_frame (void){  char string[128];  int i;  int max_len;    /* card name   */  mixer_dc (DC_PROMPT);  mvaddstr (1, 2, "Card: ");  mixer_dc (DC_TEXT);  sprintf (string, "%s", mixer_card_name);  max_len = mixer_max_x - 2 - 6 - 2;  if ((int)strlen (string) > max_len)    string[max_len] = 0;  addstr (string);    /* device name   */  mixer_dc (DC_PROMPT);  mvaddstr (2, 2, "Chip: ");  mixer_dc (DC_TEXT);  sprintf (string, "%s", mixer_device_name);  max_len = mixer_max_x - 2 - 6 - 2;  if ((int)strlen (string) > max_len)    string[max_len] = 0;  addstr (string);  /* lines   */  mixer_dc (DC_FRAME);  for (i = 1; i < mixer_max_y - 1; i++)    {      mvaddch (i, 0, ACS_VLINE);      mvaddch (i, mixer_max_x - 1, ACS_VLINE);    }  for (i = 1; i < mixer_max_x - 1; i++)    {      mvaddch (0, i, ACS_HLINE);      mvaddch (mixer_max_y - 1, i, ACS_HLINE);    }    /* corners   */  mvaddch (0, 0, ACS_ULCORNER);  mvaddch (0, mixer_max_x - 1, ACS_URCORNER);  mvaddch (mixer_max_y - 1, 0, ACS_LLCORNER);  if (!mixer_no_lrcorner)    mvaddch (mixer_max_y - 1, mixer_max_x - 1, ACS_LRCORNER);  else    {      mvaddch (mixer_max_y - 2, mixer_max_x - 1, ACS_LRCORNER);      mvaddch (mixer_max_y - 2, mixer_max_x - 2, ACS_ULCORNER);      mvaddch (mixer_max_y - 1, mixer_max_x - 2, ACS_LRCORNER);    }  /* left/right scroll indicators */  switch (mixer_view) {  case VIEW_PLAYBACK:  case VIEW_CAPTURE:  case VIEW_CHANNELS:    if (mixer_cbar_height > 0) {      int ind_hgt = (mixer_cbar_height + 1) / 2;      int ind_ofs = mixer_max_y / 2 - ind_hgt/2;      /* left scroll possible? */      if (mixer_first_vis_elem > 0) {	for (i = 0; i < ind_hgt; i++)	  mvaddch (i + ind_ofs, 0, '<');      }      /* right scroll possible? */      if (mixer_first_vis_elem + mixer_n_vis_elems < mixer_n_view_elems) {	for (i = 0; i < ind_hgt; i++)	  mvaddch (i + ind_ofs, mixer_max_x - 1, '>');      }    }    break;  default:    break;  }  /* program title   */  sprintf (string, "%s v%s (Press Escape to quit)", PRGNAME_UPPER, VERSION);  max_len = strlen (string);  if (mixer_max_x >= max_len + 4)    {      mixer_dc (DC_PROMPT);      mvaddch (0, mixer_max_x / 2 - max_len / 2 - 1, '[');      mvaddch (0, mixer_max_x / 2 - max_len / 2 + max_len, ']');    }  if (mixer_max_x >= max_len + 2)    {      mixer_dc (DC_TEXT);      mvaddstr (0, mixer_max_x / 2 - max_len / 2, string);    }}static char*mixer_offset_text (char **t,		   int	  col,		   int	 *length){  char *p = *t;  char *r;  while (*p && *p != '\n' && col--)    p++;  if (*p == '\n' || !*p)    {      if (*p == '\n')	p++;      *length = 0;      *t = p;      return p;    }  r = p;  while (*r && *r != '\n' && (*length)--)    r++;  *length = r - p;  while (*r && *r != '\n')    r++;  if (*r == '\n')    r++;  *t = r;  return p;}static voidmixer_show_text (char *title,		 char *text,		 int  *xoffs,		 int  *yoffs){  int tlines = 0, tcols = 0;  float hscroll, vscroll;  float hoffs, voffs;  char *p, *text_offs = text;  int x1, x2, y1, y2;  int i, n, l, r;  unsigned long block, stipple;  /* coords   */  x1 = 2;  x2 = mixer_max_x - 3;  y1 = 4;  y2 = mixer_max_y - 2;  if ((y2 - y1) < 3 || (x2 - x1) < 3)    return;  /* text dimensions   */  l = 0;  for (p = text; *p; p++)    if (*p == '\n')      {	tlines++;	tcols = MAX (l, tcols);	l = 0;      }    else      l++;  tcols = MAX (l, tcols);  if (p > text && *(p - 1) != '\n')    tlines++;  /* scroll areas / offsets   */  l = x2 - x1 - 2;  if (l > tcols)    {      x1 += (l - tcols) / 2;      x2 = x1 + tcols + 1;    }  if (mixer_hscroll_delta)    {      *xoffs += mixer_hscroll_delta;      mixer_hscroll_delta = 0;      if (*xoffs < 0)	{	  *xoffs = 0;	  beep ();	}      else if (*xoffs > tcols - l - 1)	{	  *xoffs = MAX (0, tcols - l - 1);	  beep ();	}    }  if (tcols - l - 1 <= 0)    {      hscroll = 1;      hoffs = 0;    }  else    {      hscroll = ((float) l) / tcols;      hoffs = ((float) *xoffs) / (tcols - l - 1);    }  l = y2 - y1 - 2;  if (l > tlines)    {      y1 += (l - tlines) / 2;      y2 = y1 + tlines + 1;    }  if (mixer_vscroll_delta)    {      *yoffs += mixer_vscroll_delta;      mixer_vscroll_delta = 0;      if (*yoffs < 0)	{	  *yoffs = 0;	  beep ();	}      else if (*yoffs > tlines - l - 1)	{	  *yoffs = MAX (0, tlines - l - 1);	  beep ();	}    }  if (tlines - l - 1 <= 0)    {      voffs = 0;      vscroll = 1;    }  else    {      vscroll = ((float) l) / tlines;      voffs = ((float) *yoffs) / (tlines - l - 1);    }  /* colors   */  mixer_dc (DC_ANY_4);  /* corners   */  mvaddch (y2, x2, ACS_LRCORNER);  mvaddch (y2, x1, ACS_LLCORNER);  mvaddch (y1, x1, ACS_ULCORNER);  mvaddch (y1, x2, ACS_URCORNER);  /* left + upper border   */  for (i = y1 + 1; i < y2; i++)    mvaddch (i, x1, ACS_VLINE);  for (i = x1 + 1; i < x2; i++)    mvaddch (y1, i, ACS_HLINE);  if (title)    {      l = strlen (title);      if (l <= x2 - x1 - 3)	{	  mvaddch (y1, x1 + 1 + (x2 - x1 - l) / 2 - 1, '[');	  mvaddch (y1, x1 + 1 + (x2 - x1 - l) / 2 + l, ']');	}      if (l <= x2 - x1 - 1)	{	  mixer_dc (DC_CBAR_LABEL);	  mvaddstr (y1, x1 + 1 + (x2 - x1 - l) / 2, title);	}      mixer_dc (DC_ANY_4);    }  stipple = ACS_CKBOARD;  block = ACS_BLOCK;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -