/* * Process options: dcshift (double) type (amplitude, power, dB) */ static int sox_dcshift_getopts(sox_effect_t * effp, int argc, char **argv) { priv_t * dcs = (priv_t *) effp->priv; dcs->dcshift = 1.0; /* default is no change */ dcs->uselimiter = 0; /* default is no limiter */ --argc, ++argv; if (argc < 1) return lsx_usage(effp); if (argc && (!sscanf(argv[0], "%lf", &dcs->dcshift))) return lsx_usage(effp); if (argc>1) { if (!sscanf(argv[1], "%lf", &dcs->limitergain)) return lsx_usage(effp); dcs->uselimiter = 1; /* ok, we'll use it */ /* The following equation is derived so that there is no * discontinuity in output amplitudes */ /* and a SOX_SAMPLE_MAX input always maps to a SOX_SAMPLE_MAX output * when the limiter is activated. */ /* (NOTE: There **WILL** be a discontinuity in the slope of the * output amplitudes when using the limiter.) */ dcs->limiterthreshhold = SOX_SAMPLE_MAX * (1.0 - (fabs(dcs->dcshift) - dcs->limitergain)); } return SOX_SUCCESS; }
/* * Process options */ static int sox_trim_getopts(sox_effect_t * effp, int argc, char **argv) { char *end; priv_t * trim = (priv_t *) effp->priv; --argc, ++argv; /* Do not know sample rate yet so hold off on completely parsing * time related strings. */ switch (argc) { case 2: end = argv[1]; if (*end == '=') { trim->end_is_absolute = sox_true; end++; } else trim->end_is_absolute = sox_false; trim->end_str = lsx_malloc(strlen(end)+1); strcpy(trim->end_str, end); /* Do a dummy parse to see if it will fail */ if (lsx_parsesamples(0., trim->end_str, &trim->length, 't') == NULL) return lsx_usage(effp); case 1: trim->start_str = lsx_malloc(strlen(argv[0])+1); strcpy(trim->start_str,argv[0]); /* Do a dummy parse to see if it will fail */ if (lsx_parsesamples(0., trim->start_str, &trim->start, 't') == NULL) return lsx_usage(effp); break; default: return lsx_usage(effp); } return (SOX_SUCCESS); }
/* * Start processing */ static int sox_trim_start(sox_effect_t * effp) { priv_t * trim = (priv_t *) effp->priv; if (lsx_parsesamples(effp->in_signal.rate, trim->start_str, &trim->start, 't') == NULL) return lsx_usage(effp); /* Account for # of channels */ trim->start *= effp->in_signal.channels; if (trim->length_str) { if (lsx_parsesamples(effp->in_signal.rate, trim->length_str, &trim->length, 't') == NULL) return lsx_usage(effp); } else trim->length = 0; /* Account for # of channels */ trim->length *= effp->in_signal.channels; trim->index = 0; trim->trimmed = 0; return (SOX_SUCCESS); }
/* * Process options */ static int sox_trim_getopts(sox_effect_t * effp, int n, char **argv) { priv_t * trim = (priv_t *) effp->priv; /* Do not know sample rate yet so hold off on completely parsing * time related strings. */ switch (n) { case 2: trim->length_str = lsx_malloc(strlen(argv[1])+1); strcpy(trim->length_str,argv[1]); /* Do a dummy parse to see if it will fail */ if (lsx_parsesamples(0., trim->length_str, &trim->length, 't') == NULL) return lsx_usage(effp); case 1: trim->start_str = lsx_malloc(strlen(argv[0])+1); strcpy(trim->start_str,argv[0]); /* Do a dummy parse to see if it will fail */ if (lsx_parsesamples(0., trim->start_str, &trim->start, 't') == NULL) return lsx_usage(effp); break; default: return lsx_usage(effp); } return (SOX_SUCCESS); }
/* * Process options */ static int getopts(sox_effect_t * effp, int argc, char **argv) { priv_t * r = (priv_t *) effp->priv; char dummy; /* To check for extraneous chars. */ r->converter_type = SRC_SINC_BEST_QUALITY; if (argc) { if (!strcmp(argv[0], "-c0")) { r->converter_type = SRC_SINC_BEST_QUALITY; argc--; argv++; } else if (!strcmp(argv[0], "-c1")) { r->converter_type = SRC_SINC_MEDIUM_QUALITY; argc--; argv++; } else if (!strcmp(argv[0], "-c2")) { r->converter_type = SRC_SINC_FASTEST; argc--; argv++; } else if (!strcmp(argv[0], "-c3")) { r->converter_type = SRC_ZERO_ORDER_HOLD; argc--; argv++; } else if (!strcmp(argv[0], "-c4")) { r->converter_type = SRC_LINEAR; argc--; argv++; } } r->out_rate = HUGE_VAL; if (argc) { if (sscanf(*argv, "%lf %c", &r->out_rate, &dummy) != 1 || r->out_rate <= 0) return lsx_usage(effp); argc--; argv++; } return argc? lsx_usage(effp) : SOX_SUCCESS; }
/* * Process options */ static int getopts(sox_effect_t * effp, int argc, char **argv) { priv_t * mixer = (priv_t *) effp->priv; double* pans = &mixer->sources[0][0]; int i; --argc, ++argv; for (i = 0; i < 16; i++) pans[i] = 0.0; mixer->mix = MIX_CENTER; mixer->num_pans = 0; /* Parse parameters. Since we don't yet know the number of */ /* input and output channels, we'll record the information for */ /* later. */ if (argc == 1) { if (!strcmp(argv[0], "-l")) mixer->mix = 'l'; else if (!strcmp(argv[0], "-r")) mixer->mix = 'r'; else if (!strcmp(argv[0], "-f")) mixer->mix = 'f'; else if (!strcmp(argv[0], "-b")) mixer->mix = 'b'; else if (!strcmp(argv[0], "-1")) mixer->mix = '1'; else if (!strcmp(argv[0], "-2")) mixer->mix = '2'; else if (!strcmp(argv[0], "-3")) mixer->mix = '3'; else if (!strcmp(argv[0], "-4")) mixer->mix = '4'; else if (argv[0][0] == '-' && !isdigit((int)argv[0][1]) && argv[0][1] != '.') return lsx_usage(effp); else { int commas; char *s; mixer->mix = MIX_SPECIFIED; pans[0] = atof(argv[0]); for (s = argv[0], commas = 0; *s; ++s) { if (*s == ',') { ++commas; if (commas >= 16) { lsx_fail("mixer can only take up to 16 pan values"); return (SOX_EOF); } pans[commas] = atof(s+1); } } mixer->num_pans = commas + 1; } } else if (argc == 0) { mixer->mix = MIX_CENTER; } else return lsx_usage(effp); return (SOX_SUCCESS); }
static int sox_silence_start(sox_effect_t * effp) { priv_t *silence = (priv_t *)effp->priv; uint64_t temp; /* When you want to remove silence, small window sizes are * better or else RMS will look like non-silence at * aburpt changes from load to silence. */ silence->window_size = (effp->in_signal.rate / 50) * effp->in_signal.channels; silence->window = lsx_malloc(silence->window_size * sizeof(double)); clear_rms(effp); /* Now that we know sample rate, reparse duration. */ if (silence->start) { if (lsx_parsesamples(effp->in_signal.rate, silence->start_duration_str, &temp, 's') == NULL) return lsx_usage(effp); silence->start_duration = temp * effp->in_signal.channels; } if (silence->stop) { if (lsx_parsesamples(effp->in_signal.rate,silence->stop_duration_str, &temp,'s') == NULL) return lsx_usage(effp); silence->stop_duration = temp * effp->in_signal.channels; } if (silence->start) silence->mode = SILENCE_TRIM; else silence->mode = SILENCE_COPY; silence->start_holdoff = lsx_malloc(sizeof(sox_sample_t)*silence->start_duration); silence->start_holdoff_offset = 0; silence->start_holdoff_end = 0; silence->start_found_periods = 0; silence->stop_holdoff = lsx_malloc(sizeof(sox_sample_t)*silence->stop_duration); silence->stop_holdoff_offset = 0; silence->stop_holdoff_end = 0; silence->stop_found_periods = 0; effp->out_signal.length = SOX_UNKNOWN_LEN; /* depends on input data */ return(SOX_SUCCESS); }
int lsx_biquad_getopts(sox_effect_t * effp, int argc, char **argv, int min_args, int max_args, int fc_pos, int width_pos, int gain_pos, char const * allowed_width_types, filter_t filter_type) { priv_t * p = (priv_t *)effp->priv; char width_type = *allowed_width_types; char dummy, * dummy_p; /* To check for extraneous chars. */ --argc, ++argv; p->filter_type = filter_type; if (argc < min_args || argc > max_args || (argc > fc_pos && ((p->fc = lsx_parse_frequency(argv[fc_pos], &dummy_p)) <= 0 || *dummy_p)) || (argc > width_pos && ((unsigned)(sscanf(argv[width_pos], "%lf%c %c", &p->width, &width_type, &dummy)-1) > 1 || p->width <= 0)) || (argc > gain_pos && sscanf(argv[gain_pos], "%lf %c", &p->gain, &dummy) != 1) || !strchr(allowed_width_types, width_type) || (width_type == 's' && p->width > 1)) return lsx_usage(effp); p->width_type = strchr(all_width_types, width_type) - all_width_types; if (p->width_type >= strlen(all_width_types)) p->width_type = 0; if (p->width_type == width_bw_kHz) { p->width *= 1000; p->width_type = width_bw_Hz; } return SOX_SUCCESS; }
/* * Process options */ static int sox_echo_getopts(sox_effect_t * effp, int argc, char **argv) { priv_t * echo = (priv_t *) effp->priv; int i; --argc, ++argv; echo->num_delays = 0; if ((argc < 4) || (argc % 2)) return lsx_usage(effp); i = 0; sscanf(argv[i++], "%f", &echo->in_gain); sscanf(argv[i++], "%f", &echo->out_gain); while (i < argc) { if ( echo->num_delays >= MAX_ECHOS ) lsx_fail("echo: to many delays, use less than %i delays", MAX_ECHOS); /* Linux bug and it's cleaner. */ sscanf(argv[i++], "%f", &echo->delay[echo->num_delays]); sscanf(argv[i++], "%f", &echo->decay[echo->num_delays]); echo->num_delays++; } return (SOX_SUCCESS); }
static int create(sox_effect_t * effp, int argc, char * * argv) { priv_t * p = (priv_t *)effp->priv; p->factor = 2; --argc, ++argv; do {NUMERIC_PARAMETER(factor, 1, 256)} while (0); return argc? lsx_usage(effp) : SOX_SUCCESS; }
static int getopts(sox_effect_t * effp, int argc, char **argv) { priv_t * p = (priv_t *)effp->priv; int c; p->time_constant = .05; p->scale = 1; while ((c = lsx_getopt(argc, argv, "+x:b:w:s:")) != -1) switch (c) { GETOPT_NUMERIC('x', hex_bits , 2 , 32) GETOPT_NUMERIC('b', scale_bits , 2 , 32) GETOPT_NUMERIC('w', time_constant , .01 , 10) GETOPT_NUMERIC('s', scale , -99, 99) default: lsx_fail("invalid option `-%c'", optopt); return lsx_usage(effp); } if (p->hex_bits) p->scale_bits = p->hex_bits; return lsx_optind != argc? lsx_usage(effp) : SOX_SUCCESS; }
static int parse(sox_effect_t * effp, char * * argv, sox_rate_t rate) { priv_t * p = (priv_t *)effp->priv; char const * next; unsigned i; uint64_t last_seen = 0; const uint64_t in_length = argv ? 0 : (effp->in_signal.length != SOX_UNKNOWN_LEN ? effp->in_signal.length / effp->in_signal.channels : SOX_UNKNOWN_LEN); uint64_t pad_len = 0; uint64_t *arg; char *str; for (i = 0; i < p->npads; ++i) { if (argv) /* 1st parse only */ p->pads[i].str = lsx_strdup(argv[i]); str = p->pads[i].str; if (*str == '%') { str++; arg = &p->pads[i].align; } else { arg = &p->pads[i].pad; } next = lsx_parsesamples(rate, str, arg, 't'); if (next == NULL) break; if (*next == '\0') p->pads[i].start = i? in_length : 0; else { if (*next != '@') break; next = lsx_parseposition(rate, next+1, argv ? NULL : &p->pads[i].start, last_seen, in_length, '='); if (next == NULL || *next != '\0') break; last_seen = p->pads[i].start; if (p->pads[i].start == SOX_UNKNOWN_LEN) p->pads[i].start = UINT64_MAX; /* currently the same value, but ... */ } if (!argv) { if (p->pads[i].align && p->pads[i].start != UINT64_MAX) { p->pads[i].pad = pad_align(p->pads[i].start + pad_len, p->pads[i].align); p->pads[i].align = 0; } pad_len += p->pads[i].pad; /* Do this check only during the second pass when the actual sample rate is known, otherwise it might fail on legal commands like pad [email protected] 1@30000s if the rate is, e.g., 48k. */ if (i > 0 && p->pads[i].start <= p->pads[i-1].start) break; } } if (i < p->npads) return lsx_usage(effp); return SOX_SUCCESS; }
static int create(sox_effect_t * effp, int argc, char * * argv) { priv_t * p = (priv_t *)effp->priv; double * d = &p->b0; char c; --argc, ++argv; if (argc == 6) for (; argc && sscanf(*argv, "%lf%c", d, &c) == 1; --argc, ++argv, ++d); return argc? lsx_usage(effp) : SOX_SUCCESS; }
static int create(sox_effect_t * effp, int argc, char * * argv) { priv_t * p = (priv_t *)effp->priv; dft_filter_priv_t * b = &p->base; char * parse_ptr = argv[0]; int i = 0; b->filter_ptr = &b->filter; p->phase = 50; p->beta = -1; while (i < 2) { int c = 1; while (c && (c = lsx_getopt(argc, argv, "+ra:b:p:MILt:n:")) != -1) switch (c) { char * parse_ptr; case 'r': p->round = sox_true; break; GETOPT_NUMERIC('a', att, 40 , 180) GETOPT_NUMERIC('b', beta, 0 , 256) GETOPT_NUMERIC('p', phase, 0, 100) case 'M': p->phase = 0; break; case 'I': p->phase = 25; break; case 'L': p->phase = 50; break; GETOPT_NUMERIC('n', num_taps[1], 11, 32767) case 't': p->tbw1 = lsx_parse_frequency(lsx_optarg, &parse_ptr); if (p->tbw1 < 1 || *parse_ptr) return lsx_usage(effp); break; default: c = 0; } if ((p->att && p->beta >= 0) || (p->tbw1 && p->num_taps[1])) return lsx_usage(effp); if (!i || !p->Fc1) p->tbw0 = p->tbw1, p->num_taps[0] = p->num_taps[1]; if (!i++ && lsx_optind < argc) { if (*(parse_ptr = argv[lsx_optind++]) != '-') p->Fc0 = lsx_parse_frequency(parse_ptr, &parse_ptr); if (*parse_ptr == '-') p->Fc1 = lsx_parse_frequency(parse_ptr + 1, &parse_ptr); } } return lsx_optind != argc || p->Fc0 < 0 || p->Fc1 < 0 || *parse_ptr ? lsx_usage(effp) : SOX_SUCCESS; }
static int create(sox_effect_t * effp, int argc, char * * argv) { priv_t * p = (priv_t *)effp->priv; p->contrast = 75; --argc, ++argv; do { NUMERIC_PARAMETER(contrast, 0, 100) } while (0); p->contrast /= 750; /* shift range to 0 to 0.1333, default 0.1 */ return argc? lsx_usage(effp) : SOX_SUCCESS; }
/* * Process options */ static int sox_pan_getopts(sox_effect_t * effp, int argc, char **argv) { priv_t * pan = (priv_t *) effp->priv; --argc, ++argv; pan->direction = 0.0; /* default is no change */ if (argc && (!sscanf(argv[0], "%lf", &pan->direction) || pan->direction < -1.0 || pan->direction > 1.0)) return lsx_usage(effp); return SOX_SUCCESS; }
/* * Start processing */ static int sox_trim_start(sox_effect_t * effp) { priv_t * trim = (priv_t *) effp->priv; if (lsx_parsesamples(effp->in_signal.rate, trim->start_str, &trim->start, 't') == NULL) return lsx_usage(effp); if (trim->end_str) { if (lsx_parsesamples(effp->in_signal.rate, trim->end_str, &trim->length, 't') == NULL) return lsx_usage(effp); if (trim->end_is_absolute) { if (trim->length < trim->start) { lsx_warn("end earlier than start"); trim->length = 0; /* with trim->end_str != NULL, this really means zero */ } else trim->length -= trim->start; } } else trim->length = 0; /* with trim->end_str == NULL, this means indefinite length */ lsx_debug("start at %lus, length %lu", trim->start, trim->length); /* Account for # of channels */ trim->start *= effp->in_signal.channels; trim->length *= effp->in_signal.channels; trim->index = 0; trim->trimmed = 0; effp->out_signal.length = trim->length; return (SOX_SUCCESS); }
static int parse(sox_effect_t * effp, char * * argv, sox_rate_t rate) { priv_t * p = (priv_t *)effp->priv; char const * s, * q; int i; for (i = p->argc - 1; i == 0 || i == 1; --i) { if (argv) /* 1st parse only */ p->pos[i].str = lsx_strdup(argv[i]); s = p->pos[i].str; if (strchr("+-" + 1 - i, *s)) p->pos[i].flag = *s++; if (!(q = lsx_parsesamples(rate, s, &p->pos[i].at, 't')) || *q) break; } return i >= 0 ? lsx_usage(effp) : SOX_SUCCESS; }
static int parse(sox_effect_t * effp, char **argv, sox_rate_t rate) { priv_t *p = (priv_t *) effp->priv; size_t i; char const *next; uint64_t last_seen = 0; const uint64_t in_length = argv ? 0 : (effp->in_signal.length != SOX_UNKNOWN_LEN ? effp->in_signal.length / effp->in_signal.channels : SOX_UNKNOWN_LEN); for (i = 0; i < p->nbends; ++i) { if (argv) /* 1st parse only */ p->bends[i].str = lsx_strdup(argv[i]); next = lsx_parseposition(rate, p->bends[i].str, argv ? NULL : &p->bends[i].start, last_seen, in_length, '+'); last_seen = p->bends[i].start; if (next == NULL || *next != ',') break; p->bends[i].cents = strtod(next + 1, (char **)&next); if (p->bends[i].cents == 0 || *next != ',') break; next = lsx_parseposition(rate, next + 1, argv ? NULL : &p->bends[i].duration, last_seen, in_length, '+'); last_seen = p->bends[i].duration; if (next == NULL || *next != '\0') break; /* sanity checks */ if (!argv && p->bends[i].duration < p->bends[i].start) { lsx_fail("Bend %" PRIuPTR " has negative width", i+1); break; } if (!argv && i && p->bends[i].start < p->bends[i-1].start) { lsx_fail("Bend %" PRIuPTR " overlaps with previous one", i+1); break; } p->bends[i].duration -= p->bends[i].start; } if (i < p->nbends) return lsx_usage(effp); return SOX_SUCCESS; }
static int getopts(sox_effect_t * effp, int argc, char * * argv) { priv_t * p = (priv_t *) effp->priv; sox_bool is_cents = sox_false; --argc, ++argv; if (argc == 1) { char c, dummy; int scanned = sscanf(*argv, "%lf%c %c", &p->factor, &c, &dummy); if (scanned == 1 || (scanned == 2 && c == 'c')) { is_cents |= scanned == 2; if (is_cents || p->factor > 0) { p->factor = is_cents? pow(2., p->factor / 1200) : p->factor; return SOX_SUCCESS; } } } return lsx_usage(effp); }
static int create(sox_effect_t * effp, int argc, char **argv) { priv_t *p = (priv_t *) effp->priv; char const * opts = "f:o:"; int c; lsx_getopt_t optstate; lsx_getopt_init(argc, argv, opts, NULL, lsx_getopt_flag_none, 1, &optstate); p->frame_rate = 25; p->ovsamp = 16; while ((c = lsx_getopt(&optstate)) != -1) switch (c) { GETOPT_NUMERIC(optstate, 'f', frame_rate, 10 , 80) GETOPT_NUMERIC(optstate, 'o', ovsamp, 4 , 32) default: lsx_fail("unknown option `-%c'", optstate.opt); return lsx_usage(effp); } argc -= optstate.ind, argv += optstate.ind; p->nbends = argc; p->bends = lsx_calloc(p->nbends, sizeof(*p->bends)); return parse(effp, argv, 0.); /* No rate yet; parse with dummy */ }
static int create(sox_effect_t * effp, int argc, char * * argv) { priv_t * p = (priv_t *)effp->priv; size_t delay, max_samples = 0; unsigned i; --argc, ++argv; p->argv = lsx_calloc(p->argc = argc, sizeof(*p->argv)); for (i = 0; i < p->argc; ++i) { char const * next = lsx_parsesamples(1e5, p->argv[i] = lsx_strdup(argv[i]), &delay, 't'); if (!next || *next) { kill(effp); return lsx_usage(effp); } if (delay > max_samples) { max_samples = delay; p->max_arg = p->argv[i]; } } return SOX_SUCCESS; }
static int parse(sox_effect_t * effp, char * * argv, sox_rate_t rate) { priv_t * p = (priv_t *)effp->priv; char const * next; unsigned i; for (i = 0; i < p->npads; ++i) { if (argv) /* 1st parse only */ p->pads[i].str = lsx_strdup(argv[i]); next = lsx_parsesamples(rate, p->pads[i].str, &p->pads[i].pad, 't'); if (next == NULL) break; if (*next == '\0') p->pads[i].start = i? SOX_SIZE_MAX : 0; else { if (*next != '@') break; next = lsx_parsesamples(rate, next+1, &p->pads[i].start, 't'); if (next == NULL || *next != '\0') break; } if (i > 0 && p->pads[i].start <= p->pads[i-1].start) break; } if (i < p->npads) return lsx_usage(effp); return SOX_SUCCESS; }
/* * Process command-line options but don't do other * initialization now: effp->in_signal & effp->out_signal are not * yet filled in. */ static int getopts(sox_effect_t* effp, int argc, char** argv) { priv_t* p = (priv_t*)effp->priv; const size_t agcDefault = 100; const size_t denoiseDefault = 15; const size_t fpsDefault = 50; for (argc--, argv++; argc; argc--, argv++) { if (!strcasecmp("-agc", argv[0])) { /* AGC level argument is optional. If not specified, it defaults to agcDefault. If specified, it must be from 0 to 100. */ if (!get_param(&argc, &argv, &p->agc, agcDefault, 0, 100)) { lsx_fail("Invalid argument \"%s\" to -agc parameter - expected number from 0 to 100.", argv[1]); return lsx_usage(effp); } } else if (!strcasecmp("-denoise", argv[0])) { /* Denoise level argument is optional. If not specified, it defaults to denoiseDefault. If specified, it must be from 0 to 100. */ if (!get_param(&argc, &argv, &p->denoise, denoiseDefault, 0, 100)) { lsx_fail("Invalid argument \"%s\" to -denoise parameter - expected number from 0 to 100.", argv[1]); return lsx_usage(effp); } } else if (!strcasecmp("-dereverb", argv[0])) { p->dereverb = 1; } else if (!strcasecmp("-spf", argv[0])) { /* If samples_per_frame option is given, argument is required and must be greater than 0. */ if (!get_param(&argc, &argv, &p->samples_per_frame, 0, 1, 1000000000) || !p->samples_per_frame) { lsx_fail("Invalid argument \"%s\" to -spf parameter - expected positive number.", argv[1]); return lsx_usage(effp); } } else if (!strcasecmp("-fps", argv[0])) { /* If frames_per_second option is given, argument is required and must be from 1 to 100. This will be used later to compute samples_per_frame once we know the sample rate). */ if (!get_param(&argc, &argv, &p->frames_per_second, 0, 1, 100) || !p->frames_per_second) { lsx_fail("Invalid argument \"%s\" to -fps parameter - expected number from 1 to 100.", argv[1]); return lsx_usage(effp); } } else { lsx_fail("Invalid parameter \"%s\".", argv[0]); return lsx_usage(effp); } } if (!p->frames_per_second) p->frames_per_second = fpsDefault; if (!p->agc && !p->denoise && !p->dereverb) { lsx_report("No features specified. Enabling default settings \"-agc %u -denoise %u\".", agcDefault, denoiseDefault); p->agc = agcDefault; p->denoise = denoiseDefault; } return SOX_SUCCESS; }
static int getopts(sox_effect_t * effp, int argc, char * * argv) { priv_t * l = (priv_t *) effp->priv; char * s; char dummy; /* To check for extraneous chars. */ unsigned pairs, i, j, commas; --argc, ++argv; if (argc < 2 || argc > 5) return lsx_usage(effp); /* Start by checking the attack and decay rates */ for (s = argv[0], commas = 0; *s; ++s) if (*s == ',') ++commas; if ((commas % 2) == 0) { lsx_fail("there must be an even number of attack/decay parameters"); return SOX_EOF; } pairs = 1 + commas/2; l->channels = lsx_calloc(pairs, sizeof(*l->channels)); l->expectedChannels = pairs; /* Now tokenise the rates string and set up these arrays. Keep them in seconds at the moment: we don't know the sample rate yet. */ for (i = 0, s = strtok(argv[0], ","); s != NULL; ++i) { for (j = 0; j < 2; ++j) { if (sscanf(s, "%lf %c", &l->channels[i].attack_times[j], &dummy) != 1) { lsx_fail("syntax error trying to read attack/decay time"); return SOX_EOF; } else if (l->channels[i].attack_times[j] < 0) { lsx_fail("attack & decay times can't be less than 0 seconds"); return SOX_EOF; } s = strtok(NULL, ","); } } if (!lsx_compandt_parse(&l->transfer_fn, argv[1], argc>2 ? argv[2] : 0)) return SOX_EOF; /* Set the initial "volume" to be attibuted to the input channels. Unless specified, choose 0dB otherwise clipping will result if the user has seleced a long attack time */ for (i = 0; i < l->expectedChannels; ++i) { double init_vol_dB = 0; if (argc > 3 && sscanf(argv[3], "%lf %c", &init_vol_dB, &dummy) != 1) { lsx_fail("syntax error trying to read initial volume"); return SOX_EOF; } else if (init_vol_dB > 0) { lsx_fail("initial volume is relative to maximum volume so can't exceed 0dB"); return SOX_EOF; } l->channels[i].volume = pow(10., init_vol_dB / 20); } /* If there is a delay, store it. */ if (argc > 4 && sscanf(argv[4], "%lf %c", &l->delay, &dummy) != 1) { lsx_fail("syntax error trying to read delay value"); return SOX_EOF; } else if (l->delay < 0) { lsx_fail("delay can't be less than 0 seconds"); return SOX_EOF; } return SOX_SUCCESS; }
static int sox_fade_getopts(sox_effect_t * effp, int argc, char **argv) { priv_t * fade = (priv_t *) effp->priv; char t_char[2]; int t_argno; uint64_t samples; const char *n; --argc, ++argv; if (argc < 1 || argc > 4) return lsx_usage(effp); /* because sample rate is unavailable at this point we store the * string off for later computations. */ if (sscanf(argv[0], "%1[qhltp]", t_char)) { fade->in_fadetype = *t_char; fade->out_fadetype = *t_char; argv++; argc--; } else { /* No type given. */ fade->in_fadetype = 'l'; fade->out_fadetype = 'l'; } fade->in_stop_str = lsx_strdup(argv[0]); /* Do a dummy parse to see if it will fail */ n = lsx_parsesamples(0., fade->in_stop_str, &samples, 't'); if (!n || *n) return lsx_usage(effp); fade->in_stop = samples; fade->out_start_str = fade->out_stop_str = 0; for (t_argno = 1; t_argno < argc && t_argno < 3; t_argno++) { /* See if there is fade-in/fade-out times/curves specified. */ if(t_argno == 1) { fade->out_stop_str = lsx_strdup(argv[t_argno]); /* Do a dummy parse to see if it will fail */ n = lsx_parseposition(0., fade->out_stop_str, NULL, (uint64_t)0, (uint64_t)0, '='); if (!n || *n) return lsx_usage(effp); fade->out_stop = samples; } else { fade->out_start_str = lsx_strdup(argv[t_argno]); /* Do a dummy parse to see if it will fail */ n = lsx_parsesamples(0., fade->out_start_str, &samples, 't'); if (!n || *n) return lsx_usage(effp); fade->out_start = samples; } } /* End for(t_argno) */ return(SOX_SUCCESS); }
static int sox_silence_getopts(sox_effect_t * effp, int argc, char **argv) { priv_t * silence = (priv_t *) effp->priv; int parse_count; uint64_t temp; const char *n; --argc, ++argv; /* check for option switches */ silence->leave_silence = sox_false; if (argc > 0) { if (!strcmp("-l", *argv)) { argc--; argv++; silence->leave_silence = sox_true; } } if (argc < 1) return lsx_usage(effp); /* Parse data related to trimming front side */ silence->start = sox_false; if (sscanf(argv[0], "%d", &silence->start_periods) != 1) return lsx_usage(effp); if (silence->start_periods < 0) { lsx_fail("Periods must not be negative"); return(SOX_EOF); } argv++; argc--; if (silence->start_periods > 0) { silence->start = sox_true; if (argc < 2) return lsx_usage(effp); /* We do not know the sample rate so we can not fully * parse the duration info yet. So save argument off * for future processing. */ silence->start_duration_str = lsx_strdup(argv[0]); /* Perform a fake parse to do error checking */ n = lsx_parsesamples(0.,silence->start_duration_str,&temp,'s'); if (!n || *n) return lsx_usage(effp); silence->start_duration = temp; parse_count = sscanf(argv[1], "%lf%c", &silence->start_threshold, &silence->start_unit); if (parse_count < 1) return lsx_usage(effp); else if (parse_count < 2) silence->start_unit = '%'; argv++; argv++; argc--; argc--; } silence->stop = sox_false; /* Parse data needed for trimming of backside */ if (argc > 0) { if (argc < 3) return lsx_usage(effp); if (sscanf(argv[0], "%d", &silence->stop_periods) != 1) return lsx_usage(effp); if (silence->stop_periods < 0) { silence->stop_periods = -silence->stop_periods; silence->restart = 1; } else silence->restart = 0; silence->stop = sox_true; argv++; argc--; /* We do not know the sample rate so we can not fully * parse the duration info yet. So save argument off * for future processing. */ silence->stop_duration_str = lsx_strdup(argv[0]); /* Perform a fake parse to do error checking */ n = lsx_parsesamples(0.,silence->stop_duration_str,&temp,'s'); if (!n || *n) return lsx_usage(effp); silence->stop_duration = temp; parse_count = sscanf(argv[1], "%lf%c", &silence->stop_threshold, &silence->stop_unit); if (parse_count < 1) return lsx_usage(effp); else if (parse_count < 2) silence->stop_unit = '%'; argv++; argv++; argc--; argc--; } /* Error checking */ if (silence->start) { if ((silence->start_unit != '%') && (silence->start_unit != 'd')) { lsx_fail("Invalid unit specified"); return lsx_usage(effp); } if ((silence->start_unit == '%') && ((silence->start_threshold < 0.0) || (silence->start_threshold > 100.0))) { lsx_fail("silence threshold should be between 0.0 and 100.0 %%"); return (SOX_EOF); } if ((silence->start_unit == 'd') && (silence->start_threshold >= 0.0)) { lsx_fail("silence threshold should be less than 0.0 dB"); return(SOX_EOF); } } if (silence->stop) { if ((silence->stop_unit != '%') && (silence->stop_unit != 'd')) { lsx_fail("Invalid unit specified"); return(SOX_EOF); } if ((silence->stop_unit == '%') && ((silence->stop_threshold < 0.0) || (silence->stop_threshold > 100.0))) { lsx_fail("silence threshold should be between 0.0 and 100.0 %%"); return (SOX_EOF); } if ((silence->stop_unit == 'd') && (silence->stop_threshold >= 0.0)) { lsx_fail("silence threshold should be less than 0.0 dB"); return(SOX_EOF); } } return(SOX_SUCCESS); }
static int getopts(sox_effect_t * effp, int argc, char **argv) { priv_t * p = (priv_t *)effp->priv; do {NUMERIC_PARAMETER(repeats, 0, 1e6)} while (0); return argc? lsx_usage(effp) : SOX_SUCCESS; }
static int oops_getopts(sox_effect_t * effp, int argc, char * * argv) { char * args[] = {0, "1,1,-1,-1"}; args[0] = argv[0]; return --argc? lsx_usage(effp) : lsx_mixer_effect_fn()->getopts(effp, (int)array_length(args), args); }
/* * Prepare processing. * Do all initializations. */ static int sox_fade_start(sox_effect_t * effp) { priv_t * fade = (priv_t *) effp->priv; sox_bool truncate = sox_false; uint64_t samples; uint64_t in_length = effp->in_signal.length != SOX_UNKNOWN_LEN ? effp->in_signal.length / effp->in_signal.channels : SOX_UNKNOWN_LEN; /* converting time values to samples */ fade->in_start = 0; if (lsx_parsesamples(effp->in_signal.rate, fade->in_stop_str, &samples, 't') == NULL) return lsx_usage(effp); fade->in_stop = samples; fade->do_out = 0; /* See if user specified a stop time */ if (fade->out_stop_str) { fade->do_out = 1; if (!lsx_parseposition(effp->in_signal.rate, fade->out_stop_str, &samples, (uint64_t)0, in_length, '=') || samples == SOX_UNKNOWN_LEN) { lsx_fail("audio length is unknown"); return SOX_EOF; } fade->out_stop = samples; if (!(truncate = !!fade->out_stop)) { fade->out_stop = effp->in_signal.length != SOX_UNKNOWN_LEN ? effp->in_signal.length / effp->in_signal.channels : 0; if (!fade->out_stop) { lsx_fail("cannot fade out: audio length is neither known nor given"); return SOX_EOF; } } /* See if user wants to fade out. */ if (fade->out_start_str) { if (lsx_parsesamples(effp->in_signal.rate, fade->out_start_str, &samples, 't') == NULL) return lsx_usage(effp); /* Fade time is relative to stop time. */ fade->out_start = fade->out_stop - samples; } else /* If user doesn't specify fade out length then * use same length as input side. This is stored * in in_stop. */ fade->out_start = fade->out_stop - fade->in_stop; } else /* If not specified then user wants to process all * of file. Use a value of zero to indicate this. */ fade->out_stop = 0; if (fade->out_start) { /* Sanity check */ if (fade->in_stop > fade->out_start) --fade->in_stop; /* 1 sample grace for rounding error. */ if (fade->in_stop > fade->out_start) { lsx_fail("fade-out overlaps fade-in"); return SOX_EOF; } } fade->samplesdone = fade->in_start; fade->endpadwarned = 0; lsx_debug("in_start = %" PRIu64 " in_stop = %" PRIu64 " " "out_start = %" PRIu64 " out_stop = %" PRIu64, fade->in_start, fade->in_stop, fade->out_start, fade->out_stop); if (fade->in_start == fade->in_stop && !truncate && fade->out_start == fade->out_stop) return SOX_EFF_NULL; effp->out_signal.length = truncate ? fade->out_stop * effp->in_signal.channels : effp->in_signal.length; return SOX_SUCCESS; }