Changeset 85:261b53488dc2 in roaraudio


Ignore:
Timestamp:
07/12/08 23:41:49 (16 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added set_mixer() and volume command to roarctl

File:
1 edited

Legend:

Unmodified
Added
Removed
  • roarclients/roarctl.c

    r58 r85  
    128128} 
    129129 
     130int set_mixer (struct roar_connection * con, int * cur, int max, char * arg[]) { 
     131 int chans = 0; 
     132 int id; 
     133 int i; 
     134 int len; 
     135 int old_chans; 
     136 int vol_l, vol_r; 
     137 char * k; 
     138 struct roar_mixer_settings mixer; 
     139 struct roar_mixer_settings old_mixer; 
     140 
     141 if (*cur + 2 > max) 
     142  return -1; 
     143 
     144 id = atoi(arg[++(*cur)]); 
     145 
     146 k = arg[++(*cur)]; 
     147 
     148 if ( roar_get_vol(con, id, &old_mixer, &old_chans) == -1 ) { 
     149  fprintf(stderr, "Error: can not get stream mixer info\n"); 
     150  return -1; 
     151 } 
     152 
     153 
     154 if ( strcmp(k, "mono") == 0 && old_chans != 1 ) { 
     155  chans = 1; 
     156 
     157  if ( *cur + 1 > max ) 
     158   return -1; 
     159 
     160  k   = arg[++(*cur)]; 
     161  len = strlen(k); 
     162 
     163  if ( k[len - 1] == '%' ) { 
     164   k[len - 1] = 0; 
     165   vol_l = (atof(k)*65535)/100; 
     166  } else { 
     167   vol_l = atoi(k); 
     168  } 
     169 
     170  for (i = 0; i < old_chans; i++) 
     171   mixer.mixer[i] = vol_l; 
     172 
     173  chans = old_chans; 
     174 
     175 } else if ( strcmp(k, "stereo") == 0 && old_chans != 2 ) { 
     176  chans = 2; 
     177//  printf("mode: stereo; chans=%i, old_chans=%i\n", chans, old_chans); 
     178  ROAR_ERR("mode stereo not supported"); 
     179  return -1; 
     180 } else { 
     181  if ( strcmp(k, "mono") == 0 ) { 
     182   chans = 1; 
     183  } else if ( strcmp(k, "stereo") == 0 ) { 
     184   chans = 2; 
     185  } else { 
     186   chans = atoi(k); 
     187  } 
     188 
     189//  printf("mode: int; chans=%i, old_chans=%i\n", chans, old_chans); 
     190 
     191  if ( *cur + chans > max ) 
     192   return -1; 
     193 
     194  for (i = 0; i < chans; i++) { 
     195   k   = arg[++(*cur)]; 
     196   len = strlen(k); 
     197 
     198   if ( k[len - 1] == '%' ) { 
     199    k[len - 1] = 0; 
     200    mixer.mixer[i] = (atof(k)*(int)65535)/100; 
     201   } else { 
     202    mixer.mixer[i] = atoi(k); 
     203   } 
     204  } 
     205 } 
     206 
     207 mixer.scale = 65535; 
     208 
     209 return roar_set_vol(con, id, &mixer, chans); 
     210} 
     211 
    130212int main (int argc, char * argv[]) { 
    131213 struct roar_connection con; 
     
    246328   } 
    247329 
     330  } else if ( !strcmp(k, "volume") ) { 
     331   if ( set_mixer(&con, &i, argc, argv) == -1 ) { 
     332    fprintf(stderr, "Error: can not set volume\n"); 
     333   } else { 
     334    printf("volume changed\n"); 
     335   } 
     336 
    248337  } else { 
    249338   fprintf(stderr, "Error: invalid command: %s\n", k); 
Note: See TracChangeset for help on using the changeset viewer.