Compare commits

...

2 Commits

Author SHA1 Message Date
992eebc8a2 web cpumeter. Not tested 2024-07-04 10:58:35 +02:00
0babfc9b5d indentation/alignment 2024-07-04 10:09:38 +02:00
4 changed files with 44 additions and 31 deletions

View File

@ -18,17 +18,17 @@
* File author: Stefano D'Angelo
*/
#define DATA_PRODUCT_AUDIO_INPUT_CHANNELS_N {{=it.product.buses.filter(x => x.type == "audio" && x.direction == "input").reduce((s, x) => s += x.channels == "mono" ? 1 : 2, 0)}}
#define DATA_PRODUCT_AUDIO_OUTPUT_CHANNELS_N {{=it.product.buses.filter(x => x.type == "audio" && x.direction == "output").reduce((s, x) => s += x.channels == "mono" ? 1 : 2, 0)}}
#define DATA_PRODUCT_MIDI_INPUTS_N {{=it.product.buses.filter(x => x.type == "midi" && x.direction == "input").length}}
#define DATA_PRODUCT_MIDI_OUTPUTS_N {{=it.product.buses.filter(x => x.type == "midi" && x.direction == "output").length}}
#define DATA_PRODUCT_PARAMETERS_N {{=it.product.parameters.length}}
#define DATA_PRODUCT_PARAMETERS_OUTPUT_N {{=it.product.parameters.filter(x => x.direction == "output").length}}
#define DATA_PRODUCT_AUDIO_INPUT_CHANNELS_N {{=it.product.buses.filter(x => x.type == "audio" && x.direction == "input").reduce((s, x) => s += x.channels == "mono" ? 1 : 2, 0)}}
#define DATA_PRODUCT_AUDIO_OUTPUT_CHANNELS_N {{=it.product.buses.filter(x => x.type == "audio" && x.direction == "output").reduce((s, x) => s += x.channels == "mono" ? 1 : 2, 0)}}
#define DATA_PRODUCT_MIDI_INPUTS_N {{=it.product.buses.filter(x => x.type == "midi" && x.direction == "input").length}}
#define DATA_PRODUCT_MIDI_OUTPUTS_N {{=it.product.buses.filter(x => x.type == "midi" && x.direction == "output").length}}
#define DATA_PRODUCT_PARAMETERS_N {{=it.product.parameters.length}}
#define DATA_PRODUCT_PARAMETERS_OUTPUT_N {{=it.product.parameters.filter(x => x.direction == "output").length}}
#if DATA_PRODUCT_PARAMETERS_N > 0
static struct {
char out;
float def;
char out;
float def;
} param_data[DATA_PRODUCT_PARAMETERS_N] = {
{{~it.product.parameters :p}}
{

View File

@ -22,10 +22,10 @@
#include <stdint.h>
typedef struct {
void * handle;
const char * format;
const char * (*get_bindir)(void *handle);
const char * (*get_datadir)(void *handle);
void *handle;
const char *format;
const char *(*get_bindir)(void *handle);
const char *(*get_datadir)(void *handle);
} plugin_callbacks;
#include "data.h"
@ -35,19 +35,19 @@ typedef struct {
#include "walloc.h"
typedef struct {
plugin p;
void * mem;
plugin p;
void *mem;
#if DATA_PRODUCT_AUDIO_INPUT_CHANNELS_N > 0
float x_buf[DATA_PRODUCT_AUDIO_INPUT_CHANNELS_N * 128];
const float * x[DATA_PRODUCT_AUDIO_INPUT_CHANNELS_N];
float zero_buf[128];
float x_buf[DATA_PRODUCT_AUDIO_INPUT_CHANNELS_N * 128];
const float *x[DATA_PRODUCT_AUDIO_INPUT_CHANNELS_N];
float zero_buf[128];
#endif
#if DATA_PRODUCT_AUDIO_OUTPUT_CHANNELS_N > 0
float y_buf[DATA_PRODUCT_AUDIO_OUTPUT_CHANNELS_N * 128];
float * y[DATA_PRODUCT_AUDIO_OUTPUT_CHANNELS_N];
float y_buf[DATA_PRODUCT_AUDIO_OUTPUT_CHANNELS_N * 128];
float *y[DATA_PRODUCT_AUDIO_OUTPUT_CHANNELS_N];
#endif
#if DATA_PRODUCT_PARAMETERS_OUTPUT_N > 0
float out_params[DATA_PRODUCT_PARAMETERS_OUTPUT_N];
float out_params[DATA_PRODUCT_PARAMETERS_OUTPUT_N];
#endif
} instance;
@ -57,10 +57,10 @@ instance * processor_new(float sample_rate) {
return NULL;
plugin_callbacks cbs = {
/* .handle = */ NULL,
/* .format = */ "web",
/* .get_bindir = */ NULL,
/* .get_datadir = */ NULL
/* .handle = */ NULL,
/* .format = */ "web",
/* .get_bindir = */ NULL,
/* .get_datadir = */ NULL
};
plugin_init(&i->p, &cbs);

View File

@ -18,14 +18,17 @@
* File author: Stefano D'Angelo
*/
var buses = {{=JSON.stringify(it.product.buses, null, 2)}};
var buses = {{=JSON.stringify(it.product.buses, null, 2)}};
var parameters = {{=JSON.stringify(it.product.parameters, null, 2)}};
var busesIn = buses.filter(x => x.type == "audio" && x.direction == "input");
var busesOut = buses.filter(x => x.type == "audio" && x.direction == "output");
var busesIn = buses.filter(x => x.type == "audio" && x.direction == "input");
var busesOut = buses.filter(x => x.type == "audio" && x.direction == "output");
var nChansIn = busesIn.reduce((a, x) => a + (x.channels == "mono" ? 1 : 2), 0);
var nChansOut = busesOut.reduce((a, x) => a + (x.channels == "mono" ? 1 : 2), 0);
var nChansIn = busesIn.reduce((a, x) => a + (x.channels == "mono" ? 1 : 2), 0);
var nChansOut = busesOut.reduce((a, x) => a + (x.channels == "mono" ? 1 : 2), 0);
var cpu_meter = 0.0;
var sampleRate = 1.0;
class Processor extends AudioWorkletProcessor {
constructor(options) {
@ -71,6 +74,8 @@ class Processor extends AudioWorkletProcessor {
}
process(inputs, outputs, params) {
const processTimeStart = performance.now();
for (var i = 0; i < this.parametersIn.length; i++) {
var index = this.parametersIn[i].index;
var parameter = parameters[index];
@ -141,7 +146,11 @@ class Processor extends AudioWorkletProcessor {
for (var i = 0; i < this.parametersOut.length; i++) {
var index = this.parametersOut[i].index;
var value = this.parametersOutValues[i];
var value;
if (parameters[index].isCpumeter)
value = cpu_meter;
else
value = this.parametersOutValues[i];
if (value != this.parametersOut[i].value) {
this.paramOutChangeMsg.index = index;
this.paramOutChangeMsg.value = value;
@ -149,6 +158,10 @@ class Processor extends AudioWorkletProcessor {
this.parametersOut[i].value = value;
}
}
const processTimeEnd = performance.now();
const processTimeMs = processTimeEnd - processTimeStart;
const processTimeS = processTimeMs * 0.001;
cpu_meter = cpu_meter * 0.9 + (processTimeS * sampleRate) * 0.1;
return true; // because Chrome sucks: https://bugs.chromium.org/p/chromium/issues/detail?id=921354
}

View File

@ -28,7 +28,7 @@ extern unsigned char __heap_base;
typedef struct _header {
struct _header *next;
struct _header *prev;
char free;
char free;
} header;
static char inited = 0;