ref: 3a158e1a59e0d9633aea0c23686ea675905ff97e
parent: 14fe92ccea9bc6bdd013c6a917792e965cc168d4
author: robs <robs>
date: Sun Jun 15 12:32:33 EDT 2008
Allow k suffix on frequencies
--- a/src/biquad.c
+++ b/src/biquad.c
@@ -22,12 +22,13 @@
static char const * const width_str[] = {
"band-width(Hz)",
+ "band-width(kHz)",
"band-width(Hz, no warp)", /* deprecated */
"band-width(octaves)",
"Q",
"slope",
};
-static char const all_width_types[] = "hboqs";
+static char const all_width_types[] = "hkboqs";
int sox_biquad_getopts(sox_effect_t * effp, int n, char **argv,
@@ -36,11 +37,11 @@
{
priv_t * p = (priv_t *)effp->priv;
char width_type = *allowed_width_types;
- char dummy; /* To check for extraneous chars. */
+ char dummy, * dummy_p; /* To check for extraneous chars. */
p->filter_type = filter_type;
if (n < min_args || n > max_args ||
- (n > fc_pos && (sscanf(argv[fc_pos], "%lf %c", &p->fc, &dummy) != 1 || p->fc <= 0)) ||
+ (n > fc_pos && ((p->fc = lsx_parse_frequency(argv[fc_pos], &dummy_p)) <= 0 || *dummy_p)) ||
(n > width_pos && ((unsigned)(sscanf(argv[width_pos], "%lf%c %c", &p->width, &width_type, &dummy)-1) > 1 || p->width <= 0)) ||
(n > gain_pos && sscanf(argv[gain_pos], "%lf %c", &p->gain, &dummy) != 1) ||
!strchr(allowed_width_types, width_type) || (width_type == 's' && p->width > 1))
@@ -48,6 +49,10 @@
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;
}
--- a/src/biquad.h
+++ b/src/biquad.h
@@ -41,6 +41,7 @@
typedef enum {
width_bw_Hz,
+ width_bw_kHz,
/* The old, non-RBJ, non-freq-warped band-pass/reject response;
* leaving here for now just in case anybody misses it: */
width_bw_old,
--- a/src/biquads.c
+++ b/src/biquads.c
@@ -59,6 +59,7 @@
#include "biquad.h"
+#include <assert.h>
#include <string.h>
typedef biquad_t priv_t;
@@ -77,7 +78,7 @@
if (n != 0 && strcmp(argv[0], "-2") == 0)
++argv, --n;
p->width = sqrt(0.5); /* Default to Butterworth */
- return sox_biquad_getopts(effp, n, argv, 1, 2, 0, 1, 2, "qoh",
+ return sox_biquad_getopts(effp, n, argv, 1, 2, 0, 1, 2, "qohk",
*effp->handler.name == 'l'? filter_LPF : filter_HPF);
}
@@ -86,12 +87,12 @@
filter_t type = filter_BPF;
if (n != 0 && strcmp(argv[0], "-c") == 0)
++argv, --n, type = filter_BPF_CSG;
- return sox_biquad_getopts(effp, n, argv, 2, 2, 0, 1, 2, "hqob", type);
+ return sox_biquad_getopts(effp, n, argv, 2, 2, 0, 1, 2, "hkqob", type);
}
static int bandrej_getopts(sox_effect_t * effp, int n, char **argv) {
- return sox_biquad_getopts(effp, n, argv, 2, 2, 0, 1, 2, "hqob", filter_notch);
+ return sox_biquad_getopts(effp, n, argv, 2, 2, 0, 1, 2, "hkqob", filter_notch);
}
@@ -103,7 +104,7 @@
else if (n != 0 && strcmp(argv[0], "-2") == 0)
++argv, --n, type = filter_AP2;
m = 1 + (type == filter_APF);
- return sox_biquad_getopts(effp, n, argv, m, m, 0, 1, 2, "hqo", type);
+ return sox_biquad_getopts(effp, n, argv, m, m, 0, 1, 2, "hkqo", type);
}
@@ -111,13 +112,13 @@
priv_t * p = (priv_t *)effp->priv;
p->width = 0.5;
p->fc = *effp->handler.name == 'b'? 100 : 3000;
- return sox_biquad_getopts(effp, n, argv, 1, 3, 1, 2, 0, "shqo",
+ return sox_biquad_getopts(effp, n, argv, 1, 3, 1, 2, 0, "shkqo",
*effp->handler.name == 'b'? filter_lowShelf: filter_highShelf);
}
static int equalizer_getopts(sox_effect_t * effp, int n, char **argv) {
- return sox_biquad_getopts(effp, n, argv, 3, 3, 0, 1, 2, "qoh", filter_peakingEQ);
+ return sox_biquad_getopts(effp, n, argv, 3, 3, 0, 1, 2, "qohk", filter_peakingEQ);
}
@@ -125,7 +126,7 @@
filter_t type = filter_BPF_SPK;
if (n != 0 && strcmp(argv[0], "-n") == 0)
++argv, --n, type = filter_BPF_SPK_N;
- return sox_biquad_getopts(effp, n, argv, 1, 2, 0, 1, 2, "hqo", type);
+ return sox_biquad_getopts(effp, n, argv, 1, 2, 0, 1, 2, "hkqo", type);
}
@@ -171,6 +172,8 @@
alpha = sin(w0)/(2*p->fc/p->width);
break;
+ case width_bw_kHz: assert(0); /* Shouldn't get here */
+
case width_bw_old:
alpha = tan(M_PI * p->width / effp->in_signal.rate);
break;
@@ -320,13 +323,13 @@
return &handler; \
}
-BIQUAD_EFFECT(highpass, hilo2, "[-1|-2] frequency [width[q|o|h]]", 0)
-BIQUAD_EFFECT(lowpass, hilo2, "[-1|-2] frequency [width[q|o|h]]", 0)
-BIQUAD_EFFECT(bandpass, bandpass, "[-c] frequency width[h|q|o]", 0)
-BIQUAD_EFFECT(bandreject,bandrej, "frequency width[h|q|o]", 0)
-BIQUAD_EFFECT(allpass, allpass, "frequency width[h|q|o]", 0)
-BIQUAD_EFFECT(bass, tone, "gain [frequency [width[s|h|q|o]]]", 0)
-BIQUAD_EFFECT(treble, tone, "gain [frequency [width[s|h|q|o]]]", 0)
-BIQUAD_EFFECT(equalizer, equalizer,"frequency width[q|o|h] gain", 0)
-BIQUAD_EFFECT(band, band, "[-n] center [width[h|q|o]]", 0)
+BIQUAD_EFFECT(highpass, hilo2, "[-1|-2] frequency [width[q|o|h|k](0.707q)]", 0)
+BIQUAD_EFFECT(lowpass, hilo2, "[-1|-2] frequency [width[q|o|h|k]](0.707q)", 0)
+BIQUAD_EFFECT(bandpass, bandpass, "[-c] frequency width[h|k|q|o]", 0)
+BIQUAD_EFFECT(bandreject,bandrej, "frequency width[h|k|q|o]", 0)
+BIQUAD_EFFECT(allpass, allpass, "frequency width[h|k|q|o]", 0)
+BIQUAD_EFFECT(bass, tone, "gain [frequency(100) [width[s|h|k|q|o]](0.5s)]", 0)
+BIQUAD_EFFECT(treble, tone, "gain [frequency(3000) [width[s|h|k|q|o]](0.5s)]", 0)
+BIQUAD_EFFECT(equalizer, equalizer,"frequency width[q|o|h|k] gain", 0)
+BIQUAD_EFFECT(band, band, "[-n] center [width[h|k|q|o]]", 0)
BIQUAD_EFFECT(deemph, deemph, NULL, 0)
--- a/src/mcompand.c
+++ b/src/mcompand.c
@@ -330,7 +330,7 @@
if (i == (c->nBands-1))
c->bands[i].topfreq = 0;
else {
- c->bands[i].topfreq = strtod(argv[(i<<1)+1],&cp);
+ c->bands[i].topfreq = lsx_parse_frequency(argv[(i<<1)+1],&cp);
if (*cp) {
sox_fail("bad frequency in args to mcompand");
return SOX_EOF;
@@ -627,7 +627,7 @@
{
static sox_effect_handler_t handler = {
"mcompand",
- "quoted_compand_args [crossover_frequency quoted_compand_args [...]]\n"
+ "quoted_compand_args [crossover_frequency[k] quoted_compand_args [...]]\n"
"\n"
"quoted_compand_args are as for the compand effect:\n"
"\n"