cleanup (tentative) and get ready for merge

This commit is contained in:
Stefano D'Angelo 2024-02-05 13:55:57 +01:00
parent 2d3f850ca0
commit 152a33c65e
10 changed files with 272 additions and 280 deletions

View File

@ -101,7 +101,6 @@ static void data_callback(ma_device* pDevice, void* pOutput, const void* pInput,
const float * in_buf = reinterpret_cast<const float *>(pInput); const float * in_buf = reinterpret_cast<const float *>(pInput);
float * out_buf = reinterpret_cast<float *>(pOutput); float * out_buf = reinterpret_cast<float *>(pOutput);
#if NUM_CHANNELS_IN + NUM_CHANNELS_OUT > 0
ma_uint32 i = 0; ma_uint32 i = 0;
#if NUM_CHANNELS_IN > 0 #if NUM_CHANNELS_IN > 0
size_t ix = 0; size_t ix = 0;
@ -128,14 +127,13 @@ static void data_callback(ma_device* pDevice, void* pOutput, const void* pInput,
for (ma_uint32 j = 0; j < n; j++) for (ma_uint32 j = 0; j < n; j++)
for (size_t k = 0; k < NUM_CHANNELS_OUT; k++, iy++) for (size_t k = 0; k < NUM_CHANNELS_OUT; k++, iy++)
out_buf[iy] = y_buf[BLOCK_SIZE * k + j]; out_buf[iy] = y_buf[BLOCK_SIZE * k + j];
#elif NUM_CHANNELS_IN == 0
for (ma_uint32 j = 0; j < n; j++)
out_buf[j] = 0;
#endif #endif
i += n; i += n;
} }
#else
for (ma_uint32 i = 0; i < frameCount; i++)
out_buf[i] = 0.f; // Unique fake channel
#endif
} }
extern "C" extern "C"
@ -146,14 +144,14 @@ JNI_FUNC(nativeAudioStart)(JNIEnv* env, jobject thiz) {
#if NUM_CHANNELS_IN + NUM_CHANNELS_OUT > 0 #if NUM_CHANNELS_IN + NUM_CHANNELS_OUT > 0
# if NUM_CHANNELS_IN == 0 # if NUM_CHANNELS_IN == 0
ma_device_config deviceConfig = ma_device_config_init(ma_device_type_playback); ma_device_config deviceConfig = ma_device_config_init(ma_device_type_playback);
# elif NUM_CHANNELS_OUT == 0 # elif NUM_CHANNELS_OUT == 0
ma_device_config deviceConfig = ma_device_config_init(ma_device_type_capture); ma_device_config deviceConfig = ma_device_config_init(ma_device_type_capture);
# else # else
ma_device_config deviceConfig = ma_device_config_init(ma_device_type_duplex); ma_device_config deviceConfig = ma_device_config_init(ma_device_type_duplex);
# endif # endif
#else #else
ma_device_config deviceConfig = ma_device_config_init(ma_device_type_playback); ma_device_config deviceConfig = ma_device_config_init(ma_device_type_playback);
#endif #endif
deviceConfig.periodSizeInFrames = BLOCK_SIZE; deviceConfig.periodSizeInFrames = BLOCK_SIZE;
@ -171,9 +169,9 @@ JNI_FUNC(nativeAudioStart)(JNIEnv* env, jobject thiz) {
deviceConfig.playback.pDeviceID = NULL; deviceConfig.playback.pDeviceID = NULL;
deviceConfig.playback.format = ma_format_f32; deviceConfig.playback.format = ma_format_f32;
#if NUM_CHANNELS_IN + NUM_CHANNELS_OUT > 0 #if NUM_CHANNELS_IN + NUM_CHANNELS_OUT > 0
deviceConfig.playback.channels = NUM_CHANNELS_OUT; deviceConfig.playback.channels = NUM_CHANNELS_OUT;
#else #else
deviceConfig.playback.channels = 1; // Fake & muted deviceConfig.playback.channels = 1; // Fake & muted
#endif #endif
deviceConfig.playback.shareMode = ma_share_mode_shared; deviceConfig.playback.shareMode = ma_share_mode_shared;
@ -273,6 +271,7 @@ JNIEXPORT void JNICALL
JNI_FUNC(nativeAudioStop)(JNIEnv* env, jobject thiz) { JNI_FUNC(nativeAudioStop)(JNIEnv* env, jobject thiz) {
(void)env; (void)env;
(void)thiz; (void)thiz;
ma_device_stop(&device); ma_device_stop(&device);
ma_device_uninit(&device); ma_device_uninit(&device);
if (mem != NULL) if (mem != NULL)

View File

@ -1,35 +1,38 @@
include vars.mk include vars.mk
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) COMMON_DIR := $(or $(COMMON_DIR),.)
DATA_DIR := $(or $(DATA_DIR),.)
PLUGIN_DIR := $(or $(PLUGIN_DIR),src)
SOURCES := \
${DATA_DIR}/src/data.h \
${DATA_DIR}/src/index.html \
${COMMON_DIR}/src/app.swift \
${COMMON_DIR}/src/native.mm \
${COMMON_DIR}/src/app-Bridging-Header.h \
${PLUGIN_DIR}/plugin.h \
${C_SRCS_EXTRA} \
${CXX_SRCS_EXTRA}
SOURCES_OUT = $(addprefix build/gen/src/, $(notdir $(SOURCES)))
SOURCES := data.h index.html app.swift native.mm app-Bridging-Header.h platform.h plugin.h all: build/gen/${BUNDLE_NAME}.xcodeproj
SOURCES_IN := $(addprefix ${ROOT_DIR}/src/, ${SOURCES})
SOURCES_OUT := $(addprefix ${ROOT_DIR}/build/gen/src/, ${SOURCES})
EXT_SOURCES_IN := ${3RDPARTYFILES}
EXT_SOURCES_OUT :=
build/gen/${BUNDLE_NAME}.xcodeproj: ${SOURCES_OUT}
all: build/gen/${PROJECT_NAME}.xcodeproj
${SOURCES_OUT}: ${SOURCES_IN} ${EXT_SOURCES_IN} | build/gen/src
cp $^ ${ROOT_DIR}/build/gen/src
${EXT_SOURCES_OUT}: ${EXT_SOURCES_IN}
cp ${EXT_SOURCES_IN} ${ROOT_DIR}/build/gen/src/
build/gen/${PROJECT_NAME}.xcodeproj: ${SOURCES_OUT}
xcodegen generate --spec project.yml xcodegen generate --spec project.yml
mv ${PROJECT_NAME}.xcodeproj build/gen/${PROJECT_NAME}.xcodeproj mv ${BUNDLE_NAME}.xcodeproj build/gen/${BUNDLE_NAME}.xcodeproj
mv Info.plist build/gen/Info.plist mv Info.plist build/gen/Info.plist
build/gen build/gen/src: build/gen/src:
mkdir -p $@ mkdir -p $@
clean: clean:
rm -fr build rm -fr build
install: .PHONY: all clean
.PHONY: all clean install .SECONDEXPANSION:
PERCENT := %
$(SOURCES_OUT): build/gen/src/%: $$(filter $$(PERCENT)/%,$$(SOURCES)) | build/gen/src
cp $^ $@

View File

@ -1,6 +1,6 @@
name: {{=it.ios_make.projectName}} name: {{=it.product.bundleName}}
targets: targets:
{{=it.ios_make.targetName}}: {{=it.product.bundleName}}:
platform: [iOS] platform: [iOS]
deploymentTarget: deploymentTarget:
iOS: {{=it.ios_make.deploymentTarget}} iOS: {{=it.ios_make.deploymentTarget}}
@ -9,11 +9,15 @@ targets:
- path: src - path: src
settings: settings:
base: base:
PRODUCT_BUNDLE_IDENTIFIER: com.orastron.{{=it.product.bundleName}} PRODUCT_BUNDLE_IDENTIFIER: {{=it.ios_make.productBundleIdentifier}}
SWIFT_OBJC_BRIDGING_HEADER: src/app-Bridging-Header.h SWIFT_OBJC_BRIDGING_HEADER: src/app-Bridging-Header.h
HEADER_SEARCH_PATHS: {{~it.ios_make.header_search_paths:p}} {{?it.ios_make.headerSearchPaths}}
HEADER_SEARCH_PATHS: {{~it.ios_make.headerSearchPaths :p}}
- {{=p}}{{~}} - {{=p}}{{~}}
{{?}}
info: info:
path: Info.plist path: Info.plist
{{?it.product.buses.filter(x => x.type == "audio" && x.direction == "input").length > 0}}
properties: properties:
NSMicrophoneUsageDescription: Audio input access needed to run the example NSMicrophoneUsageDescription: Need audio input for processing sound
{{?}}

View File

@ -1,8 +1,8 @@
BUNDLE_NAME := {{=it.product.bundleName}} BUNDLE_NAME := {{=it.product.bundleName}}
PROJECT_NAME := {{=it.ios_make.projectName}} C_SRCS_EXTRA := {{=it.make && it.make.cSrcs ? it.make.cSrcs : ""}} {{=it.ios_make && it.ios_make.cSrcs ? it.ios_make.cSrcs : ""}}
TARGET_NAME := {{=it.ios_make.targetName}} CXX_SRCS_EXTRA := {{=it.make && it.make.cxxSrcs ? it.make.cxxSrcs : ""}} {{=it.ios_make && it.ios_make.cxxSrcs ? it.ios_make.cxxSrcs : ""}}
3RDPARTYFILES := {{=it.ios_make["3rdpartyfiles"].join(' ')}} COMMON_DIR := {{=it.ios_make && it.ios_make.commonDir ? it.ios_make.commonDir : (it.make && it.make.commonDir ? it.make.commonDir : "")}}
DATA_DIR := {{=it.ios_make && it.ios_make.dataDir ? it.ios_make.dataDir : (it.make && it.make.dataDir ? it.make.dataDir : "")}}
HAS_MIDI_IN := {{=it.product.buses.filter(x => x.type == "midi" && x.direction == "input").length > 0 ? "yes" : "no"}} PLUGIN_DIR := {{=it.ios_make && it.ios_make.pluginDir ? it.ios_make.pluginDir : (it.make && it.make.pluginDir ? it.make.pluginDir : "")}}

View File

@ -16,7 +16,7 @@
#include "miniaudio.h" #include "miniaudio.h"
#define BLOCK_SIZE 32 #define BLOCK_SIZE 32
#define NUM_BUFS (NUM_CHANNELS_IN > NUM_CHANNELS_OUT ? NUM_CHANNELS_IN : NUM_CHANNELS_OUT) #define NUM_BUFS (NUM_CHANNELS_IN > NUM_CHANNELS_OUT ? NUM_CHANNELS_IN : NUM_CHANNELS_OUT)
static ma_device device; static ma_device device;
static plugin instance; static plugin instance;
@ -50,302 +50,301 @@ CFStringRef midiClientName = NULL;
MIDIClientRef midiClient = NULL; MIDIClientRef midiClient = NULL;
CFStringRef midiInputName = NULL; CFStringRef midiInputName = NULL;
MIDIPortRef midiPort = NULL; MIDIPortRef midiPort = NULL;
#define MIDIBUFFERLEN 1026 #define MIDIBUFFERLEN 1023
uint8_t midiBuffer[MIDIBUFFERLEN]; uint8_t midiBuffer[MIDIBUFFERLEN];
int midiBuffer_i = 0; int midiBuffer_i = 0;
#endif #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;
#if PARAMETERS_N + NUM_MIDI_INPUTS > 0 #if PARAMETERS_N + NUM_MIDI_INPUTS > 0
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)
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];
} }
} }
# endif # endif
# if NUM_MIDI_INPUTS > 0 # if NUM_MIDI_INPUTS > 0
if (midiBuffer_i > 0) { if (midiBuffer_i > 0) {
for (int i = 0; i < midiBuffer_i; i+=3) { for (int i = 0; i < midiBuffer_i; i+=3) {
plugin_midi_msg_in(&instance, MIDI_BUS_IN, &(midiBuffer[i])); plugin_midi_msg_in(&instance, MIDI_BUS_IN, &(midiBuffer[i]));
} }
} }
midiBuffer_i = 0; midiBuffer_i = 0;
# endif # endif
mutex.unlock(); mutex.unlock();
} }
#endif #endif
#if NUM_CHANNELS_IN == 0 #if NUM_CHANNELS_IN == 0
(void)pInput; (void)pInput;
#else #else
const float * in_buf = reinterpret_cast<const float *>(pInput); const float * in_buf = reinterpret_cast<const float *>(pInput);
#endif #endif
float * out_buf = reinterpret_cast<float *>(pOutput); float * out_buf = reinterpret_cast<float *>(pOutput);
#if NUM_CHANNELS_IN + NUM_CHANNELS_OUT > 0 ma_uint32 i = 0;
ma_uint32 i = 0; #if NUM_CHANNELS_IN > 0
#if NUM_CHANNELS_IN > 0 size_t ix = 0;
size_t ix = 0;
#endif
#if NUM_CHANNELS_OUT > 0
size_t iy = 0;
#endif
while (i < frameCount) {
ma_uint32 n = std::min(frameCount - i, static_cast<ma_uint32>(BLOCK_SIZE));
#if NUM_CHANNELS_IN > 0
for (ma_uint32 j = 0; j < n; j++)
for (size_t k = 0; k < NUM_CHANNELS_IN; k++, ix++)
x_buf[BLOCK_SIZE * k + j] = in_buf[ix];
#endif
#if NUM_NON_OPT_CHANNELS_IN > NUM_CHANNELS_IN
memset(zero, 0, BLOCK_SIZE * sizeof(float));
#endif
plugin_process(&instance, x, y, n);
#if NUM_CHANNELS_OUT > 0
for (ma_uint32 j = 0; j < n; j++)
for (size_t k = 0; k < NUM_CHANNELS_OUT; k++, iy++)
out_buf[iy] = y_buf[BLOCK_SIZE * k + j];
#endif
i += n;
}
#else
for (ma_uint32 i = 0; i < frameCount; i++)
out_buf[i] = 0.f; // Unique fake channel
#endif #endif
#if NUM_CHANNELS_OUT > 0
size_t iy = 0;
#endif
while (i < frameCount) {
ma_uint32 n = std::min(frameCount - i, static_cast<ma_uint32>(BLOCK_SIZE));
#if NUM_CHANNELS_IN > 0
for (ma_uint32 j = 0; j < n; j++)
for (size_t k = 0; k < NUM_CHANNELS_IN; k++, ix++)
x_buf[BLOCK_SIZE * k + j] = in_buf[ix];
#endif
#if NUM_NON_OPT_CHANNELS_IN > NUM_CHANNELS_IN
memset(zero, 0, BLOCK_SIZE * sizeof(float));
#endif
plugin_process(&instance, x, y, n);
#if NUM_CHANNELS_OUT > 0
for (ma_uint32 j = 0; j < n; j++)
for (size_t k = 0; k < NUM_CHANNELS_OUT; k++, iy++)
out_buf[iy] = y_buf[BLOCK_SIZE * k + j];
#elif NUM_CHANNELS_IN == 0
for (ma_uint32 j = 0; j < n; j++)
out_buf[j] = 0.f;
#endif
i += n;
}
} }
#if (NUM_MIDI_INPUTS > 0) #if (NUM_MIDI_INPUTS > 0)
void (^midiNotifyBlock)(const MIDINotification *message) = ^(const MIDINotification *message) { void (^midiNotifyBlock)(const MIDINotification *message) = ^(const MIDINotification *message) {
if (message->messageID != kMIDIMsgObjectAdded) if (message->messageID != kMIDIMsgObjectAdded)
return; return;
const MIDIObjectAddRemoveNotification *n = reinterpret_cast<const MIDIObjectAddRemoveNotification *>(message); const MIDIObjectAddRemoveNotification *n = reinterpret_cast<const MIDIObjectAddRemoveNotification *>(message);
MIDIEndpointRef endPoint = n->child; MIDIEndpointRef endPoint = n->child;
MIDIPortConnectSource(midiPort, endPoint, NULL); MIDIPortConnectSource(midiPort, endPoint, NULL);
}; };
void (^midiReceiveBlock)(const MIDIEventList *evtlist, void *srcConnRefCon) = ^(const MIDIEventList *evtlist, void *srcConnRefCon) { void (^midiReceiveBlock)(const MIDIEventList *evtlist, void *srcConnRefCon) = ^(const MIDIEventList *evtlist, void *srcConnRefCon) {
const MIDIEventPacket *p = evtlist->packet; const MIDIEventPacket *p = evtlist->packet;
for (UInt32 i = 0; i < evtlist->numPackets; i++) { for (UInt32 i = 0; i < evtlist->numPackets; i++) {
for (UInt32 j = 0; j < p->wordCount; j++) { for (UInt32 j = 0; j < p->wordCount; j++) {
const UInt32 w = p->words[j]; const UInt32 w = p->words[j];
const uint8_t* t = (uint8_t*) &(w); const uint8_t* t = (uint8_t*) &(w);
if ((t[3] & 0xf0) != 32) if ((t[3] & 0xf0) != 32)
continue; // We only support MIDI 1.0 continue; // We only support MIDI 1.0
if ((t[2] & 0xF0) == 0xF0) if ((t[2] & 0xF0) == 0xF0)
continue; continue;
mutex.lock(); mutex.lock();
if (midiBuffer_i < MIDIBUFFERLEN - 3) { if (midiBuffer_i < MIDIBUFFERLEN - 3) {
midiBuffer[midiBuffer_i ] = t[2]; midiBuffer[midiBuffer_i ] = t[2];
midiBuffer[midiBuffer_i + 1] = t[1]; midiBuffer[midiBuffer_i + 1] = t[1];
midiBuffer[midiBuffer_i + 2] = t[0]; midiBuffer[midiBuffer_i + 2] = t[0];
midiBuffer_i += 3; midiBuffer_i += 3;
} }
mutex.unlock(); mutex.unlock();
} }
p = MIDIEventPacketNext(p); p = MIDIEventPacketNext(p);
} }
}; };
#endif #endif
extern "C" extern "C"
char audioStart() { char audioStart() {
#if NUM_CHANNELS_IN + NUM_CHANNELS_OUT > 0 #if NUM_CHANNELS_IN + NUM_CHANNELS_OUT > 0
# if NUM_CHANNELS_IN == 0 # if NUM_CHANNELS_IN == 0
ma_device_config deviceConfig = ma_device_config_init(ma_device_type_playback); ma_device_config deviceConfig = ma_device_config_init(ma_device_type_playback);
# elif NUM_CHANNELS_OUT == 0 # elif NUM_CHANNELS_OUT == 0
ma_device_config deviceConfig = ma_device_config_init(ma_device_type_capture); ma_device_config deviceConfig = ma_device_config_init(ma_device_type_capture);
# else # else
ma_device_config deviceConfig = ma_device_config_init(ma_device_type_duplex); ma_device_config deviceConfig = ma_device_config_init(ma_device_type_duplex);
# endif # endif
#else #else
ma_device_config deviceConfig = ma_device_config_init(ma_device_type_playback); ma_device_config deviceConfig = ma_device_config_init(ma_device_type_playback);
#endif #endif
deviceConfig.periodSizeInFrames = BLOCK_SIZE; deviceConfig.periodSizeInFrames = BLOCK_SIZE;
deviceConfig.periods = 1; deviceConfig.periods = 1;
deviceConfig.performanceProfile = ma_performance_profile_low_latency; deviceConfig.performanceProfile = ma_performance_profile_low_latency;
deviceConfig.noPreSilencedOutputBuffer = 1; deviceConfig.noPreSilencedOutputBuffer = 1;
deviceConfig.noClip = 0; deviceConfig.noClip = 0;
deviceConfig.noDisableDenormals = 0; deviceConfig.noDisableDenormals = 0;
deviceConfig.noFixedSizedCallback = 1; deviceConfig.noFixedSizedCallback = 1;
deviceConfig.dataCallback = data_callback; deviceConfig.dataCallback = data_callback;
deviceConfig.capture.pDeviceID = NULL; deviceConfig.capture.pDeviceID = NULL;
deviceConfig.capture.format = ma_format_f32; deviceConfig.capture.format = ma_format_f32;
deviceConfig.capture.channels = NUM_CHANNELS_IN; deviceConfig.capture.channels = NUM_CHANNELS_IN;
deviceConfig.capture.shareMode = ma_share_mode_shared; deviceConfig.capture.shareMode = ma_share_mode_shared;
deviceConfig.playback.pDeviceID = NULL; deviceConfig.playback.pDeviceID = NULL;
deviceConfig.playback.format = ma_format_f32; deviceConfig.playback.format = ma_format_f32;
#if NUM_CHANNELS_IN + NUM_CHANNELS_OUT > 0 #if NUM_CHANNELS_IN + NUM_CHANNELS_OUT > 0
deviceConfig.playback.channels = NUM_CHANNELS_OUT; deviceConfig.playback.channels = NUM_CHANNELS_OUT;
#else #else
deviceConfig.playback.channels = 1; // Fake & muted deviceConfig.playback.channels = 1; // Fake & muted
#endif #endif
deviceConfig.playback.shareMode = ma_share_mode_shared; deviceConfig.playback.shareMode = ma_share_mode_shared;
if (ma_device_init(NULL, &deviceConfig, &device) != MA_SUCCESS) if (ma_device_init(NULL, &deviceConfig, &device) != MA_SUCCESS)
return false; return false;
#if (NUM_MIDI_INPUTS > 0) #if (NUM_MIDI_INPUTS > 0)
if (midiClientName == NULL) { if (midiClientName == NULL) {
midiClientName = CFSTR("template"); midiClientName = CFSTR("template");
if (midiClientName == NULL) if (midiClientName == NULL)
return false; // Check unint return false; // Check unint
} }
if (midiClient == (MIDIClientRef)NULL) { if (midiClient == (MIDIClientRef)NULL) {
if (MIDIClientCreateWithBlock(midiClientName, &midiClient, midiNotifyBlock) != 0) if (MIDIClientCreateWithBlock(midiClientName, &midiClient, midiNotifyBlock) != 0)
return false; return false;
} }
if (midiInputName == NULL) { if (midiInputName == NULL) {
midiInputName = CFSTR("Input"); midiInputName = CFSTR("Input");
if (midiInputName == NULL) if (midiInputName == NULL)
return false; return false;
} }
if (midiPort == (MIDIPortRef)NULL) { if (midiPort == (MIDIPortRef)NULL) {
if (MIDIInputPortCreateWithProtocol(midiClient, midiInputName, kMIDIProtocol_1_0, &midiPort, midiReceiveBlock) != 0) if (MIDIInputPortCreateWithProtocol(midiClient, midiInputName, kMIDIProtocol_1_0, &midiPort, midiReceiveBlock) != 0)
return false; return false;
ItemCount n = MIDIGetNumberOfSources(); ItemCount n = MIDIGetNumberOfSources();
for (ItemCount i = 0; i < n; i++) { for (ItemCount i = 0; i < n; i++) {
MIDIEndpointRef endPoint = MIDIGetSource(i); MIDIEndpointRef endPoint = MIDIGetSource(i);
MIDIPortConnectSource(midiPort, endPoint, NULL); MIDIPortConnectSource(midiPort, endPoint, NULL);
} }
} }
#endif #endif
plugin_init(&instance); plugin_init(&instance);
#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)
plugin_set_parameter(&instance, i, param_data[i].def); plugin_set_parameter(&instance, i, param_data[i].def);
param_values_prev[i] = param_values[i] = param_data[i].def; param_values_prev[i] = param_values[i] = param_data[i].def;
} }
#endif #endif
plugin_set_sample_rate(&instance, (float)device.sampleRate); plugin_set_sample_rate(&instance, (float)device.sampleRate);
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);
if (mem == NULL) { if (mem == NULL) {
plugin_fini(&instance); plugin_fini(&instance);
ma_device_uninit(&device); ma_device_uninit(&device);
return false; return false;
} }
plugin_mem_set(&instance, mem); plugin_mem_set(&instance, mem);
} else } else
mem = NULL; mem = NULL;
plugin_reset(&instance); plugin_reset(&instance);
#if NUM_ALL_CHANNELS_IN > 0 #if NUM_ALL_CHANNELS_IN > 0
# if AUDIO_BUS_IN >= 0 # if AUDIO_BUS_IN >= 0
size_t ix = 0; size_t ix = 0;
size_t ixb = 0; size_t ixb = 0;
for (size_t j = 0; j < NUM_AUDIO_BUSES_IN + NUM_AUDIO_BUSES_OUT; j++) { for (size_t j = 0; j < NUM_AUDIO_BUSES_IN + NUM_AUDIO_BUSES_OUT; j++) {
if (audio_bus_data[j].out) if (audio_bus_data[j].out)
continue; continue;
if (audio_bus_data[j].index == AUDIO_BUS_IN) if (audio_bus_data[j].index == AUDIO_BUS_IN)
for (char k = 0; k < audio_bus_data[j].channels; k++, ix++, ixb++) for (char k = 0; k < audio_bus_data[j].channels; k++, ix++, ixb++)
x[ix] = x_buf + BLOCK_SIZE * ixb; x[ix] = x_buf + BLOCK_SIZE * ixb;
# if NUM_NON_OPT_CHANNELS_IN > NUM_CHANNELS_IN # if NUM_NON_OPT_CHANNELS_IN > NUM_CHANNELS_IN
else if (!audio_bus_data[j].optional) else if (!audio_bus_data[j].optional)
for (char k = 0; k < audio_bus_data[j].channels; k++, ix++) for (char k = 0; k < audio_bus_data[j].channels; k++, ix++)
x[ix] = zero; x[ix] = zero;
# endif # endif
else else
for (char k = 0; k < audio_bus_data[j].channels; k++, ix++) for (char k = 0; k < audio_bus_data[j].channels; k++, ix++)
x[ix] = NULL; x[ix] = NULL;
} }
# else # else
for (size_t i = 0; i < NUM_ALL_CHANNELS_IN; i++) for (size_t i = 0; i < NUM_ALL_CHANNELS_IN; i++)
x[i] = NULL; x[i] = NULL;
# endif # endif
#else #else
x = NULL; x = NULL;
#endif #endif
#if NUM_ALL_CHANNELS_OUT > 0 #if NUM_ALL_CHANNELS_OUT > 0
# if AUDIO_BUS_OUT >= 0 # if AUDIO_BUS_OUT >= 0
size_t iy = 0; size_t iy = 0;
size_t iyb = 0; size_t iyb = 0;
for (size_t j = 0; j < NUM_AUDIO_BUSES_IN + NUM_AUDIO_BUSES_OUT; j++) { for (size_t j = 0; j < NUM_AUDIO_BUSES_IN + NUM_AUDIO_BUSES_OUT; j++) {
if (!audio_bus_data[j].out) if (!audio_bus_data[j].out)
continue; continue;
if (audio_bus_data[j].index == AUDIO_BUS_OUT) if (audio_bus_data[j].index == AUDIO_BUS_OUT)
for (char k = 0; k < audio_bus_data[j].channels; k++, iy++, iyb++) for (char k = 0; k < audio_bus_data[j].channels; k++, iy++, iyb++)
y[iy] = y_buf + BLOCK_SIZE * iyb; y[iy] = y_buf + BLOCK_SIZE * iyb;
# if NUM_NON_OPT_CHANNELS_OUT > NUM_CHANNELS_OUT # if NUM_NON_OPT_CHANNELS_OUT > NUM_CHANNELS_OUT
else if (!audio_bus_data[j].optional) else if (!audio_bus_data[j].optional)
for (char k = 0; k < audio_bus_data[j].channels; k++, iy++) for (char k = 0; k < audio_bus_data[j].channels; k++, iy++)
y[iy] = zero; y[iy] = zero;
# endif # endif
else else
for (char k = 0; k < audio_bus_data[j].channels; k++, iy++) for (char k = 0; k < audio_bus_data[j].channels; k++, iy++)
y[iy] = NULL; y[iy] = NULL;
} }
# else # else
for (size_t i = 0; i < NUM_ALL_CHANNELS_OUT; i++) for (size_t i = 0; i < NUM_ALL_CHANNELS_OUT; i++)
y[i] = NULL; y[i] = NULL;
# endif # endif
#else #else
y = NULL; y = NULL;
#endif #endif
if (ma_device_start(&device) != MA_SUCCESS) { if (ma_device_start(&device) != MA_SUCCESS) {
if (mem != NULL) if (mem != NULL)
free(mem); free(mem);
ma_device_uninit(&device); ma_device_uninit(&device);
return false; return false;
} }
return true; return true;
} }
extern "C" extern "C"
void audioStop() { void audioStop() {
ma_device_stop(&device); ma_device_stop(&device);
ma_device_uninit(&device); ma_device_uninit(&device);
if (mem != NULL) if (mem != NULL)
free(mem); free(mem);
plugin_fini(&instance); plugin_fini(&instance);
// No need to close MIDI connections (e.g. via MIDIClientDispose), the system terminates them when the app terminates. // No need to close MIDI connections (e.g. via MIDIClientDispose), the system terminates them when the app terminates.
} }
extern "C" extern "C"
float getParameter(int i) { float getParameter(int i) {
#if PARAMETERS_N > 0 #if PARAMETERS_N > 0
mutex.lock(); mutex.lock();
float v = param_values[i]; float v = param_values[i];
mutex.unlock(); mutex.unlock();
return v; return v;
#else #else
return 0.f; (void)i;
return 0.f;
#endif #endif
} }
extern "C" extern "C"
void setParameter(int i, float v) { void setParameter(int i, float v) {
if (param_data[i].flags & (PARAM_BYPASS | PARAM_TOGGLED)) if (param_data[i].flags & (PARAM_BYPASS | PARAM_TOGGLED))
v = v > 0.5f ? 1.f : 0.f; v = v > 0.5f ? 1.f : 0.f;
else if (param_data[i].flags & PARAM_INTEGER) else if (param_data[i].flags & PARAM_INTEGER)
v = (int32_t)(v + 0.5f); v = (int32_t)(v + 0.5f);
v = std::min(std::max(v, param_data[i].min), param_data[i].max); v = std::min(std::max(v, param_data[i].min), param_data[i].max);
#if PARAMETERS_N > 0 #if PARAMETERS_N > 0
mutex.lock(); mutex.lock();
param_values[i] = v; param_values[i] = v;
mutex.unlock(); mutex.unlock();
#endif #endif
} }

