Changeset 5950:7fe8f5df7a83 in roaraudio for roarclients/roarfilt.c
- Timestamp:
- 10/20/13 13:52:15 (11 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
roarclients/roarfilt.c
r5823 r5950 32 32 33 33 #define BUFFERSIZE 1024 34 35 #ifdef ROAR_HAVE_LIBM36 struct {37 uint16_t a, b;38 int16_t old[ROAR_MAX_CHANNELS];39 } g_lowpass;40 #endif41 34 42 35 void usage (void) { … … 57 50 " --mul VAL - Set mul\n" 58 51 " --div VAL - Set div\n" 59 #ifdef ROAR_HAVE_LIBM60 " --lowpass freq - lowpass filter (obsolete)\n"61 #endif62 52 " --filter name - add filter name\n" 63 53 " --ffreq freq - set filter freq\n" … … 87 77 _volX(32,64,4) 88 78 89 #ifdef ROAR_HAVE_LIBM90 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] * B124 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 #endif137 138 79 int main (int argc, char * argv[]) { 139 80 struct roar_audio_info info; … … 144 85 int filter_id; 145 86 int32_t tmp; 146 float logscale = 0; 147 float lp = 0; 87 float tmpfp; 148 88 char buf[BUFFERSIZE]; 149 89 struct roardsp_filterchain fc; … … 156 96 info.codec = ROAR_CODEC_DEFAULT; 157 97 158 #ifdef ROAR_HAVE_LIBM159 memset(&g_lowpass, 0, sizeof(g_lowpass));160 #endif161 162 98 roardsp_fchain_init(&fc); 163 99 … … 166 102 167 103 if ( strcmp(k, "--server") == 0 || strcmp(k, "-s") == 0 ) { 104 ROAR_CKHAVEARGS(1); 168 105 server = argv[++i]; 169 106 } else if ( strcmp(k, "--rate") == 0 || strcmp(k, "-R") == 0 || strcmp(k, "-r") == 0 ) { 107 ROAR_CKHAVEARGS(1); 170 108 info.rate = roar_str2rate(argv[++i]); 171 109 } else if ( strcmp(k, "--bits") == 0 || strcmp(k, "-B") == 0 ) { 110 ROAR_CKHAVEARGS(1); 172 111 info.bits = roar_str2bits(argv[++i]); 173 112 } else if ( strcmp(k, "--channels") == 0 || strcmp(k, "--chans") == 0 || strcmp(k, "-C") == 0 ) { 113 ROAR_CKHAVEARGS(1); 174 114 info.channels = roar_str2channels(argv[++i]); 175 115 } else if ( strcmp(k, "-b") == 0 ) { … … 178 118 info.channels = 1; 179 119 } else if ( !strcmp(k, "--aiprofile") ) { 120 ROAR_CKHAVEARGS(1); 180 121 if ( roar_profile2info(&info, argv[++i]) == -1 ) { 181 122 fprintf(stderr, "Error: Can not load audio profile: %s: %s\n", argv[i], roar_error2str(roar_error)); … … 188 129 mul *= 2; 189 130 } else if ( strcmp(k, "--amp") == 0 ) { 131 ROAR_CKHAVEARGS(1); 190 132 mul *= atoi(argv[++i]); 191 133 } else if ( strcmp(k, "--mul") == 0 ) { 134 ROAR_CKHAVEARGS(1); 192 135 mul = atoi(argv[++i]); 193 136 } else if ( strcmp(k, "--div") == 0 ) { 137 ROAR_CKHAVEARGS(1); 194 138 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_LIBM199 } 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 #endif205 // printf("lowpass: A=%i, B=%i\n", g_lowpass.a, g_lowpass.b);206 139 } else if ( strcmp(k, "--filter") == 0 ) { 140 ROAR_CKHAVEARGS(1); 207 141 stream.info = info; 208 142 filter_id = roardsp_filter_str2id(argv[++i]); … … 219 153 } 220 154 } 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); 223 158 } else if ( strcmp(k, "--fmul") == 0 ) { 159 ROAR_CKHAVEARGS(1); 224 160 tmp = atoi(argv[++i]); 225 161 roardsp_filter_ctl(filter, ROARDSP_FCTL_MUL, &tmp); 226 162 } else if ( strcmp(k, "--fdiv") == 0 ) { 163 ROAR_CKHAVEARGS(1); 227 164 tmp = atoi(argv[++i]); 228 165 roardsp_filter_ctl(filter, ROARDSP_FCTL_DIV, &tmp); 229 166 } else if ( strcmp(k, "--fn") == 0 ) { 167 ROAR_CKHAVEARGS(1); 230 168 tmp = atoi(argv[++i]); 231 169 roardsp_filter_ctl(filter, ROARDSP_FCTL_N, &tmp); 232 170 } else if ( strcmp(k, "--fq") == 0 ) { 171 ROAR_CKHAVEARGS(1); 233 172 tmp = atoi(argv[++i]); 234 173 roardsp_filter_ctl(filter, ROARDSP_FCTL_Q, &tmp); 235 174 } else if ( strcmp(k, "--flimit") == 0 ) { 175 ROAR_CKHAVEARGS(1); 236 176 tmp = atoi(argv[++i]); 237 177 roardsp_filter_ctl(filter, ROARDSP_FCTL_LIMIT, &tmp); 238 178 } else if ( strcmp(k, "--fmode") == 0 ) { 179 ROAR_CKHAVEARGS(1); 239 180 tmp = atoi(argv[++i]); 240 181 roardsp_filter_ctl(filter, ROARDSP_FCTL_MODE, &tmp); … … 257 198 258 199 if ( mul == div && 259 #ifdef ROAR_HAVE_LIBM260 logscale == 0 && g_lowpass.a == 0 &&261 #endif262 200 roardsp_fchain_num(&fc) == 0 ) { 263 201 fprintf(stderr, "Error: filter is useless!\n"); … … 278 216 if ( mul != div ) 279 217 vol16((void*)buf, mul, div, i); 280 #ifdef ROAR_HAVE_LIBM281 if ( logscale )282 logs2((void*)buf, logscale, i);283 if ( g_lowpass.a )284 lowpass2((void*)buf, i, info.channels);285 #endif286 218 roardsp_fchain_calc(&fc, (void*)buf, (8*i)/info.bits); 287 219 if (roar_vio_write(&svio, buf, i) != i)
Note: See TracChangeset
for help on using the changeset viewer.