ref: e8b8568401bd122e2822220b496f1a40ac992c31
parent: d5aabbc466238d0231e17568ad52f123eb6f2616
author: robs <robs>
date: Sun Feb 10 13:42:43 EST 2008
various small clean-ups
--- a/soxeffect.7
+++ b/soxeffect.7
@@ -268,7 +268,7 @@
.TP
\fBearwax\fR
Makes audio easier to listen to on headphones.
-Adds `cues' to audio in audio-CD format so that
+Adds `cues' to 44.1kHz stereo (i.e. audio CD format) audio so that
when listened to on headphones the stereo image is
moved from inside
your head (standard for headphones) to outside and in front of the
--- a/src/earwax.c
+++ b/src/earwax.c
@@ -1,6 +1,6 @@
/*
* earwax - makes listening to headphones easier
- *
+ *
* This effect takes a stereo sound that is meant to be listened to
* on headphones, and adds audio cues to move the soundstage from inside
* your head (standard for headphones) to outside and in front of the
@@ -7,174 +7,97 @@
* listener (standard for speakers). This makes the sound much easier to
* listen to on headphones. See www.geocities.com/beinges for a full
* explanation.
- *
- * Usage:
+ *
+ * Usage:
* earwax
*
* Note:
- * This filter only works for 44.1 kHz stereo signals (cd format)
- *
+ * This filter only works for 44.1 kHz stereo signals (CD format)
+ *
* November 9, 2000
- * Copyright (C) 2000 Edward Beingessner And Sundry Contributors
+ * Copyright (c) 2000 Edward Beingessner And Sundry Contributors
* This source code is freely redistributable and may be used for
- * any purpose. This copyright notice must be maintained.
- * Edward Beingessner And Sundry Contributors are not responsible for
+ * any purpose. This copyright notice must be maintained.
+ * Edward Beingessner And Sundry Contributors are not responsible for
* the consequences of using this software.
*/
#include "sox_i.h"
+#include <string.h>
-#define EARWAX_SCALE 64
+static const sox_sample_t filt[32 * 2] = {
+/* 30° 330° */
+ 4, -6, /* 32 tap stereo FIR filter. */
+ 4, -11, /* One side filters as if the */
+ -1, -5, /* signal was from 30 degrees */
+ 3, 3, /* from the ear, the other as */
+ -2, 5, /* if 330 degrees. */
+ -5, 0,
+ 9, 1,
+ 6, 3, /* Input */
+ -4, -1, /* Left Right */
+ -5, -3, /* __________ __________ */
+ -2, -5, /* | | | | */
+ -7, 1, /* .---| Hh,0(f) | | Hh,0(f) |---. */
+ 6, -7, /* / |__________| |__________| \ */
+ 30, -29, /* / \ / \ */
+ 12, -3, /* / X \ */
+ -11, 4, /* / / \ \ */
+ -3, 7, /* ____V_____ __________V V__________ _____V____ */
+ -20, 23, /* | | | | | | | | */
+ 2, 0, /* | Hh,30(f) | | Hh,330(f)| | Hh,330(f)| | Hh,30(f) | */
+ 1, -6, /* |__________| |__________| |__________| |__________| */
+ -14, -5, /* \ ___ / \ ___ / */
+ 15, -18, /* \ / \ / _____ \ / \ / */
+ 6, 7, /* `->| + |<--' / \ `-->| + |<-' */
+ 15, -10, /* \___/ _/ \_ \___/ */
+ -14, 22, /* \ / \ / \ / */
+ -7, -2, /* `--->| | | |<---' */
+ -4, 9, /* \_/ \_/ */
+ 6, -12, /* */
+ 6, -6, /* Headphones */
+ 0, -11,
+ 0, -5,
+ 4, 0};
-/* A stereo fir filter. One side filters as if the signal was from
- 30 degrees from the ear, the other as if 330 degrees. */
-/* 30 330 */
-static const sox_sample_t filt[] =
-{ 4, -6,
- 4, -11,
- -1, -5,
- 3, 3,
- -2, 5,
- -5, 0,
- 9, 1,
- 6, 3,
- -4, -1,
- -5, -3,
- -2, -5,
- -7, 1,
- 6, -7,
- 30, -29,
- 12, -3,
- -11, 4,
- -3, 7,
- -20, 23,
- 2, 0,
- 1, -6,
- -14, -5,
- 15, -18,
- 6, 7,
- 15, -10,
- -14, 22,
- -7, -2,
- -4, 9,
- 6, -12,
- 6, -6,
- 0, -11,
- 0, -5,
- 4, 0};
+#define EARWAX_NUMTAPS array_length(filt)
+#define taps ((sox_sample_t *)&(effp->priv)) /* FIR filter z^-1 delays */
-/* 32 tap stereo FIR filter needs 64 taps */
-#define EARWAX_NUMTAPS 64
-
-typedef struct earwaxstuff {
- sox_sample_t *tap; /* taps are z^-1 delays for the FIR filter */
-} *earwax_t;
-
-/*
- * Prepare for processing.
- */
-static int sox_earwax_start(sox_effect_t * effp)
+static int start(sox_effect_t * effp)
{
- earwax_t earwax = (earwax_t) effp->priv;
- int i;
-
- /* check the input format */
+ assert_static(EARWAX_NUMTAPS * sizeof(*taps) <= SOX_MAX_EFFECT_PRIVSIZE,
+ /* else */ earwax_PRIVSIZE_too_big);
if (effp->ininfo.rate != 44100 || effp->ininfo.channels != 2) {
- sox_fail("The earwax effect works only with 44.1 kHz, stereo audio.");
- return (SOX_EOF);
+ sox_fail("works only with 44.1kHz stereo audio");
+ return SOX_EOF;
}
-
- /* allocate tap memory */
- earwax->tap = (sox_sample_t*)xmalloc( sizeof(sox_sample_t) * EARWAX_NUMTAPS );
-
- /* zero out the delayed taps */
- for(i=0; i < EARWAX_NUMTAPS; i++ ){
- earwax->tap[i] = 0;
- }
-
- return (SOX_SUCCESS);
+ memset(taps, 0, EARWAX_NUMTAPS * sizeof(*taps)); /* zero tap memory */
+ return SOX_SUCCESS;
}
-/*
- * Processed signed long samples from ibuf to obuf.
- * Return number of samples processed.
- */
-
-static int sox_earwax_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obuf,
- sox_size_t *isamp, sox_size_t *osamp)
+static int flow(sox_effect_t * effp, const sox_sample_t * ibuf,
+ sox_sample_t * obuf, sox_size_t * isamp, sox_size_t * osamp)
{
- earwax_t earwax = (earwax_t) effp->priv;
- int len, done;
- int i;
- sox_sample_t output;
+ sox_size_t i, len = *isamp = *osamp = min(*isamp, *osamp);
- len = ((*isamp > *osamp) ? *osamp : *isamp);
+ while (len--) { /* update taps and calculate output */
+ sox_sample_t output = 0;
- for(done = 0; done < len; done++) {
-
- /* update taps and calculate output */
- output = 0;
- for(i = EARWAX_NUMTAPS-1; i > 0; i--) {
- earwax->tap[i] = earwax->tap[i-1];
- output += earwax->tap[i] * filt[i];
+ for (i = EARWAX_NUMTAPS - 1; i; --i) {
+ taps[i] = taps[i - 1];
+ output += taps[i] * filt[i];
}
- earwax->tap[0] = *ibuf++ / EARWAX_SCALE;
- output += earwax->tap[0] * filt[i];
-
- /* store scaled output */
- *obuf++ = output;
+ taps[0] = *ibuf++ / 64;
+ *obuf++ = output + taps[0] * filt[0]; /* store scaled output */
}
-
- *isamp = *osamp = len;
- return (SOX_SUCCESS);
+ return SOX_SUCCESS;
}
-/*
- * Drain out taps.
- */
-static int sox_earwax_drain(sox_effect_t * effp, sox_sample_t *obuf, sox_size_t *osamp)
-{
- earwax_t earwax = (earwax_t) effp->priv;
- int i,j;
- sox_sample_t output;
+/* No drain: preserve audio file length; it's only 32 samples anyway. */
- for(i = EARWAX_NUMTAPS-1; i >= 0; i--){
- output = 0;
- for(j = 0; j < i; j++ ){
- output += filt[j+(EARWAX_NUMTAPS-i)] * earwax->tap[j];
- }
- *obuf++ = output;
- }
- *osamp = EARWAX_NUMTAPS-1;
-
- return (SOX_EOF);
-}
-
-/*
- * Clean up taps.
- */
-static int sox_earwax_stop(sox_effect_t * effp)
+sox_effect_handler_t const *sox_earwax_effect_fn(void)
{
- earwax_t earwax = (earwax_t) effp->priv;
-
- free((char *)earwax->tap);
-
- return (SOX_SUCCESS);
-}
-
-static sox_effect_handler_t sox_earwax_effect = {
- "earwax",
- NULL,
- SOX_EFF_MCHAN|SOX_EFF_LENGTH,
- NULL,
- sox_earwax_start,
- sox_earwax_flow,
- sox_earwax_drain,
- sox_earwax_stop,
- NULL
-};
-
-const sox_effect_handler_t *sox_earwax_effect_fn(void)
-{
- return &sox_earwax_effect;
+ static sox_effect_handler_t handler = {
+ "earwax", NULL, SOX_EFF_MCHAN, NULL, start, flow, NULL, NULL, NULL};
+ return &handler;
}
--- a/src/echo.c
+++ b/src/echo.c
@@ -59,7 +59,7 @@
#include <math.h>
#include "sox_i.h"
-#define DELAY_BUFSIZ ( 50 * SOX_MAXRATE )
+#define DELAY_BUFSIZ ( 50 * 50U * 1024 )
#define MAX_ECHOS 7 /* 24 bit x ( 1 + MAX_ECHOS ) = */
/* 24 bit x 8 = 32 bit !!! */
--- a/src/echos.c
+++ b/src/echos.c
@@ -50,7 +50,7 @@
#include <math.h>
#include "sox_i.h"
-#define DELAY_BUFSIZ ( 50 * SOX_MAXRATE )
+#define DELAY_BUFSIZ ( 50 * 50U * 1024 )
#define MAX_ECHOS 7 /* 24 bit x ( 1 + MAX_ECHOS ) = */
/* 24 bit x 8 = 32 bit !!! */
--- a/src/fade.c
+++ b/src/fade.c
@@ -75,7 +75,7 @@
fade->in_stop_str = (char *)xmalloc(strlen(argv[0])+1);
strcpy(fade->in_stop_str,argv[0]);
/* Do a dummy parse to see if it will fail */
- if (sox_parsesamples(0, fade->in_stop_str, &fade->in_stop, 't') == NULL)
+ if (sox_parsesamples(0., fade->in_stop_str, &fade->in_stop, 't') == NULL)
return sox_usage(effp);
fade->out_start_str = fade->out_stop_str = 0;
@@ -89,7 +89,7 @@
strcpy(fade->out_stop_str,argv[t_argno]);
/* Do a dummy parse to see if it will fail */
- if (sox_parsesamples(0, fade->out_stop_str,
+ if (sox_parsesamples(0., fade->out_stop_str,
&fade->out_stop, 't') == NULL)
return sox_usage(effp);
}
@@ -99,7 +99,7 @@
strcpy(fade->out_start_str,argv[t_argno]);
/* Do a dummy parse to see if it will fail */
- if (sox_parsesamples(0, fade->out_start_str,
+ if (sox_parsesamples(0., fade->out_start_str,
&fade->out_start, 't') == NULL)
return sox_usage(effp);
}
--- a/src/flac.c
+++ b/src/flac.c
@@ -335,7 +335,7 @@
FLAC__stream_encoder_set_channels(encoder->flac, ft->signal.channels);
FLAC__stream_encoder_set_bits_per_sample(encoder->flac, encoder->bits_per_sample);
- FLAC__stream_encoder_set_sample_rate(encoder->flac, ft->signal.rate);
+ FLAC__stream_encoder_set_sample_rate(encoder->flac, (unsigned)(ft->signal.rate + .5));
{ /* Check if rate is streamable: */
static const unsigned streamable_rates[] =
--- a/src/pad.c
+++ b/src/pad.c
@@ -64,7 +64,7 @@
{
pad_t p = (pad_t) effp->priv;
p->pads = xcalloc(p->npads = n, sizeof(*p->pads));
- return parse(effp, argv, SOX_MAXRATE); /* No rate yet; parse with dummy */
+ return parse(effp, argv, 96000.); /* No rate yet; parse with dummy */
}
static int start(sox_effect_t * effp)
--- a/src/polyphas.c
+++ b/src/polyphas.c
@@ -44,8 +44,8 @@
} polystage;
typedef struct polyphase {
- sox_rate_t lcmrate; /* least common multiple of rates */
- sox_rate_t inskip, outskip; /* LCM increments for I & O rates */
+ unsigned lcmrate; /* least common multiple of rates */
+ unsigned inskip, outskip; /* LCM increments for I & O rates */
double Factor; /* out_rate/in_rate */
unsigned long total; /* number of filter stages */
sox_size_t oskip; /* output samples to skip at start*/
--- a/src/silence.c
+++ b/src/silence.c
@@ -121,7 +121,7 @@
silence->start_duration_str = (char *)xmalloc(strlen(argv[0])+1);
strcpy(silence->start_duration_str,argv[0]);
/* Perform a fake parse to do error checking */
- if (sox_parsesamples(0,silence->start_duration_str,
+ if (sox_parsesamples(0.,silence->start_duration_str,
&silence->start_duration,'s') == NULL)
return sox_usage(effp);
@@ -162,7 +162,7 @@
silence->stop_duration_str = (char *)xmalloc(strlen(argv[0])+1);
strcpy(silence->stop_duration_str,argv[0]);
/* Perform a fake parse to do error checking */
- if (sox_parsesamples(0,silence->stop_duration_str,
+ if (sox_parsesamples(0.,silence->stop_duration_str,
&silence->stop_duration,'s') == NULL)
return sox_usage(effp);
--- a/src/sox.c
+++ b/src/sox.c
@@ -539,7 +539,9 @@
return strcaseends(filename, ".m3u") || strcaseends(filename, ".pls");
}
-static void parse_playlist(int (* callback)(void *, char *), void * p, char const * const listname)
+typedef int (* playlist_callback_t)(void *, char *);
+
+static void parse_playlist(playlist_callback_t callback, void * p, char const * const listname)
{
sox_bool is_pls = strcaseends(listname, ".pls");
int comment_char = "#;"[is_pls];
@@ -658,7 +660,7 @@
printf("Usage: soxi [-r|-c|-s|-d|-b|-e|-a] infile1 ...\n");
else for (; optind < argc; ++optind) {
if (is_playlist(argv[optind]))
- parse_playlist(soxi1, &type, argv[optind]);
+ parse_playlist((playlist_callback_t)soxi1, &type, argv[optind]);
else soxi1(&type, argv[optind]);
}
exit(0);
@@ -702,7 +704,7 @@
if (optind >= argc || sox_find_effect(argv[optind]))
break;
if (is_playlist(argv[optind])) {
- parse_playlist(add_file, f, argv[optind++]);
+ parse_playlist((playlist_callback_t)add_file, f, argv[optind++]);
free(f);
f = NULL;
continue;
@@ -1611,7 +1613,7 @@
if (!known_length)
olen = 0;
- open_output_file(olen * ofile->signal.channels * ofile->signal.rate / combiner.rate + .5);
+ open_output_file((sox_size_t)(olen * ofile->signal.channels * ofile->signal.rate / combiner.rate + .5));
ofile_effects_chain.global_info = sox_effects_globals;
add_effects(&ofile_effects_chain);
--- a/src/sox.h
+++ b/src/sox.h
@@ -175,10 +175,6 @@
#define SOX_SSIZE_MIN (-SOX_SSIZE_MAX - 1)
typedef double sox_rate_t;
-/* Warning, this is a MAX value used in the library. Each format and
- * effect may have its own limitations of rate.
- */
-#define SOX_MAXRATE (50U * 1024) /* maximum sample rate in library */
typedef enum {
SOX_ENCODING_UNKNOWN ,
--- a/src/splice.c
+++ b/src/splice.c
@@ -99,12 +99,12 @@
for (i = 0; i < p->nsplices; ++i) {
if (argv) /* 1st parse only */
p->splices[i].str = xstrdup(argv[i]);
-
+
p->splices[i].overlap = p->splices[i].search = rate * 0.01 + .5;
next = sox_parsesamples(rate, p->splices[i].str, &p->splices[i].start, 't');
if (next == NULL) break;
-
+
if (*next == ',') {
next = sox_parsesamples(rate, next + 1, &p->splices[i].overlap, 't');
if (next == NULL) break;
@@ -118,7 +118,7 @@
if (*next != '\0') break;
p->splices[i].overlap = max(p->splices[i].overlap + 4, 16);
p->splices[i].overlap &= ~7; /* Make divisible by 8 for loop optimisation */
-
+
if (i > 0 && p->splices[i].start <= p->splices[i-1].start) break;
if (p->splices[i].start < p->splices[i].overlap) break;
p->splices[i].start -= p->splices[i].overlap;
@@ -134,7 +134,7 @@
{
splice_t p = (splice_t) effp->priv;
p->splices = xcalloc(p->nsplices = n, sizeof(*p->splices));
- return parse(effp, argv, SOX_MAXRATE); /* No rate yet; parse with dummy */
+ return parse(effp, argv, 96000.); /* No rate yet; parse with dummy */
}
static int start(sox_effect_t * effp)
--- a/src/synth.c
+++ b/src/synth.c
@@ -290,7 +290,7 @@
synth->length_str = xmalloc(strlen(argv[argn]) + 1);
strcpy(synth->length_str, argv[argn]);
/* Do a dummy parse of to see if it will fail */
- if (sox_parsesamples(0, synth->length_str, &synth->samples_to_do, 't') == NULL)
+ if (sox_parsesamples(0., synth->length_str, &synth->samples_to_do, 't') == NULL)
return sox_usage(effp);
argn++;
}
--- a/src/trim.c
+++ b/src/trim.c
@@ -39,13 +39,13 @@
trim->length_str = (char *)xmalloc(strlen(argv[1])+1);
strcpy(trim->length_str,argv[1]);
/* Do a dummy parse to see if it will fail */
- if (sox_parsesamples(0, trim->length_str, &trim->length, 't') == NULL)
+ if (sox_parsesamples(0., trim->length_str, &trim->length, 't') == NULL)
return sox_usage(effp);
case 1:
trim->start_str = (char *)xmalloc(strlen(argv[0])+1);
strcpy(trim->start_str,argv[0]);
/* Do a dummy parse to see if it will fail */
- if (sox_parsesamples(0, trim->start_str, &trim->start, 't') == NULL)
+ if (sox_parsesamples(0., trim->start_str, &trim->start, 't') == NULL)
return sox_usage(effp);
break;
default: