Changeset 4740:f3abf82e2ead in roaraudio for roarclients


Ignore:
Timestamp:
01/31/11 02:21:19 (13 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

Added support for UNMAPPED volume control (Closes: #55)

Location:
roarclients
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • roarclients/roarctl.c

    r4708 r4740  
    644644 int len; 
    645645 int old_chans; 
    646  int vol_l, vol_r, vol_mono; 
    647646 char * k; 
    648647 struct roar_mixer_settings mixer; 
    649648 struct roar_mixer_settings old_mixer; 
     649 int mode = ROAR_SET_VOL_ALL; 
    650650 
    651651 if (*cur + 2 > max) 
     
    655655 
    656656 k = arg[++(*cur)]; 
    657  
    658  if ( roar_get_vol(con, id, &old_mixer, &old_chans) == -1 ) { 
    659   fprintf(stderr, "Error: can not get stream mixer info for stream %i\n", id); 
    660   return -1; 
    661  } 
    662657 
    663658 if ( !strcmp(arg[*cur + 1], "scale") ) { 
     
    667662 } 
    668663 
    669 // TODO: clean up code here as the % vs. abs code is very duplicate... 
    670  
    671  if ( strcmp(k, "mono") == 0 && old_chans != 1 ) { 
     664 mixer.scale = scale; 
     665 
     666 if ( roar_get_vol(con, id, &old_mixer, &old_chans) == -1 ) { 
     667  fprintf(stderr, "Error: can not get stream mixer info for stream %i\n", id); 
     668  return -1; 
     669 } 
     670 
     671 if ( strcmp(k, "mono") == 0 ) { 
    672672  chans = 1; 
    673  
    674   if ( *cur + 1 > max ) 
    675    return -1; 
    676  
     673  mode  = ROAR_SET_VOL_UNMAPPED; 
     674 } else if ( strcmp(k, "stereo") == 0 ) { 
     675  chans = 2; 
     676  mode  = ROAR_SET_VOL_UNMAPPED; 
     677 } else { 
     678  chans = atoi(k); 
     679 } 
     680 
     681 // ensure most simple mode: 
     682 if ( old_chans == chans && mode == ROAR_SET_VOL_UNMAPPED ) 
     683  mode = ROAR_SET_VOL_ALL; 
     684 
     685 if ( *cur + chans > max ) 
     686  return -1; 
     687 
     688 for (i = 0; i < chans; i++) { 
    677689  k   = arg[++(*cur)]; 
    678690  len = strlen(k); 
    679691 
    680   vol_mono = set_mixer_parse_volume(k, len, scale); 
    681  
    682   for (i = 0; i < old_chans; i++) 
    683    mixer.mixer[i] = vol_mono; 
    684  
    685   chans = old_chans; 
    686  
    687  } else if ( strcmp(k, "stereo") == 0 && old_chans != 2 ) { 
    688   chans = old_chans; 
    689  
    690   if ( *cur + 2 > max ) 
    691    return -1; 
    692  
    693   k   = arg[++(*cur)]; 
    694   len = strlen(k); 
    695  
    696   vol_l = set_mixer_parse_volume(k, len, scale); 
    697  
    698   k   = arg[++(*cur)]; 
    699   len = strlen(k); 
    700  
    701   vol_r = set_mixer_parse_volume(k, len, scale); 
    702  
    703   vol_mono = (vol_l + vol_r) / 2; 
    704  
    705   mixer.mixer[0] = vol_l; 
    706   mixer.mixer[1] = vol_r; 
    707  
    708   switch (chans) { 
    709    case 1: 
    710      mixer.mixer[0] = vol_mono; 
    711     break; 
    712 //   case 2: classic stereo... 
    713    case 3: 
    714      mixer.mixer[2] = vol_mono; 
    715     break; 
    716    case 4: 
    717      mixer.mixer[2] = vol_l; 
    718      mixer.mixer[3] = vol_r; 
    719     break; 
    720    case 5: 
    721      mixer.mixer[2] = vol_mono; 
    722      mixer.mixer[3] = vol_l; 
    723      mixer.mixer[4] = vol_r; 
    724     break; 
    725    case 6: 
    726      mixer.mixer[2] = vol_mono; 
    727      mixer.mixer[3] = vol_mono; 
    728      mixer.mixer[4] = vol_l; 
    729      mixer.mixer[5] = vol_r; 
    730     break; 
    731    default: 
    732      ROAR_ERR("mode stereo not supported on stream with %i channels", chans); 
    733      return -1; 
    734     break; 
    735   } 
    736  
    737  } else { 
    738   if ( strcmp(k, "mono") == 0 ) { 
    739    chans = 1; 
    740   } else if ( strcmp(k, "stereo") == 0 ) { 
    741    chans = 2; 
    742   } else { 
    743    chans = atoi(k); 
    744   } 
    745  
    746 //  printf("mode: int; chans=%i, old_chans=%i\n", chans, old_chans); 
    747  
    748   if ( *cur + chans > max ) 
    749    return -1; 
    750  
    751   for (i = 0; i < chans; i++) { 
    752    k   = arg[++(*cur)]; 
    753    len = strlen(k); 
    754  
    755    mixer.mixer[i] = set_mixer_parse_volume(k, len, scale); 
    756   } 
    757  } 
    758  
    759  mixer.scale = scale; 
    760  
    761  return roar_set_vol(con, id, &mixer, chans); 
     692  mixer.mixer[i] = set_mixer_parse_volume(k, len, scale); 
     693 } 
     694 
     695 if ( roar_set_vol2(con, id, &mixer, chans, mode) == 0 ) 
     696  return 0; 
     697 
     698 // no fallback if already using ROAR_SET_VOL_ALL: 
     699 if ( mode == ROAR_SET_VOL_ALL ) 
     700  return -1; 
     701 
     702 if ( roar_conv_volume(&mixer, &mixer, old_chans, chans) == -1 ) 
     703  return -1; 
     704 
     705 chans = old_chans; 
     706 mode  = ROAR_SET_VOL_ALL; 
     707 
     708 if ( roar_set_vol2(con, id, &mixer, chans, mode) == 0 ) 
     709  return 0; 
     710 
     711 return -1; 
    762712} 
    763713 
  • roarclients/roarradio.c

    r4708 r4740  
    4343       ); 
    4444 
     45} 
     46 
     47static void die(const char * msg) { 
     48 fprintf(stderr, "Fatal error: %s\n", msg); 
     49 abort(); 
    4550} 
    4651 
     
    6267 char buf0[80], buf1[80]; 
    6368 int proto = P_UNKNOWN; 
     69 ssize_t slen; 
    6470 
    6571 for (i = 1; i < argc; i++) { 
     
    160166 
    161167      while (*buf0 != '\r' && *buf0 != '\n') { 
    162        fgets(buf0, 80, http); 
     168       if ( fgets(buf0, 80, http) == NULL ) 
     169        die("Can not read header lion"); 
    163170      } 
    164171 
     
    173180      } 
    174181      // TODO: do some error checks here 
    175       write(in, file, strlen(file)); 
    176       write(in, "\r\n", 2); 
     182      slen = strlen(file); 
     183      if ( write(in, file, slen) != slen ) 
     184       die("Can not write selector"); 
     185      if ( write(in, "\r\n", 2) != 2 ) 
     186       die("Can not write selector terminator"); 
    177187      ROAR_SHUTDOWN(in, SHUT_WR); 
    178188     break; 
Note: See TracChangeset for help on using the changeset viewer.