cpumeter android

This commit is contained in:
Paolo Marrone 2024-07-09 12:21:11 +02:00 committed by Paolo Marrone
parent af99a702c3
commit 1587e1ec9f
3 changed files with 106 additions and 71 deletions

View File

@ -28,7 +28,7 @@
#define NUM_CHANNELS_OUT {{=it.product.buses.filter(x => x.type == "audio" && x.direction == "output" && !x.cv && !x.sidechain && !x.optional).length > 0 ? (it.product.buses.filter(x => x.type == "audio" && x.direction == "output" && !x.cv && !x.sidechain && !x.optional)[0].channels == "mono" ? 1 : 2) : 0}} #define NUM_CHANNELS_OUT {{=it.product.buses.filter(x => x.type == "audio" && x.direction == "output" && !x.cv && !x.sidechain && !x.optional).length > 0 ? (it.product.buses.filter(x => x.type == "audio" && x.direction == "output" && !x.cv && !x.sidechain && !x.optional)[0].channels == "mono" ? 1 : 2) : 0}}
#define NUM_NON_OPT_CHANNELS_IN {{=it.product.buses.filter(x => x.type == "audio" && x.direction == "input" && !x.optional).reduce((a, x) => a + (x.channels == "mono" ? 1 : 2), 0)}} #define NUM_NON_OPT_CHANNELS_IN {{=it.product.buses.filter(x => x.type == "audio" && x.direction == "input" && !x.optional).reduce((a, x) => a + (x.channels == "mono" ? 1 : 2), 0)}}
#define NUM_NON_OPT_CHANNELS_OUT {{=it.product.buses.filter(x => x.type == "audio" && x.direction == "output" && !x.optional).reduce((a, x) => a + (x.channels == "mono" ? 1 : 2), 0)}} #define NUM_NON_OPT_CHANNELS_OUT {{=it.product.buses.filter(x => x.type == "audio" && x.direction == "output" && !x.optional).reduce((a, x) => a + (x.channels == "mono" ? 1 : 2), 0)}}
#define NUM_ALL_CHANNELS_IN {{=it.product.buses.filter(x => x.type == "audio" && x.direction == "input").reduce((a, x) => a + (x.channels == "mono" ? 1 : 2), 0)}} #define NUM_ALL_CHANNELS_IN {{=it.product.buses.filter(x => x.type == "audio" && x.direction == "input") .reduce((a, x) => a + (x.channels == "mono" ? 1 : 2), 0)}}
#define NUM_ALL_CHANNELS_OUT {{=it.product.buses.filter(x => x.type == "audio" && x.direction == "output").reduce((a, x) => a + (x.channels == "mono" ? 1 : 2), 0)}} #define NUM_ALL_CHANNELS_OUT {{=it.product.buses.filter(x => x.type == "audio" && x.direction == "output").reduce((a, x) => a + (x.channels == "mono" ? 1 : 2), 0)}}
#define NUM_MIDI_INPUTS {{=it.product.buses.filter(x => x.type == "midi" && x.direction == "input").length}} #define NUM_MIDI_INPUTS {{=it.product.buses.filter(x => x.type == "midi" && x.direction == "input").length}}
@ -80,6 +80,11 @@ static struct {
}, },
{{~}} {{~}}
}; };
{{?it.product.parameters.find(x => x.direction == "output" && x.isCpumeter)}}
# define PARAM_OUT_CPU_INDEX {{=it.product.parameters.indexOf(it.product.parameters.find(x => x.direction == "output" && x.isCpumeter))}}
{{?}}
#endif #endif
#define JNI_FUNC(x) Java_{{=it.android.javaPackageName.replaceAll("_", "_1").replaceAll(".", "_")}}_MainActivity_##x #define JNI_FUNC(x) Java_{{=it.android.javaPackageName.replaceAll("_", "_1").replaceAll(".", "_")}}_MainActivity_##x

View File

