Changeset 646:a8915fb83769 in roaraudio for roarclients
- Timestamp:
- 08/26/08 04:23:15 (16 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
roarclients/roarfilt.c
r233 r646 5 5 6 6 #define BUFSIZE 1024 7 struct { 8 uint16_t a, b, old[ROAR_MAX_CHANNELS]; 9 } g_lowpass; 7 10 8 11 void usage (void) { … … 22 25 " --mul VAL - Set mul\n" 23 26 " --div VAL - Set div\n" 27 " --lowpass freq - lowpass filter\n" 24 28 ); 25 29 … … 67 71 } 68 72 73 void 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 69 97 int main (int argc, char * argv[]) { 70 98 int rate = 44100; … … 78 106 int mul = 1, div = 1; 79 107 float logscale = 0; 108 float lp = 0; 80 109 char buf[BUFSIZE]; 110 111 memset(&g_lowpass, 0, sizeof(g_lowpass)); 81 112 82 113 for (i = 1; i < argc; i++) { … … 103 134 } else if ( strcmp(k, "--log") == 0 ) { 104 135 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; 105 140 } else if ( strcmp(k, "--help") == 0 ) { 106 141 usage(); … … 118 153 } 119 154 120 if ( mul == div && logscale == 0 ) {155 if ( mul == div && logscale == 0 && lp == 0 ) { 121 156 fprintf(stderr, "Error: filter is useless!\n"); 122 157 return 0; … … 129 164 if ( logscale ) 130 165 logs2((void*)buf, logscale, i); 166 if ( g_lowpass.a ) 167 lowpass2((void*)buf, i, channels); 131 168 if (write(fh, buf, i) != i) 132 169 break;
Note: See TracChangeset
for help on using the changeset viewer.