Use the new lsx_parseposition function for the delay effect and update the documentation accordingly.
Unified · Split
| @@ -1937,14 +1937,15 @@ This effect supports the \fB\-\-plot\fR global option. · 1936 unmodified lines | |||
| 1937 | .SP | 1937 | .SP |
| 1938 | See also the \fBbass\fR and \fBtreble\fR shelving equalisation effects. | 1938 | See also the \fBbass\fR and \fBtreble\fR shelving equalisation effects. |
| 1939 | .TP | 1939 | .TP |
| 1940 | \fBdelay\fR {\fItime\fR} | 1940 | \fBdelay\fR {\fIposition(=)\fR} |
| 1941 | Delay one or more audio channels by the given \fItime\fR (a time | 1941 | Delay one or more audio channels such that they start at the given |
| 1942 | specification). | 1942 | \fIposition\fR. |
| 1943 | For example, | 1943 | For example, |
| 1944 | .B delay 1\*d5 0 3000s | 1944 | .B delay 1\*d5 +1 3000s |
| 1945 | delays the first channel by 1\*d5 seconds, the third channel by 3000 | 1945 | delays the first channel by 1\*d5 seconds, the second channel by 2\*d5 |
| 1946 | samples, and leaves the second channel (and any other channels that may be | 1946 | seconds (one second more than the previous channel), the third channel |
| 1947 | present) un-delayed. | 1947 | by 3000 samples, and leaves any other channels that may be |
| 1948 | present un-delayed. | ||
| 1948 | The following (one long) command plays a chime sound: | 1949 | The following (one long) command plays a chime sound: |
| 1949 | .EX | 1950 | .EX |
| 1950 | .ne 3 | 1951 | .ne 3 |
| @@ -43,7 +43,6 @@ static int lsx_kill(sox_effect_t * effp) · 42 unmodified lines | |||
| 43 | static int create(sox_effect_t * effp, int argc, char * * argv) | 43 | static 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 | |||
| 70 | static int start(sox_effect_t * effp) | 69 | static 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 | |||
| 152 | sox_effect_handler_t const * lsx_delay_effect_fn(void) | 156 | sox_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; |