View File

@ -1,6 +0,0 @@
#ifndef PLATFORM_H
#define PLATFORM_H
#define NDEBUG
#endif

View File

@ -3,9 +3,8 @@ var sep = path.sep;
module.exports = function (data, api) { module.exports = function (data, api) {
api.generateFileFromTemplateFile(`src${sep}data.h`, `src${sep}data.h`, data); api.generateFileFromTemplateFile(`src${sep}data.h`, `src${sep}data.h`, data);
api.generateFileFromTemplateFile(`src${sep}index.html`, `src${sep}index.html`, data);
api.copyFile(`src${sep}native.mm`, `src${sep}native.mm`); api.copyFile(`src${sep}native.mm`, `src${sep}native.mm`);
api.copyFile(`src${sep}app-Bridging-Header.h`, `src${sep}app-Bridging-Header.h`); api.copyFile(`src${sep}app-Bridging-Header.h`, `src${sep}app-Bridging-Header.h`);
api.copyFile(`src${sep}platform.h`, `src${sep}platform.h`); api.copyFile(`src${sep}app.swift`, `src${sep}app.swift`, data);
api.generateFileFromTemplateFile(`src${sep}app.swift`, `src${sep}app.swift`, data);
api.generateFileFromTemplateFile(`src${sep}index.html`, `src${sep}index.html`, data);
}; };

