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
1937.SP1937.SP
1938See also the \fBbass\fR and \fBtreble\fR shelving equalisation effects.1938See also the \fBbass\fR and \fBtreble\fR shelving equalisation effects.
1939.TP1939.TP
1940\fBdelay\fR {\fItime\fR}1940\fBdelay\fR {\fIposition(=)\fR}
1941Delay one or more audio channels by the given \fItime\fR (a time1941Delay one or more audio channels such that they start at the given
1942specification).1942\fIposition\fR.
1943For example,1943For example,
1944.B delay 1\*d5 0 3000s1944.B delay 1\*d5 +1 3000s
1945delays the first channel by 1\*d5 seconds, the third channel by 30001945delays the first channel by 1\*d5 seconds, the second channel by 2\*d5
1946samples, and leaves the second channel (and any other channels that may be1946seconds (one second more than the previous channel), the third channel
1947present) un-delayed.1947by 3000 samples, and leaves any other channels that may be
1948present un-delayed.
1948The following (one long) command plays a chime sound:1949The following (one long) command plays a chime sound:
1949.EX1950.EX
1950.ne 31951.ne 3
src/delay.c+10−6
@@ -43,7 +43,6 @@ static int lsx_kill(sox_effect_t * effp) · 42 unmodified lines
43static int create(sox_effect_t * effp, int argc, char * * argv)43static int create(sox_effect_t * effp, int argc, char * * argv)
44{44{
45 priv_t * p = (priv_t *)effp->priv;45 priv_t * p = (priv_t *)effp->priv;
46 uint64_t dummy;
47 unsigned i;46 unsigned i;
48 47
49 --argc, ++argv;48 --argc, ++argv;
@@ -51,7 +50,7 @@ static int create(sox_effect_t * effp, int argc, char * * argv) · 1 unmodified line
51 p->args = lsx_calloc(p->argc, sizeof(*p->args));50 p->args = lsx_calloc(p->argc, sizeof(*p->args));
52 p->max_delay = lsx_malloc(sizeof(*p->max_delay));51 p->max_delay = lsx_malloc(sizeof(*p->max_delay));
53 for (i = 0; i < p->argc; ++i) {52 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, '=');
55 if (!next || *next) {54 if (!next || *next) {
56 lsx_kill(effp);55 lsx_kill(effp);
57 return lsx_usage(effp);56 return lsx_usage(effp);
@@ -70,7 +69,9 @@ static int stop(sox_effect_t * effp) · 12 unmodified lines
70static int start(sox_effect_t * effp)69static int start(sox_effect_t * effp)
71{70{
72 priv_t * p = (priv_t *)effp->priv;71 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;
74 75
75 if (effp->flow == 0) {76 if (effp->flow == 0) {
76 unsigned i;77 unsigned i;
@@ -79,8 +80,11 @@ static int start(sox_effect_t * effp) · 2 unmodified lines
79 return SOX_EOF;80 return SOX_EOF;
80 }81 }
81 for (i = 0; i < p->argc; ++i) {82 for (i = 0; i < p->argc; ++i) {
82 lsx_parsesamples(effp->in_signal.rate, p->args[i].str, &delay, 't');83 if (!lsx_parseposition(effp->in_signal.rate, p->args[i].str, &delay, last_seen, in_length, '=') || delay == SOX_UNKNOWN_LEN) {
83 p->args[i].delay = delay;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;
84 if (delay > max_delay) {88 if (delay > max_delay) {
85 max_delay = delay;89 max_delay = delay;
86 }90 }
@@ -152,7 +156,7 @@ static int drain(sox_effect_t * effp, sox_sample_t * obuf, size_t * osamp) · 65 unmodified lines
152sox_effect_handler_t const * lsx_delay_effect_fn(void)156sox_effect_handler_t const * lsx_delay_effect_fn(void)
153{157{
154 static sox_effect_handler_t handler = {158 static sox_effect_handler_t handler = {
155 "delay", "{length}", SOX_EFF_LENGTH | SOX_EFF_MODIFY,159 "delay", "{position}", SOX_EFF_LENGTH | SOX_EFF_MODIFY,
156 create, start, flow, drain, stop, lsx_kill, sizeof(priv_t)160 create, start, flow, drain, stop, lsx_kill, sizeof(priv_t)
157 };161 };
158 return &handler;162 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