Changeset 646:a8915fb83769 in roaraudio


Ignore:
Timestamp:
08/26/08 04:23:15 (16 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added lowpass, but seems not to work at the moment

File:
1 edited

Legend:

Unmodified
Added
Removed
  • roarclients/roarfilt.c

    r233 r646  
    55 
    66#define BUFSIZE 1024 
     7struct { 
     8 uint16_t a, b, old[ROAR_MAX_CHANNELS]; 
     9} g_lowpass; 
    710 
    811void usage (void) { 
     
    2225        "  --mul VAL          - Set mul\n" 
    2326        "  --div VAL          - Set div\n" 
     27        "  --lowpass freq     - lowpass filter\n" 
    2428       ); 
    2529 
     
    6771} 
    6872 
     73void lowpass2 (void * data, int len, int channels) { 
     74 int16_t * samples = (int16_t *) data; 
     75 register int32_t s; 
     76 int i, c; 
     77 
     78 if ( channels > ROAR_MAX_CHANNELS ) 
     79  return; 
     80 
     81 len /= 2 * channels; 
     82 
     83//  *      output[N] = input[N] * A + output[N-1] * B 
     84 
     85 for (i = 0; i < len; i++) { 
     86  for (c = 0; c < channels; c++) { 
     87   s = samples[i*channels + c] * g_lowpass.a + g_lowpass.old[c] * g_lowpass.b; 
     88 
     89   s /= 65536; 
     90 
     91   samples[i*channels + c] = s; 
     92   g_lowpass.old[       c] = s; 
     93  } 
     94 } 
     95} 
     96 
    6997int main (int argc, char * argv[]) { 
    7098 int    rate     = 44100; 
     
    78106 int    mul = 1, div = 1; 
    79107 float  logscale = 0; 
     108 float  lp       = 0; 
    80109 char buf[BUFSIZE]; 
     110 
     111 memset(&g_lowpass, 0, sizeof(g_lowpass)); 
    81112 
    82113 for (i = 1; i < argc; i++) { 
     
    103134  } else if ( strcmp(k, "--log") == 0 ) { 
    104135   logscale = atof(argv[++i]); 
     136  } else if ( strcmp(k, "--lowpass") == 0 ) { 
     137   lp = exp(-2 * M_PI * atof(argv[++i]) / rate) * 65536; 
     138   g_lowpass.b = lp; 
     139   g_lowpass.a = 65536 - lp; 
    105140  } else if ( strcmp(k, "--help") == 0 ) { 
    106141   usage(); 
     
    118153 } 
    119154 
    120  if ( mul == div && logscale == 0 ) { 
     155 if ( mul == div && logscale == 0 && lp == 0 ) { 
    121156  fprintf(stderr, "Error: filter is useless!\n"); 
    122157  return 0; 
     
    129164   if ( logscale ) 
    130165    logs2((void*)buf, logscale, i); 
     166   if ( g_lowpass.a ) 
     167    lowpass2((void*)buf, i, channels); 
    131168   if (write(fh, buf, i) != i) 
    132169    break; 
Note: See TracChangeset for help on using the changeset viewer.