@ -22,10 +22,10 @@
#include <stdint.h> #include <stdint.h>
typedef struct { typedef struct {
void * handle; void *handle;
const char * format; const char *format;
const char * (*get_bindir)(void *handle); const char *(*get_bindir)(void *handle);
const char * (*get_datadir)(void *handle); const char *(*get_datadir)(void *handle);
} plugin_callbacks; } plugin_callbacks;
#include "data.h" #include "data.h"
@ -52,10 +52,13 @@ typedef struct {
#if NUM_MIDI_INPUTS > 0 #if NUM_MIDI_INPUTS > 0
# include <vector> # include <vector>
# include <amidi/AMidi.h> # include <amidi/AMidi.h>
#endif #endif
#ifdef PARAM_OUT_CPU_INDEX
# include "fatica.h"
#endif
#if defined(__i386__) || defined(__x86_64__) #if defined(__i386__) || defined(__x86_64__)
#include <xmmintrin.h> #include <xmmintrin.h>
#include <pmmintrin.h> #include <pmmintrin.h>
@ -63,29 +66,29 @@ typedef struct {
static ma_device device; static ma_device device;
static plugin instance; static plugin instance;
static void * mem; static void *mem;
#if NUM_NON_OPT_CHANNELS_IN > NUM_CHANNELS_IN #if NUM_NON_OPT_CHANNELS_IN > NUM_CHANNELS_IN
float zero[BLOCK_SIZE]; float zero[BLOCK_SIZE];
#endif #endif
#if NUM_CHANNELS_IN > 0 #if NUM_CHANNELS_IN > 0
float x_buf[NUM_CHANNELS_IN * BLOCK_SIZE]; float x_buf[NUM_CHANNELS_IN * BLOCK_SIZE];
float * x_in[NUM_CHANNELS_IN]; float *x_in[NUM_CHANNELS_IN];
#endif #endif
#if NUM_ALL_CHANNELS_IN > 0 #if NUM_ALL_CHANNELS_IN > 0
const float * x[NUM_ALL_CHANNELS_IN]; const float *x[NUM_ALL_CHANNELS_IN];
#else #else
const float ** x; const float **x;
#endif #endif
#if NUM_NON_OPT_CHANNELS_OUT > 0 #if NUM_NON_OPT_CHANNELS_OUT > 0
float y_buf[NUM_NON_OPT_CHANNELS_OUT * BLOCK_SIZE]; float y_buf[NUM_NON_OPT_CHANNELS_OUT * BLOCK_SIZE];
#endif #endif
#if NUM_CHANNELS_OUT > 0 #if NUM_CHANNELS_OUT > 0
float * y_out[NUM_CHANNELS_OUT]; float *y_out[NUM_CHANNELS_OUT];
#endif #endif
#if NUM_ALL_CHANNELS_OUT > 0 #if NUM_ALL_CHANNELS_OUT > 0
float * y[NUM_ALL_CHANNELS_OUT]; float *y[NUM_ALL_CHANNELS_OUT];
#else #else
float ** y; float **y;
#endif #endif
#if PARAMETERS_N > 0 #if PARAMETERS_N > 0
std::mutex mutex; std::mutex mutex;
@ -102,10 +105,18 @@ std::vector<PortData> midiPorts;
# define MIDI_BUFFER_SIZE 1024 # define MIDI_BUFFER_SIZE 1024
uint8_t midiBuffer[MIDI_BUFFER_SIZE]; uint8_t midiBuffer[MIDI_BUFFER_SIZE];
#endif #endif
#ifdef PARAM_OUT_CPU_INDEX
float cpu_meter = 0.f;
float sample_rate = 1.f;
#endif
static void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) { static void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) {
(void)pDevice; (void)pDevice;
#ifdef PARAM_OUT_CPU_INDEX
const unsigned long long processTimeStart = fatica_time_process();
#endif
#if defined(__aarch64__) #if defined(__aarch64__)
uint64_t fpcr; uint64_t fpcr;
__asm__ __volatile__ ("mrs %0, fpcr" : "=r"(fpcr)); __asm__ __volatile__ ("mrs %0, fpcr" : "=r"(fpcr));
@ -122,8 +133,15 @@ static void data_callback(ma_device* pDevice, void* pOutput, const void* pInput,
if (mutex.try_lock()) { if (mutex.try_lock()) {
# if PARAMETERS_N > 0 # if PARAMETERS_N > 0
for (size_t i = 0; i < PARAMETERS_N; i++) { for (size_t i = 0; i < PARAMETERS_N; i++) {
if (param_data[i].out) if (param_data[i].out) {
# ifdef PARAM_OUT_CPU_INDEX
if (i == PARAM_OUT_CPU_INDEX) {
param_values_prev[i] = param_values[i] = cpu_meter;
continue;
}
# endif
param_values_prev[i] = param_values[i] = plugin_get_parameter(&instance, i); param_values_prev[i] = param_values[i] = plugin_get_parameter(&instance, i);
}
else if (param_values_prev[i] != param_values[i]) { else if (param_values_prev[i] != param_values[i]) {
plugin_set_parameter(&instance, i, param_values[i]); plugin_set_parameter(&instance, i, param_values[i]);
param_values_prev[i] = param_values[i]; param_values_prev[i] = param_values[i];
@ -188,6 +206,13 @@ static void data_callback(ma_device* pDevice, void* pOutput, const void* pInput,
_MM_SET_FLUSH_ZERO_MODE(flush_zero_mode); _MM_SET_FLUSH_ZERO_MODE(flush_zero_mode);
_MM_SET_DENORMALS_ZERO_MODE(denormals_zero_mode); _MM_SET_DENORMALS_ZERO_MODE(denormals_zero_mode);
#endif #endif
#ifdef PARAM_OUT_CPU_INDEX
const unsigned long long processTimeEnd = fatica_time_process();
const unsigned long long processTime100n = processTimeEnd - processTimeStart;
const double processTimeS = ((double) processTime100n) * 1.0e-7;
cpu_meter = cpu_meter * 0.9f + ((float) (processTimeS * sample_rate)) * 0.1f;
#endif
} }
extern "C" extern "C"
@ -249,6 +274,10 @@ JNI_FUNC(nativeAudioStart)(JNIEnv* env, jobject thiz) {
#endif #endif
plugin_set_sample_rate(&instance, (float)device.sampleRate); plugin_set_sample_rate(&instance, (float)device.sampleRate);
#ifdef PARAM_OUT_CPU_INDEX
sample_rate = (float)device.sampleRate;
#endif
size_t req = plugin_mem_req(&instance); size_t req = plugin_mem_req(&instance);
if (req != 0) { if (req != 0) {
mem = malloc(req); mem = malloc(req);

View File

@ -18,6 +18,7 @@ cp $dir/plugin.h $dir/../out/web/src
$dir/../tibia $dir/product.json,$dir/company.json,$dir/android.json $dir/../templates/android $dir/../out/android $dir/../tibia $dir/product.json,$dir/company.json,$dir/android.json $dir/../templates/android $dir/../out/android
$dir/../tibia $dir/product.json,$dir/company.json,$dir/android.json,$dir/android-make.json $dir/../templates/android-make $dir/../out/android $dir/../tibia $dir/product.json,$dir/company.json,$dir/android.json,$dir/android-make.json $dir/../templates/android-make $dir/../out/android
cp $dir/../templates/common/* $dir/../out/android/src/
cp $dir/keystore.jks $dir/../out/android cp $dir/keystore.jks $dir/../out/android
cp $dir/plugin.h $dir/../out/android/src cp $dir/plugin.h $dir/../out/android/src