History

delay: use lsx_parseposition

Use the new lsx_parseposition function for the delay effect and update the documentation accordingly.

Ulrich Klauer committed 14 years ago

Commit a447efe1 parent b547a292 files · +18 −13Browse files

Unified · Split

2 files
  1. sox.1 +8 −7
  2. src/delay.c +10 −6
sox.1+8−7
@@ -1937,14 +1937,15 @@ This effect supports the \fB\-\-plot\fR global option. · 1936 unmodified lines
19371937 .SP
19381938 See also the \fBbass\fR and \fBtreble\fR shelving equalisation effects.
19391939 .TP
1940−\fBdelay\fR {\fItime\fR}
1941−Delay one or more audio channels by the given \fItime\fR (a time
1942−specification).
1940+\fBdelay\fR {\fIposition(=)\fR}
1941+Delay one or more audio channels such that they start at the given
1942+\fIposition\fR.
19431943 For example,
1944−.B delay 1\*d5 0 3000s
1945−delays the first channel by 1\*d5 seconds, the third channel by 3000
1946−samples, and leaves the second channel (and any other channels that may be
1947−present) un-delayed.
1944+.B delay 1\*d5 +1 3000s
1945+delays the first channel by 1\*d5 seconds, the second channel by 2\*d5
1946+seconds (one second more than the previous channel), the third channel
1947+by 3000 samples, and leaves any other channels that may be
1948+present un-delayed.
19481949 The following (one long) command plays a chime sound:
19491950 .EX
19501951 .ne 3
src/delay.c+10−6
@@ -43,7 +43,6 @@ static int lsx_kill(sox_effect_t * effp) · 42 unmodified lines
4343 static int create(sox_effect_t * effp, int argc, char * * argv)
4444 {
4545 priv_t * p = (priv_t *)effp->priv;
46− uint64_t dummy;
4746 unsigned i;
4847
4948 --argc, ++argv;
@@ -51,7 +50,7 @@ static int create(sox_effect_t * effp, int argc, char * * argv) · 1 unmodified line
5150 p->args = lsx_calloc(p->argc, sizeof(*p->args));
5251 p->max_delay = lsx_malloc(sizeof(*p->max_delay));
5352 for (i = 0; i < p->argc; ++i) {
54− char const * next = lsx_parsesamples(1e5, p->args[i].str = lsx_strdup(argv[i]), &dummy, 't');
53+ char const * next = lsx_parseposition(0., p->args[i].str = lsx_strdup(argv[i]), NULL, (uint64_t)0, (uint64_t)0, '=');
5554 if (!next || *next) {
5655 lsx_kill(effp);
5756 return lsx_usage(effp);
@@ -70,7 +69,9 @@ static int stop(sox_effect_t * effp) · 12 unmodified lines
7069 static int start(sox_effect_t * effp)
7170 {
7271 priv_t * p = (priv_t *)effp->priv;
73− uint64_t max_delay = 0, delay;
72+ uint64_t max_delay = 0, last_seen = 0, delay;
73+ uint64_t in_length = effp->in_signal.length != SOX_UNKNOWN_LEN ?
74+ effp->in_signal.length / effp->in_signal.channels : SOX_UNKNOWN_LEN;
7475
7576 if (effp->flow == 0) {
7677 unsigned i;
@@ -79,8 +80,11 @@ static int start(sox_effect_t * effp) · 2 unmodified lines
7980 return SOX_EOF;
8081 }
8182 for (i = 0; i < p->argc; ++i) {
82− lsx_parsesamples(effp->in_signal.rate, p->args[i].str, &delay, 't');
83− p->args[i].delay = delay;
83+ if (!lsx_parseposition(effp->in_signal.rate, p->args[i].str, &delay, last_seen, in_length, '=') || delay == SOX_UNKNOWN_LEN) {
84+ lsx_fail("Position relative to end of audio specified, but audio length is unknown");
85+ return SOX_EOF;
86+ }
87+ p->args[i].delay = last_seen = delay;
8488 if (delay > max_delay) {
8589 max_delay = delay;
8690 }
@@ -152,7 +156,7 @@ static int drain(sox_effect_t * effp, sox_sample_t * obuf, size_t * osamp) · 65 unmodified lines
152156 sox_effect_handler_t const * lsx_delay_effect_fn(void)
153157 {
154158 static sox_effect_handler_t handler = {
155− "delay", "{length}", SOX_EFF_LENGTH | SOX_EFF_MODIFY,
159+ "delay", "{position}", SOX_EFF_LENGTH | SOX_EFF_MODIFY,
156160 create, start, flow, drain, stop, lsx_kill, sizeof(priv_t)
157161 };
158162 return &handler;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t