summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wtaymans@redhat.com>2017-06-28 16:33:11 +0200
committerWim Taymans <wtaymans@redhat.com>2017-06-28 16:33:11 +0200
commitd8cac792f4efa78d28cc96eb14689040b0ebde23 (patch)
treef0488a0e0968824a996a726788a609589f8b4ea7
parent387dee32375b65b68d328213b26fe5a979692258 (diff)
spa: small performance fixes
-rw-r--r--spa/plugins/audiomixer/audiomixer.c24
-rw-r--r--spa/plugins/audiotestsrc/render.c4
2 files changed, 22 insertions, 6 deletions
diff --git a/spa/plugins/audiomixer/audiomixer.c b/spa/plugins/audiomixer/audiomixer.c
index 56676e75..738bf9c4 100644
--- a/spa/plugins/audiomixer/audiomixer.c
+++ b/spa/plugins/audiomixer/audiomixer.c
@@ -99,6 +99,7 @@ struct impl {
void *user_data;
int port_count;
+ int last_port;
struct port in_ports[MAX_PORTS];
struct port out_ports[1];
@@ -220,7 +221,7 @@ impl_node_get_port_ids(struct spa_node *node,
this = SPA_CONTAINER_OF(node, struct impl, node);
if (input_ids) {
- for (i = 0, idx = 0; i < MAX_PORTS && idx < n_input_ports; i++) {
+ for (i = 0, idx = 0; i < this->last_port && idx < n_input_ports; i++) {
if (this->in_ports[i].valid)
input_ids[idx++] = i;
}
@@ -252,6 +253,8 @@ static int impl_node_add_port(struct spa_node *node, enum spa_direction directio
SPA_PORT_INFO_FLAG_IN_PLACE;
this->port_count++;
+ if (this->last_port < port_id)
+ this->last_port = port_id;
return SPA_RESULT_OK;
}
@@ -277,6 +280,16 @@ impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint3
}
spa_memzero(port, sizeof(struct port));
+ if (port_id == this->last_port) {
+ int i;
+
+ for (i = this->last_port; i > 0; i--)
+ if (GET_IN_PORT (this, i)->valid)
+ break;
+
+ this->last_port = i;
+ }
+
return SPA_RESULT_OK;
}
@@ -673,7 +686,7 @@ static int mix_output(struct impl *this, size_t n_bytes)
spa_log_trace(this->log, NAME " %p: dequeue output buffer %d %zd",
this, outbuf->outbuf->id, n_bytes);
- for (layer = 0, i = 0; i < MAX_PORTS; i++) {
+ for (layer = 0, i = 0; i < this->last_port; i++) {
struct port *in_port = GET_IN_PORT(this, i);
if (in_port->io == NULL || in_port->n_buffers == 0)
@@ -712,7 +725,7 @@ static int impl_node_process_input(struct spa_node *node)
if (outio->status == SPA_RESULT_HAVE_BUFFER)
return SPA_RESULT_HAVE_BUFFER;
- for (i = 0; i < MAX_PORTS; i++) {
+ for (i = 0; i < this->last_port; i++) {
struct port *inport = GET_IN_PORT(this, i);
struct spa_port_io *inio;
@@ -777,7 +790,7 @@ static int impl_node_process_output(struct spa_node *node)
outio->buffer_id = SPA_ID_INVALID;
}
/* produce more output if possible */
- for (i = 0; i < MAX_PORTS; i++) {
+ for (i = 0; i < this->last_port; i++) {
struct port *inport = GET_IN_PORT(this, i);
if (inport->io == NULL || inport->n_buffers == 0)
@@ -790,7 +803,7 @@ static int impl_node_process_output(struct spa_node *node)
outio->status = mix_output(this, min_queued);
} else {
/* take requested output range and apply to input */
- for (i = 0; i < MAX_PORTS; i++) {
+ for (i = 0; i < this->last_port; i++) {
struct port *inport = GET_IN_PORT(this, i);
struct spa_port_io *inio;
@@ -892,6 +905,7 @@ impl_init(const struct spa_handle_factory *factory,
this->node = impl_node;
port = GET_OUT_PORT(this, 0);
+ port->valid = true;
port->info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS |
SPA_PORT_INFO_FLAG_NO_REF;
spa_list_init(&port->queue);
diff --git a/spa/plugins/audiotestsrc/render.c b/spa/plugins/audiotestsrc/render.c
index fc6bf0df..7fcd1e2d 100644
--- a/spa/plugins/audiotestsrc/render.c
+++ b/spa/plugins/audiotestsrc/render.c
@@ -33,11 +33,13 @@ audio_test_src_create_sine_##type (struct impl *this, type *samples, size_t n_sa
amp = this->props.volume * scale; \
\
for (i = 0; i < n_samples; i++) { \
+ type val; \
this->accumulator += step; \
if (this->accumulator >= M_PI_M2) \
this->accumulator -= M_PI_M2; \
+ val = (type) (sin (this->accumulator) * amp); \
for (c = 0; c < channels; ++c) \
- *samples++ = (type) (sin (this->accumulator) * amp); \
+ *samples++ = val; \
} \
}