ref: 8c2ffe1623bd26348f2d371f248e9e33ff4600db
parent: 18a98c11353eb5f5613ced866ec1f6cf1efdfee5
author: cbagwell <cbagwell>
date: Thu Nov 16 12:48:52 EST 2000
Fixed trim effect and man pages to use seconds to compute the location of trims. This aligns with how the fade effect works.
--- a/Changelog
+++ b/Changelog
@@ -31,6 +31,9 @@
o Added new "earwax" effect from Edward Beingessner. It is meant to
be used for CD audio played through headphones. It will move the
sound stage from left/right to in front of you.
+ o Trim effect did not compute locations as was documented in the
+ man pages. Changed effect so that it computed the time the
+ same way that the fade effect does.
sox-12.17
---------
--- a/sox.1
+++ b/sox.1
@@ -1034,8 +1034,8 @@
trim \fIstart\fR [ \fIlength\fR ]
Trim can trim off unwanted audio data from the beginning and end of the
audio file. Audio samples are not sent to the output stream until
-the \fIstart\fR location is reached. \fIstart\fR is an integer number that
-tells the exact sample number to start at.
+the \fIstart\fR location is reached. \fIstart\fR is a floating point number
+that tells the number of seconds to wait before starting.
.br
The optional \fIlength\fR parameter tells the number of samples to output
after the \fIstart\fR sample and is used to trim off the back side of the
--- a/src/sphere.c
+++ b/src/sphere.c
@@ -90,7 +90,7 @@
ft->info.encoding = ST_ENCODING_ULAW;
}
}
- if (strncmp(buf, "sample_rate", 11) == 0 &&
+ if (strncmp(buf, "sample_rate ", 12) == 0 &&
ft->info.rate == 0)
{
#ifdef __alpha__
--- a/src/tests.sh
+++ b/src/tests.sh
@@ -15,7 +15,7 @@
./sox $noise -t raw -r 8196 -u -b -c 1 ub.raw -r 8196 -s -b sb.raw
./sox $noise -t raw -r 8196 -s -b -c 1 sb.raw -r 8196 -u -b ub2.raw
./sox $noise -r 8196 -u -b -c 1 ub2.raw -r 8196 ub2.voc
-echo Comparing ub.raw o ub2.raw
+echo Comparing ub.raw to ub2.raw
cmp -l ub.raw ub2.raw
# skip checksum and rate byte
echo Comparing $file.voc to ub2.voc, ignoring Comment field
--- a/src/trim.c
+++ b/src/trim.c
@@ -13,7 +13,11 @@
#include "st.h"
+/* Time resolutin one millisecond */
+#define TIMERES 1000
+#define TRIM_USAGE "Trim usage: trim start [length]"
+
typedef struct
{
@@ -37,18 +41,35 @@
char **argv;
{
trim_t trim = (trim_t) effp->priv;
+ double time;
trim->start = 0;
trim->length = 0;
switch (n) {
- case 2:
- trim->length = atol(argv[1]);
+ case 2:
+ if (sscanf(argv[1], "%lf", &time) == 1)
+ {
+ trim->length = time * TIMERES;
+ }
+ else
+ {
+ st_fail(TRIM_USAGE);
+ return(ST_EOF);
+ }
case 1:
- trim->start = atol(argv[0]);
+ if (sscanf(argv[0], "%lf", &time) == 1)
+ {
+ trim->start = time * TIMERES;
+ }
+ else
+ {
+ st_fail(TRIM_USAGE);
+ return(ST_EOF);
+ }
break;
default:
- st_fail("Trim usage: trim start [length]");
+ st_fail(TRIM_USAGE);
return ST_EOF;
break;
@@ -65,13 +86,13 @@
trim_t trim = (trim_t) effp->priv;
- trim->start = (LONG)(effp->ininfo.channels * effp->ininfo.rate * (0.001e0) * trim->start);
+ trim->start = effp->ininfo.channels * effp->ininfo.rate * trim->start / TIMERES;
if (trim->start < 0)
{
st_fail("trim: start must be positive");
}
- trim->length = (LONG)(effp->ininfo.channels * effp->ininfo.rate * (0.001e0) * trim->length);
+ trim->length = effp->ininfo.channels * effp->ininfo.rate * trim->length / TIMERES;
if (trim->length < 0)
{
st_fail("trim: start must be positive");
@@ -126,7 +147,6 @@
if (trim->trimmed || start_trim ) {
if (trim->length && ( (trim->trimmed+done) > trim->length)) {
- fprintf(stderr, "passed done\n");
done = trim->length - trim->trimmed ;
*osamp = done;
trim->done = 1;