View File

@ -1,11 +1,8 @@
{ {
"ios_make": { "ios_make": {
"header_search_paths": [], "headerSearchPaths": [],
"3rdpartyfiles": [ "sourcesExtra": [],
"../../../miniaudio/miniaudio.h" "productBundleIdentifier": "com.example.tibia_test",
],
"projectName": "tibia_test",
"targetName": "tibia_test",
"deploymentTarget": 16.6 "deploymentTarget": 16.6
} }
} }

View File

@ -1,3 +0,0 @@
{
}

View File

@ -19,8 +19,8 @@ $dir/../tibia $dir/product.json,$dir/company.json,$dir/android.json,$dir/android
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
$dir/../tibia $dir/product.json,$dir/company.json,$dir/ios.json $dir/../templates/ios $dir/../out/ios $dir/../tibia $dir/product.json,$dir/company.json $dir/../templates/ios $dir/../out/ios
$dir/../tibia $dir/product.json,$dir/company.json,$dir/ios.json,$dir/ios-make.json $dir/../templates/ios-make $dir/../out/ios $dir/../tibia $dir/product.json,$dir/company.json,$dir/ios-make.json $dir/../templates/ios-make $dir/../out/ios
cp $dir/plugin.h $dir/../out/ios/src cp $dir/plugin.h $dir/../out/ios/src
$dir/../tibia $dir/product.json,$dir/company.json,$dir/cmd.json $dir/../templates/cmd $dir/../out/cmd $dir/../tibia $dir/product.json,$dir/company.json,$dir/cmd.json $dir/../templates/cmd $dir/../out/cmd