aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2015-06-22 15:33:45 +0200
committerHanspeter Portner <dev@open-music-kontrollers.ch>2015-06-22 15:33:45 +0200
commit761a0e999913bebec5e656ed36631c8b8dfb86b1 (patch)
tree5ba4587548cefc5fe8e06e6dd21f268927e58f90
parent0c102b7d3980cb40c1be3ef858ca6b7f847a7718 (diff)
downloadsynthpod-761a0e999913bebec5e656ed36631c8b8dfb86b1.tar.xz
limit port update events to 30Hz.
* limit port update events to 30Hz for: * control ports * audio ports * cv ports
-rw-r--r--lib/synthpod_app.c101
-rw-r--r--lib/synthpod_ui.c9
2 files changed, 63 insertions, 47 deletions
diff --git a/lib/synthpod_app.c b/lib/synthpod_app.c
index c627bbf3..08ba4423 100644
--- a/lib/synthpod_app.c
+++ b/lib/synthpod_app.c
@@ -144,7 +144,6 @@ struct _port_t {
int subscriptions; // subsriptions reference counter
float last;
- uint32_t period_cnt;
float min;
float dflt;
@@ -189,6 +188,12 @@ struct _sp_app_t {
char *bundle_path;
char *bundle_filename;
+
+ struct {
+ uint32_t period_cnt;
+ uint32_t bound;
+ uint32_t counter;
+ } fps;
};
static void
@@ -850,6 +855,9 @@ sp_app_new(const LilvWorld *world, sp_app_driver_t *driver, void *data)
}
else
; //TODO report
+
+ app->fps.bound = driver->sample_rate / 30; //TODO make this configurable
+ app->fps.counter = 0;
return app;
}
@@ -1983,6 +1991,16 @@ sp_app_run_pre(sp_app_t *app, uint32_t nsamples)
void
sp_app_run_post(sp_app_t *app, uint32_t nsamples)
{
+ int send_port_updates = 0;
+
+ app->fps.counter += nsamples; // increase sample counter
+ app->fps.period_cnt += 1; // increase period counter
+ if(app->fps.counter >= app->fps.bound) // check whether we reached boundary
+ {
+ send_port_updates = 1;
+ app->fps.counter -= app->fps.bound; // reet sample counter
+ }
+
// iterate over all modules
for(int m=0; m<app->num_mods; m++)
{
@@ -2176,58 +2194,59 @@ sp_app_run_post(sp_app_t *app, uint32_t nsamples)
if(port->protocol == app->regs.port.float_protocol.urid)
{
- const float val = *(const float *)buf;
- if(val != port->last) // has value changed since last time?
+ if(send_port_updates)
{
- // update last value
- port->last = val;
+ const float val = *(const float *)buf;
- size_t size = sizeof(transfer_float_t);
- transfer_float_t *trans = _sp_app_to_ui_request(app, size);
- if(trans)
+ if(val != port->last)
{
- _sp_transfer_float_fill(&app->regs, &app->forge, trans, port->mod->uid, port->index, &val);
- _sp_app_to_ui_advance(app, size);
+ // update last value
+ port->last = val;
+
+ size_t size = sizeof(transfer_float_t);
+ transfer_float_t *trans = _sp_app_to_ui_request(app, size);
+ if(trans)
+ {
+ _sp_transfer_float_fill(&app->regs, &app->forge, trans, port->mod->uid, port->index, &val);
+ _sp_app_to_ui_advance(app, size);
+ }
}
}
}
else if(port->protocol == app->regs.port.peak_protocol.urid)
{
- const float *vec = (const float *)buf;
-
- // find peak value in current period
- float peak = 0.f;
- for(int j=0; j<nsamples; j++)
+ if(send_port_updates)
{
- float val = fabs(vec[j]);
- if(val > peak)
- peak = val;
- }
-
- port->period_cnt += 1; // increase period counter
- //printf("%u %f\n", port->period_cnt, peak);
-
- if( (peak != port->last) //TODO make below two configurable
- && ((port->period_cnt & 0x3f) == 0x00) ) // only update every 512th period
- {
- //printf("peak different: %i %i\n", port->last == 0.f, peak == 0.f);
-
- // update last value
- port->last = peak;
+ const float *vec = (const float *)buf;
- LV2UI_Peak_Data data = {
- .period_start = port->period_cnt,
- .period_size = nsamples,
- .peak = peak
- };
+ // find peak value in current period
+ float peak = 0.f;
+ for(int j=0; j<nsamples; j++)
+ {
+ float val = fabs(vec[j]);
+ if(val > peak)
+ peak = val;
+ }
- size_t size = sizeof(transfer_peak_t);
- transfer_peak_t *trans = _sp_app_to_ui_request(app, size);
- if(trans)
+ if(fabs(peak - port->last) >= 1e-3) //TODO make this configurable
{
- _sp_transfer_peak_fill(&app->regs, &app->forge, trans,
- port->mod->uid, port->index, &data);
- _sp_app_to_ui_advance(app, size);
+ // update last value
+ port->last = peak;
+
+ LV2UI_Peak_Data data = {
+ .period_start = app->fps.period_cnt,
+ .period_size = nsamples,
+ .peak = peak
+ };
+
+ size_t size = sizeof(transfer_peak_t);
+ transfer_peak_t *trans = _sp_app_to_ui_request(app, size);
+ if(trans)
+ {
+ _sp_transfer_peak_fill(&app->regs, &app->forge, trans,
+ port->mod->uid, port->index, &data);
+ _sp_app_to_ui_advance(app, size);
+ }
}
}
}
diff --git a/lib/synthpod_ui.c b/lib/synthpod_ui.c
index 45744184..45907e58 100644
--- a/lib/synthpod_ui.c
+++ b/lib/synthpod_ui.c
@@ -386,13 +386,10 @@ _std_port_event(LV2UI_Handle handle, uint32_t index, uint32_t size,
else if(protocol == ui->regs.port.peak_protocol.urid)
{
const LV2UI_Peak_Data *peak_data = buf;
- if(peak_data->peak > port->peak)
- port->peak = peak_data->peak;
- else
- port->peak *= 0.8;
+ //TODO smooth/filter signal?
+ port->peak = peak_data->peak;
- if(port->std.widget && (port->peak > 0.f) )
- smart_meter_value_set(port->std.widget, port->peak);
+ smart_meter_value_set(port->std.widget, port->peak);
}
else if(protocol == ui->regs.port.event_transfer.urid)
{