From a811f2e39064a77ab1874c091dbf1a378dedab4e Mon Sep 17 00:00:00 2001 From: Stefano D'Angelo Date: Fri, 9 Feb 2024 11:34:06 +0100 Subject: [PATCH] fixes --- TODO | 1 + templates/android/src/data.h | 2 ++ templates/android/src/jni.cpp | 4 ++-- templates/cmd/src/data.h | 2 ++ templates/cmd/src/main.c | 10 +++++----- templates/daisy-seed/src/data.h | 2 ++ templates/daisy-seed/src/main.cpp | 18 +++++++++++------- templates/ios/src/data.h | 2 ++ templates/ios/src/native.mm | 4 ++-- templates/lv2/src/lv2.c | 12 +++++++++++- templates/vst3/src/vst3.c | 6 +++++- test/plugin.h | 2 +- 12 files changed, 46 insertions(+), 19 deletions(-) diff --git a/TODO b/TODO index 226c9f1..36cd686 100644 --- a/TODO +++ b/TODO @@ -29,3 +29,4 @@ * daisy-seed and android: isolate C part from C++ * cmd help and version * common code... (eg buffer handling android ios cmd daisy-seed)? +* cmd use midi to determine length in synths diff --git a/templates/android/src/data.h b/templates/android/src/data.h index 9a9cde6..df869c6 100644 --- a/templates/android/src/data.h +++ b/templates/android/src/data.h @@ -17,6 +17,7 @@ #if NUM_AUDIO_BUSES_IN + NUM_AUDIO_BUSES_OUT > 0 static struct { + size_t index; char out; char optional; char channels; @@ -24,6 +25,7 @@ static struct { {{~it.product.buses :b:i}} {{?b.type == "audio"}} { + /* .index = */ {{=i}}, /* .out = */ {{=b.direction == "output" ? 1 : 0}}, /* .optional = */ {{=b.optional ? 1 : 0}}, /* .channels = */ {{=b.channels == "mono" ? 1 : 2}} diff --git a/templates/android/src/jni.cpp b/templates/android/src/jni.cpp index d1c53e2..ebabd45 100644 --- a/templates/android/src/jni.cpp +++ b/templates/android/src/jni.cpp @@ -239,7 +239,7 @@ JNI_FUNC(nativeAudioStart)(JNIEnv* env, jobject thiz) { if (audio_bus_data[i].out) continue; for (int l = 0; l < audio_bus_data[i].channels; l++, j++) { - if (AUDIO_BUS_IN == i) { + if (AUDIO_BUS_IN == audio_bus_data[i].index) { float * b = x_buf + BLOCK_SIZE * k; x[j] = b; x_in[l] = b; @@ -261,7 +261,7 @@ JNI_FUNC(nativeAudioStart)(JNIEnv* env, jobject thiz) { if (!audio_bus_data[i].out) continue; for (int l = 0; l < audio_bus_data[i].channels; l++, j++) { - if (AUDIO_BUS_OUT == i) { + if (AUDIO_BUS_OUT == audio_bus_data[i].index) { y[j] = y_buf + BLOCK_SIZE * k; y_out[l] = y[j]; k++; diff --git a/templates/cmd/src/data.h b/templates/cmd/src/data.h index 129f8c6..d9236ef 100644 --- a/templates/cmd/src/data.h +++ b/templates/cmd/src/data.h @@ -17,6 +17,7 @@ #if NUM_AUDIO_BUSES_IN + NUM_AUDIO_BUSES_OUT > 0 static struct { + size_t index; char out; char optional; char channels; @@ -24,6 +25,7 @@ static struct { {{~it.product.buses :b:i}} {{?b.type == "audio"}} { + /* .index = */ {{=i}}, /* .out = */ {{=b.direction == "output" ? 1 : 0}}, /* .optional = */ {{=b.optional ? 1 : 0}}, /* .channels = */ {{=b.channels == "mono" ? 1 : 2}} diff --git a/templates/cmd/src/main.c b/templates/cmd/src/main.c index 3c36c20..3883be9 100644 --- a/templates/cmd/src/main.c +++ b/templates/cmd/src/main.c @@ -315,7 +315,7 @@ int main(int argc, char * argv[]) { printf(" fs: %g\n", fs); printf(" bufsize: %zu\n", bufsize); #if NUM_CHANNELS_IN > 0 - printf(" length: %g\n", (double)tw_in.numFramesInHeader / (double)tw_in.h.SampleRate); + printf(" length: %g\n", (double)tw_in.numFramesInHeader / (double)fs); printf(" infile: %s\n", infile); #else printf(" length: %g\n", length); @@ -375,7 +375,7 @@ int main(int argc, char * argv[]) { if (audio_bus_data[i].out) continue; for (int l = 0; l < audio_bus_data[i].channels; l++, j++) { - if (AUDIO_BUS_IN == i) { + if (AUDIO_BUS_IN == audio_bus_data[i].index) { float * b = x_buf + bufsize * k; x[j] = b; x_in[l] = b; @@ -404,7 +404,7 @@ int main(int argc, char * argv[]) { if (!audio_bus_data[i].out) continue; for (int l = 0; l < audio_bus_data[i].channels; l++, j++) { - if (AUDIO_BUS_OUT == i) { + if (AUDIO_BUS_OUT == audio_bus_data[i].index) { y[j] = y_buf + bufsize * k; y_out[l] = y[j]; k++; @@ -468,7 +468,7 @@ int main(int argc, char * argv[]) { #if NUM_CHANNELS_IN > 0 size_t len = tw_in.numFramesInHeader; #else - size_t len = (size_t)(tw_in.h.SampleRate * length + 0.5f); + size_t len = (size_t)(fs * length + 0.5f); #endif while (i < len) { size_t left = len - i; @@ -512,7 +512,7 @@ int main(int argc, char * argv[]) { break; } } - midi_next -= 1e6 * ((double)n / (double)tw_in.h.SampleRate); + midi_next -= 1e6 * ((double)n / (double)fs); #endif plugin_process(&instance, x, y, n); diff --git a/templates/daisy-seed/src/data.h b/templates/daisy-seed/src/data.h index 9b21578..5d33dde 100644 --- a/templates/daisy-seed/src/data.h +++ b/templates/daisy-seed/src/data.h @@ -15,6 +15,7 @@ #if NUM_AUDIO_BUSES_IN + NUM_AUDIO_BUSES_OUT > 0 static struct { + size_t index; char out; char optional; char channels; @@ -22,6 +23,7 @@ static struct { {{~it.product.buses :b:i}} {{?b.type == "audio"}} { + /* .index = */ {{=i}}, /* .out = */ {{=b.direction == "output" ? 1 : 0}}, /* .optional = */ {{=b.optional ? 1 : 0}}, /* .channels = */ {{=b.channels == "mono" ? 1 : 2}} diff --git a/templates/daisy-seed/src/main.cpp b/templates/daisy-seed/src/main.cpp index d5c2bf5..a6c363e 100644 --- a/templates/daisy-seed/src/main.cpp +++ b/templates/daisy-seed/src/main.cpp @@ -47,7 +47,7 @@ float * y[NUM_ALL_CHANNELS_OUT]; float ** y; #endif -#if NUM_ADC >= 0 +#if NUM_PARAMETERS > 0 static float clampf(float x, float m, float M) { return x < m ? m : (x > M ? M : x); } @@ -71,7 +71,9 @@ static float parameterAdjust(int i, float v) { static void setParameter(int i, float v) { plugin_set_parameter(&instance, i, parameterAdjust(i, v)); } +#endif +#if NUM_ADC > 0 static void readADCs() { for (int i = 0, j = 0; i < NUM_PARAMETERS; i++) { if (param_data[i].out || param_data[i].pin < 0) @@ -90,7 +92,9 @@ static void AudioCallback( loadMeter.OnBlockStart(); #endif +#if NUM_ADC > 0 readADCs(); +#endif const size_t n = size >> 1; #if NUM_CHANNELS_IN > 0 @@ -128,7 +132,7 @@ int main() { hardware.Configure(); hardware.Init(); -#if NUM_ADC >= 0 +#if NUM_ADC > 0 AdcChannelConfig adcConfig[NUM_ADC]; for (int i = 0, j = 0; i < NUM_PARAMETERS; i++) { if (param_data[i].out || param_data[i].pin < 0) @@ -163,7 +167,7 @@ int main() { loadMeter.Init(sample_rate, BLOCK_SIZE); #endif -#if NUM_ADC >= 0 +#if NUM_ADC > 0 readADCs(); #endif plugin_reset(&instance); @@ -173,7 +177,7 @@ int main() { if (audio_bus_data[i].out) continue; for (int l = 0; l < audio_bus_data[i].channels; l++, j++) { - if (AUDIO_BUS_IN == i) { + if (AUDIO_BUS_IN == audio_bus_data[i].index) { float * b = x_buf + BLOCK_SIZE * k; x[j] = b; x_in[l] = b; @@ -195,7 +199,7 @@ int main() { if (!audio_bus_data[i].out) continue; for (int l = 0; l < audio_bus_data[i].channels; l++, j++) { - if (AUDIO_BUS_OUT == i) { + if (AUDIO_BUS_OUT == audio_bus_data[i].index) { y[j] = y_buf + BLOCK_SIZE * k; y_out[l] = y[j]; k++; @@ -236,8 +240,8 @@ int main() { case ControlChange: # if NUM_PARAMETERS > 0 && HAS_MIDI_CC_MAPS for (int i = 0; i < NUM_PARAMETERS; i++) - if (midi_cc_maps[i] == data[1]) { - setParameter(i, (1.f / 127.f) * data[2]); + if (midi_cc_maps[i] == ev.data[0]) { + setParameter(i, parameterMap(i, (1.f / 127.f) * ev.data[1])); goto loopNext; } # endif diff --git a/templates/ios/src/data.h b/templates/ios/src/data.h index 8936d71..b6a2898 100644 --- a/templates/ios/src/data.h +++ b/templates/ios/src/data.h @@ -17,6 +17,7 @@ #if NUM_AUDIO_BUSES_IN + NUM_AUDIO_BUSES_OUT > 0 static struct { + size_t index; char out; char optional; char channels; @@ -24,6 +25,7 @@ static struct { {{~it.product.buses :b:i}} {{?b.type == "audio"}} { + /* .index = */ {{=i}}, /* .out = */ {{=b.direction == "output" ? 1 : 0}}, /* .optional = */ {{=b.optional ? 1 : 0}}, /* .channels = */ {{=b.channels == "mono" ? 1 : 2}} diff --git a/templates/ios/src/native.mm b/templates/ios/src/native.mm index 55ea1cf..c6a977f 100644 --- a/templates/ios/src/native.mm +++ b/templates/ios/src/native.mm @@ -265,7 +265,7 @@ char audioStart() { if (audio_bus_data[i].out) continue; for (int l = 0; l < audio_bus_data[i].channels; l++, j++) { - if (AUDIO_BUS_IN == i) { + if (AUDIO_BUS_IN == audio_bus_data[i].index) { float * b = x_buf + BLOCK_SIZE * k; x[j] = b; x_in[l] = b; @@ -287,7 +287,7 @@ char audioStart() { if (!audio_bus_data[i].out) continue; for (int l = 0; l < audio_bus_data[i].channels; l++, j++) { - if (AUDIO_BUS_OUT == i) { + if (AUDIO_BUS_OUT == audio_bus_data[i].index) { y[j] = y_buf + BLOCK_SIZE * k; y_out[l] = y[j]; k++; diff --git a/templates/lv2/src/lv2.c b/templates/lv2/src/lv2.c index d31f8c2..3356ef5 100644 --- a/templates/lv2/src/lv2.c +++ b/templates/lv2/src/lv2.c @@ -217,7 +217,17 @@ static void run(LV2_Handle instance, uint32_t sample_count) { } #endif - plugin_process(&i->p, i->x, i->y, sample_count); +#if DATA_PRODUCT_AUDIO_INPUT_CHANNELS_N > 0 + const float ** x = i->x; +#else + const float ** x = NULL; +#endif +#if DATA_PRODUCT_AUDIO_OUTPUT_CHANNELS_N > 0 + float ** y = i-> y; +#else + float ** y = NULL; +#endif + plugin_process(&i->p, x, y, sample_count); #if DATA_PRODUCT_CONTROL_OUTPUTS_N > 0 for (uint32_t j = 0; j < DATA_PRODUCT_CONTROL_OUTPUTS_N; j++) { diff --git a/templates/vst3/src/vst3.c b/templates/vst3/src/vst3.c index b4bf45f..5f40660 100644 --- a/templates/vst3/src/vst3.c +++ b/templates/vst3/src/vst3.c @@ -63,7 +63,7 @@ typedef struct pluginInstance { const float * inputs[DATA_PRODUCT_CHANNELS_AUDIO_INPUT_N]; #endif #if DATA_PRODUCT_CHANNELS_AUDIO_OUTPUT_N > 0 - float * outputs[DATA_PRODUCT_CHANNELS_AUDIO_INPUT_N]; + float * outputs[DATA_PRODUCT_CHANNELS_AUDIO_OUTPUT_N]; #endif #if DATA_PRODUCT_BUSES_AUDIO_INPUT_N > 0 char inputsActive[DATA_PRODUCT_BUSES_AUDIO_INPUT_N]; @@ -452,6 +452,8 @@ static Steinberg_tresult pluginSetBusArrangements(void* thisInterface, Steinberg if ((busInfoAudioInput[i].channelCount == 1 && inputs[i] != Steinberg_Vst_SpeakerArr_kMono) || (busInfoAudioInput[i].channelCount == 2 && inputs[i] != Steinberg_Vst_SpeakerArr_kStereo)) return Steinberg_kResultFalse; +#else + (void)inputs; #endif #if DATA_PRODUCT_BUSES_AUDIO_OUTPUT_N > 0 @@ -459,6 +461,8 @@ static Steinberg_tresult pluginSetBusArrangements(void* thisInterface, Steinberg if ((busInfoAudioOutput[i].channelCount == 1 && outputs[i] != Steinberg_Vst_SpeakerArr_kMono) || (busInfoAudioOutput[i].channelCount == 2 && outputs[i] != Steinberg_Vst_SpeakerArr_kStereo)) return Steinberg_kResultFalse; +#else + (void)outputs; #endif return Steinberg_kResultTrue; diff --git a/test/plugin.h b/test/plugin.h index 29d2c38..64bdea0 100644 --- a/test/plugin.h +++ b/test/plugin.h @@ -91,7 +91,7 @@ static void plugin_process(plugin *instance, const float **inputs, float **outpu static void plugin_midi_msg_in(plugin *instance, size_t index, const uint8_t * data) { (void)index; - if ((data[0] & 0xf0) && (data[2] != 0)) + if ((data[0] & 0xf0 == 0x90) && (data[2] != 0)) //approx instance->cutoff_k = powf(2.f, (1.f / 12.f) * (note - 60)); instance->cutoff_k = data[1] < 64 ? (-0.19558034980097166f * data[1] - 2.361735109225749f) / (data[1] - 75.57552349522389f) : (393.95397927344214f - 7.660826245588588f * data[1]) / (data[1] - 139.0755234952239f); }