Changeset 128:5cae7d8795d5 in roaraudio


Ignore:
Timestamp:
07/13/08 19:23:13 (16 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added esdfilt like --half --half and --double

File:
1 edited

Legend:

Unmodified
Added
Removed
  • roarclients/roarfilt.c

    r126 r128  
    1515        "  --chans  CHANNELS  - Set number of channels\n" 
    1616        "  --help             - Show this help\n" 
     17        "\n" 
     18        "  --half             - half the volume\n" 
     19        "  --double           - double the volume\n" 
    1720       ); 
    1821 
     22} 
     23 
     24void vol2 (void * data, int mul, int div, int len) { 
     25 int16_t * samples = (int16_t *) data; 
     26 int i; 
     27 
     28 len /= 2; 
     29 
     30 for (i = 0; i < len; i++) 
     31  samples[i] = ((int) samples[i] * mul) / div; 
     32} 
     33 
     34void vol1 (void * data, int mul, int div, int len) { 
     35 int8_t * samples = (int8_t *) data; 
     36 int i; 
     37 
     38 len /= 2; 
     39 
     40 for (i = 0; i < len; i++) 
     41  samples[i] = ((int) samples[i] * mul) / div; 
    1942} 
    2043 
     
    2851 int    fh; 
    2952 int    i; 
     53 int    mul = 1, div = 1; 
    3054 char buf[BUFSIZE]; 
    3155 
     
    4165  } else if ( strcmp(k, "--channels") == 0 || strcmp(k, "--chans") == 0 ) { 
    4266   channels = atoi(argv[++i]); 
     67  } else if ( strcmp(k, "--half") == 0 ) { 
     68   div *= 2; 
     69  } else if ( strcmp(k, "--double") == 0 ) { 
     70   mul *= 2; 
    4371  } else if ( strcmp(k, "--help") == 0 ) { 
    4472   usage(); 
     
    5684 } 
    5785 
    58  while((i = read(fh, buf, BUFSIZE))) 
    59   if (write(fh, buf, i) != i) 
    60    break; 
     86 if ( mul == div ) { 
     87  fprintf(stderr, "Error: filter is useless!\n"); 
     88  return 0; 
     89 } 
     90 
     91 if ( bits == 16 ) { 
     92  while((i = read(fh, buf, BUFSIZE))) { 
     93   vol2((void*)buf, mul, div, i); 
     94   if (write(fh, buf, i) != i) 
     95    break; 
     96  } 
     97 } else if ( bits == 8 ) { 
     98  while((i = read(fh, buf, BUFSIZE))) { 
     99   vol1((void*)buf, mul, div, i); 
     100   if (write(fh, buf, i) != i) 
     101    break; 
     102  } 
     103 } else { 
     104  fprintf(stderr, "Error: %i bits per sample is not supported!\n", bits); 
     105  return 1; 
     106 } 
    61107 
    62108 roar_simple_close(fh); 
Note: See TracChangeset for help on using the changeset viewer.