Skip to content

Commit

Permalink
effect.c: Remove duplicate code in drain_effects_chain().
Browse files Browse the repository at this point in the history
  • Loading branch information
bmc0 committed Nov 15, 2018
1 parent f299454 commit 7eba29c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 16 deletions.
2 changes: 1 addition & 1 deletion dsp.c
Expand Up @@ -625,7 +625,7 @@ int main(int argc, char *argv[])
}
w = r = in_codecs.head->read(in_codecs.head, buf1, dsp_globals.buf_frames);
pos += r;
obuf = run_effects_chain(&chain, &w, buf1, buf2);
obuf = run_effects_chain(chain.head, &w, buf1, buf2);
write_out(w, obuf, do_dither);
k += w;
if (show_progress && k >= out_codec->fs) {
Expand Down
16 changes: 3 additions & 13 deletions effect.c
Expand Up @@ -241,10 +241,9 @@ ssize_t get_effects_chain_buffer_len(struct effects_chain *chain, ssize_t in_fra
return max_len;
}

sample_t * run_effects_chain(struct effects_chain *chain, ssize_t *frames, sample_t *buf1, sample_t *buf2)
sample_t * run_effects_chain(struct effect *e, ssize_t *frames, sample_t *buf1, sample_t *buf2)
{
sample_t *ibuf = buf1, *obuf = buf2, *tmp;
struct effect *e = chain->head;
while (e != NULL && *frames > 0) {
tmp = e->run(e, frames, ibuf, obuf);
if (tmp == obuf) {
Expand Down Expand Up @@ -325,11 +324,10 @@ sample_t * drain_effects_chain(struct effects_chain *chain, ssize_t *frames, sam
{
int gcd;
ssize_t ftmp = *frames, dframes = -1;
sample_t *ibuf = buf1, *obuf = buf2, *tmp;
struct effect *e = chain->head;
while (e != NULL && dframes == -1) {
dframes = ftmp;
if (e->drain != NULL) e->drain(e, &dframes, ibuf);
if (e->drain != NULL) e->drain(e, &dframes, buf1);
else dframes = -1;
if (e->ostream.fs != e->istream.fs) {
gcd = find_gcd(e->ostream.fs, e->istream.fs);
Expand All @@ -338,15 +336,7 @@ sample_t * drain_effects_chain(struct effects_chain *chain, ssize_t *frames, sam
e = e->next;
}
*frames = dframes;
while (e != NULL && *frames > 0) {
tmp = e->run(e, frames, ibuf, obuf);
if (tmp == obuf) {
obuf = ibuf;
ibuf = tmp;
}
e = e->next;
}
return ibuf;
return run_effects_chain(e, frames, buf1, buf2);
}

void destroy_effects_chain(struct effects_chain *chain)
Expand Down
2 changes: 1 addition & 1 deletion effect.h
Expand Up @@ -36,7 +36,7 @@ void append_effect(struct effects_chain *, struct effect *);
int build_effects_chain(int, char **, struct effects_chain *, struct stream_info *, char *, const char *);
int build_effects_chain_from_file(struct effects_chain *, struct stream_info *, char *, const char *, const char *);
ssize_t get_effects_chain_buffer_len(struct effects_chain *, ssize_t, int);
sample_t * run_effects_chain(struct effects_chain *, ssize_t *, sample_t *, sample_t *);
sample_t * run_effects_chain(struct effect *, ssize_t *, sample_t *, sample_t *);
double get_effects_chain_delay(struct effects_chain *);
void reset_effects_chain(struct effects_chain *);
void plot_effects_chain(struct effects_chain *, int);
Expand Down
2 changes: 1 addition & 1 deletion ladspa_dsp.c
Expand Up @@ -252,7 +252,7 @@ static void run_dsp(LADSPA_Handle inst, unsigned long s)
for (k = 0; k < d->input_channels; ++k)
d->buf1[j++] = (sample_t) d->ports[k][i];

obuf = run_effects_chain(&d->chain, &w, d->buf1, d->buf2);
obuf = run_effects_chain(d->chain.head, &w, d->buf1, d->buf2);

for (i = j = 0; i < s; i++)
for (k = d->input_channels; k < d->input_channels + d->output_channels; ++k)
Expand Down

0 comments on commit 7eba29c

Please sign in to comment.