Changeset 5950:7fe8f5df7a83 in roaraudio for roarclients/roarfilt.c


Ignore:
Timestamp:
10/20/13 13:52:15 (11 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

code cleanup and again a patch for checking commandlion parameters

File:
1 edited

Legend:

Unmodified
Added
Removed
  • roarclients/roarfilt.c

    r5823 r5950  
    3232 
    3333#define BUFFERSIZE 1024 
    34  
    35 #ifdef ROAR_HAVE_LIBM 
    36 struct { 
    37  uint16_t a, b; 
    38  int16_t  old[ROAR_MAX_CHANNELS]; 
    39 } g_lowpass; 
    40 #endif 
    4134 
    4235void usage (void) { 
     
    5750        "  --mul VAL           - Set mul\n" 
    5851        "  --div VAL           - Set div\n" 
    59 #ifdef ROAR_HAVE_LIBM 
    60         "  --lowpass freq      - lowpass filter (obsolete)\n" 
    61 #endif 
    6252        "  --filter  name      - add filter name\n" 
    6353        "  --ffreq   freq      - set filter freq\n" 
     
    8777_volX(32,64,4) 
    8878 
    89 #ifdef ROAR_HAVE_LIBM 
    90 void logs2 (void * data, float scale, int len) { 
    91  int16_t * samples = (int16_t *) data; 
    92  int i; 
    93  float div = logf(scale); 
    94  float scalemul = scale - 1; 
    95  int neg; 
    96  
    97  len /= 2; 
    98  
    99  //printf("logs2(data=%p, scale=%f, len=%i): scalemul=%f, div=%f\n", data, scale, len, scalemul, div); 
    100  
    101  for (i = 0; i < len; i++) { 
    102   if ( (neg = (samples[i] < 0)) )  
    103    samples[i] = abs(samples[i]); 
    104  
    105  
    106   samples[i] = (neg ? 32768.0 : 32767.0)*logf(1 + (scalemul*(float)samples[i]/(neg ? 32768.0 : 32767.0))) / div; 
    107  
    108   if ( neg ) 
    109    samples[i] *= -1; 
    110  } 
    111 } 
    112  
    113 void lowpass2 (void * data, int len, int channels) { 
    114  int16_t * samples = (int16_t *) data; 
    115  register int32_t s; 
    116  int i, c; 
    117  
    118  if ( channels > ROAR_MAX_CHANNELS ) 
    119   return; 
    120  
    121  len /= 2 * channels; 
    122  
    123 //  *      output[N] = input[N] * A + output[N-1] * B 
    124  
    125  for (i = 0; i < len; i++) { 
    126   for (c = 0; c < channels; c++) { 
    127    s = samples[i*channels + c] * g_lowpass.a + g_lowpass.old[c] * g_lowpass.b; 
    128  
    129    s /= 65536; 
    130  
    131    samples[i*channels + c] = s; 
    132    g_lowpass.old[       c] = s; 
    133   } 
    134  } 
    135 } 
    136 #endif 
    137  
    13879int main (int argc, char * argv[]) { 
    13980 struct roar_audio_info info; 
     
    14485 int     filter_id; 
    14586 int32_t tmp; 
    146  float   logscale = 0; 
    147  float   lp       = 0; 
     87 float   tmpfp; 
    14888 char    buf[BUFFERSIZE]; 
    14989 struct roardsp_filterchain fc; 
     
    15696 info.codec = ROAR_CODEC_DEFAULT; 
    15797 
    158 #ifdef ROAR_HAVE_LIBM 
    159  memset(&g_lowpass, 0, sizeof(g_lowpass)); 
    160 #endif 
    161  
    16298 roardsp_fchain_init(&fc); 
    16399 
     
    166102 
    167103  if ( strcmp(k, "--server") == 0 || strcmp(k, "-s") == 0 ) { 
     104   ROAR_CKHAVEARGS(1); 
    168105   server = argv[++i]; 
    169106  } else if ( strcmp(k, "--rate") == 0 || strcmp(k, "-R") == 0 || strcmp(k, "-r") == 0 ) { 
     107   ROAR_CKHAVEARGS(1); 
    170108   info.rate = roar_str2rate(argv[++i]); 
    171109  } else if ( strcmp(k, "--bits") == 0 || strcmp(k, "-B") == 0 ) { 
     110   ROAR_CKHAVEARGS(1); 
    172111   info.bits = roar_str2bits(argv[++i]); 
    173112  } else if ( strcmp(k, "--channels") == 0 || strcmp(k, "--chans") == 0 || strcmp(k, "-C") == 0 ) { 
     113   ROAR_CKHAVEARGS(1); 
    174114   info.channels = roar_str2channels(argv[++i]); 
    175115  } else if ( strcmp(k, "-b") == 0 ) { 
     
    178118   info.channels = 1; 
    179119  } else if ( !strcmp(k, "--aiprofile") ) { 
     120   ROAR_CKHAVEARGS(1); 
    180121   if ( roar_profile2info(&info, argv[++i]) == -1 ) { 
    181122    fprintf(stderr, "Error: Can not load audio profile: %s: %s\n", argv[i], roar_error2str(roar_error)); 
     
    188129   mul *= 2; 
    189130  } else if ( strcmp(k, "--amp") == 0 ) { 
     131   ROAR_CKHAVEARGS(1); 
    190132   mul *= atoi(argv[++i]); 
    191133  } else if ( strcmp(k, "--mul") == 0 ) { 
     134   ROAR_CKHAVEARGS(1); 
    192135   mul  = atoi(argv[++i]); 
    193136  } else if ( strcmp(k, "--div") == 0 ) { 
     137   ROAR_CKHAVEARGS(1); 
    194138   div  = atoi(argv[++i]); 
    195   } else if ( strcmp(k, "--log") == 0 ) { 
    196    ROAR_WARN("The logscaler is obsolete and will be removed soon."); 
    197    logscale = atof(argv[++i]); 
    198 #ifdef ROAR_HAVE_LIBM 
    199   } else if ( strcmp(k, "--lowpass") == 0 ) { 
    200    ROAR_WARN("The builtin lowpass is obsolete and will be removed soon. Use --filter lowpass."); 
    201    lp = exp(-2 * M_PI * atof(argv[++i]) / info.rate) * 65536; 
    202    g_lowpass.b = lp; 
    203    g_lowpass.a = 65536 - lp; 
    204 #endif 
    205 //   printf("lowpass: A=%i, B=%i\n", g_lowpass.a, g_lowpass.b); 
    206139  } else if ( strcmp(k, "--filter") == 0 ) { 
     140   ROAR_CKHAVEARGS(1); 
    207141   stream.info = info; 
    208142   filter_id = roardsp_filter_str2id(argv[++i]); 
     
    219153   } 
    220154  } else if ( strcmp(k, "--ffreq") == 0 ) { 
    221    lp = atof(argv[++i]); 
    222    roardsp_filter_ctl(filter, ROARDSP_FCTL_FREQ, &lp); 
     155   ROAR_CKHAVEARGS(1); 
     156   tmpfp = atof(argv[++i]); 
     157   roardsp_filter_ctl(filter, ROARDSP_FCTL_FREQ, &tmpfp); 
    223158  } else if ( strcmp(k, "--fmul") == 0 ) { 
     159   ROAR_CKHAVEARGS(1); 
    224160   tmp = atoi(argv[++i]); 
    225161   roardsp_filter_ctl(filter, ROARDSP_FCTL_MUL, &tmp); 
    226162  } else if ( strcmp(k, "--fdiv") == 0 ) { 
     163   ROAR_CKHAVEARGS(1); 
    227164   tmp = atoi(argv[++i]); 
    228165   roardsp_filter_ctl(filter, ROARDSP_FCTL_DIV, &tmp); 
    229166  } else if ( strcmp(k, "--fn") == 0 ) { 
     167   ROAR_CKHAVEARGS(1); 
    230168   tmp = atoi(argv[++i]); 
    231169   roardsp_filter_ctl(filter, ROARDSP_FCTL_N, &tmp); 
    232170  } else if ( strcmp(k, "--fq") == 0 ) { 
     171   ROAR_CKHAVEARGS(1); 
    233172   tmp = atoi(argv[++i]); 
    234173   roardsp_filter_ctl(filter, ROARDSP_FCTL_Q, &tmp); 
    235174  } else if ( strcmp(k, "--flimit") == 0 ) { 
     175   ROAR_CKHAVEARGS(1); 
    236176   tmp = atoi(argv[++i]); 
    237177   roardsp_filter_ctl(filter, ROARDSP_FCTL_LIMIT, &tmp); 
    238178  } else if ( strcmp(k, "--fmode") == 0 ) { 
     179   ROAR_CKHAVEARGS(1); 
    239180   tmp = atoi(argv[++i]); 
    240181   roardsp_filter_ctl(filter, ROARDSP_FCTL_MODE, &tmp); 
     
    257198 
    258199 if ( mul == div && 
    259 #ifdef ROAR_HAVE_LIBM 
    260       logscale == 0 && g_lowpass.a == 0 && 
    261 #endif 
    262200      roardsp_fchain_num(&fc) == 0 ) { 
    263201  fprintf(stderr, "Error: filter is useless!\n"); 
     
    278216     if ( mul != div ) 
    279217      vol16((void*)buf, mul, div, i); 
    280 #ifdef ROAR_HAVE_LIBM 
    281      if ( logscale ) 
    282       logs2((void*)buf, logscale, i); 
    283      if ( g_lowpass.a ) 
    284       lowpass2((void*)buf, i, info.channels); 
    285 #endif 
    286218     roardsp_fchain_calc(&fc, (void*)buf, (8*i)/info.bits); 
    287219     if (roar_vio_write(&svio, buf, i) != i) 
Note: See TracChangeset for help on using the changeset viewer.