From c160cd01765ef7aa8f4ce82bbd143c0490d3c596 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 15 Jun 2022 17:54:32 +0200 Subject: [PATCH] audioconvert2: implement control port Add a control port when requested in the PortConfig. Fix the sequence loop. Make a copy of the sample pointers before changing them. --- spa/plugins/audioconvert/audioconvert2.c | 43 ++++++++++++++++++------ 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/spa/plugins/audioconvert/audioconvert2.c b/spa/plugins/audioconvert/audioconvert2.c index db4faca52..dcbab6486 100644 --- a/spa/plugins/audioconvert/audioconvert2.c +++ b/spa/plugins/audioconvert/audioconvert2.c @@ -885,7 +885,7 @@ static int apply_midi(struct impl *this, const struct spa_pod *value) if ((val[0] & 0xf0) != 0xb0 || val[1] != 7) return 0; - p->volume = val[2] / 127.0; + p->volume = val[2] / 127.0f; set_volume(this); return 1; } @@ -951,6 +951,10 @@ static int reconfigure_mode(struct impl *this, enum spa_param_port_config_mode m default: return -ENOTSUP; } + if (direction == SPA_DIRECTION_INPUT && dir->control) { + i = dir->n_ports++; + init_port(this, direction, i, 0, false, false, true); + } this->info.change_mask |= SPA_NODE_CHANGE_MASK_FLAGS | SPA_NODE_CHANGE_MASK_PARAMS; this->info.flags &= ~SPA_NODE_FLAG_NEED_CONFIGURE; @@ -2030,8 +2034,8 @@ static int channelmix_process_control(struct impl *this, struct port *ctrlport, struct spa_pod_control *c, *prev = NULL; uint32_t avail_samples = n_samples; uint32_t i; - const float **s = (const float **)src; - float **d = (float **)dst; + const float *s[MAX_PORTS], **ss = (const float**) src; + float *d[MAX_PORTS], **sd = (float **) dst; SPA_POD_SEQUENCE_FOREACH(ctrlport->ctrl, c) { uint32_t chunk; @@ -2060,26 +2064,45 @@ static int channelmix_process_control(struct impl *this, struct port *ctrlport, chunk = SPA_MIN(avail_samples, c->offset - ctrlport->ctrl_offset); - spa_log_trace_fp(this->log, "%p: process %d %d", this, - c->offset, chunk); + spa_log_trace_fp(this->log, "%p: process %d-%d %d", this, + c->offset, ctrlport->ctrl_offset, chunk); + + if (ss == (const float**)src) { + for (i = 0; i < this->mix.src_chan; i++) + s[i] = ss[i]; + for (i = 0; i < this->mix.dst_chan; i++) + d[i] = sd[i]; + ss = s; + sd = d; + } + + channelmix_process(&this->mix, (void**)sd, (const void**)ss, chunk); - channelmix_process(&this->mix, dst, src, chunk); for (i = 0; i < this->mix.src_chan; i++) - s[i] += chunk; + ss[i] += chunk; for (i = 0; i < this->mix.dst_chan; i++) - d[i] += chunk; + sd[i] += chunk; avail_samples -= chunk; ctrlport->ctrl_offset += chunk; prev = c; } - + if (prev) { + switch (prev->type) { + case SPA_CONTROL_Midi: + apply_midi(this, &prev->value); + break; + case SPA_CONTROL_Properties: + apply_props(this, &prev->value); + break; + } + } /* when we get here we run out of control points but still have some * remaining samples */ spa_log_trace_fp(this->log, "%p: remain %d", this, avail_samples); if (avail_samples > 0) - channelmix_process(&this->mix, dst, src, avail_samples); + channelmix_process(&this->mix, (void**)sd, (const void**)ss, avail_samples); return 1; }