2021-07-27 09:47:15 +02:00
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
#include "ProcessUnit_FX.h"
|
2021-07-27 19:00:39 +02:00
|
|
|
#include "constants.h"
|
2022-08-23 00:17:32 +02:00
|
|
|
#include "log.h"
|
2021-07-27 09:47:15 +02:00
|
|
|
|
2022-08-23 14:59:08 +02:00
|
|
|
#define EFFECT_NAME "ViPER4Android Reworked " VERSION_STRING
|
2022-08-23 07:47:06 +00:00
|
|
|
#define EFFECT_IMPLEMENTOR "ViPER.WYF, Martmists, Iscle"
|
|
|
|
|
2021-07-27 09:47:15 +02:00
|
|
|
static effect_descriptor_t viper_descriptor = {
|
|
|
|
// Identical type/uuid to original ViPER4Android
|
2022-08-23 00:26:44 +02:00
|
|
|
.type = {0x00000000, 0x0000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
|
|
|
|
.uuid = {0x41d3c987, 0xe6cf, 0x11e3, 0xa88a, {0x11, 0xab, 0xa5, 0xd5, 0xc5, 0x1b}},
|
2022-08-23 00:17:32 +02:00
|
|
|
.apiVersion = EFFECT_CONTROL_API_VERSION,
|
|
|
|
.flags = EFFECT_FLAG_OUTPUT_BOTH | EFFECT_FLAG_INPUT_BOTH | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_TYPE_INSERT,
|
|
|
|
.cpuLoad = 8, // In 0.1 MIPS units as estimated on an ARM9E core (ARMv5TE) with 0 WS
|
|
|
|
.memoryUsage = 1, // In KB and includes only dynamically allocated memory
|
2022-08-23 07:47:06 +00:00
|
|
|
.name = EFFECT_NAME,
|
|
|
|
.implementor = EFFECT_IMPLEMENTOR
|
2021-07-27 09:47:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
extern "C" {
|
2022-08-23 00:26:44 +02:00
|
|
|
struct ViperContext {
|
2022-08-23 07:47:06 +00:00
|
|
|
const struct effect_interface_s *interface; // Should always be the first struct member
|
2022-08-23 00:26:44 +02:00
|
|
|
ProcessUnit_FX *effect;
|
|
|
|
};
|
2022-08-23 00:17:32 +02:00
|
|
|
|
2022-08-23 07:47:06 +00:00
|
|
|
static int32_t ViperProcess(effect_handle_t self, audio_buffer_t *inBuffer, audio_buffer_t *outBuffer) {
|
2022-08-23 00:26:44 +02:00
|
|
|
auto pContext = (ViperContext *) self;
|
|
|
|
|
|
|
|
if (pContext == nullptr) {
|
2022-08-23 07:47:06 +00:00
|
|
|
v4a_printf(ANDROID_LOG_ERROR, "ViperProcess(), Error [pContext = NULL]");
|
2022-08-23 00:26:44 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2022-08-23 00:17:32 +02:00
|
|
|
|
2022-08-23 07:47:06 +00:00
|
|
|
if (inBuffer == nullptr) {
|
|
|
|
v4a_printf(ANDROID_LOG_ERROR, "ViperProcess(), Error [inBuffer = NULL]");
|
2022-08-23 00:26:44 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2022-08-23 00:17:32 +02:00
|
|
|
|
2022-08-23 07:47:06 +00:00
|
|
|
if (outBuffer == nullptr) {
|
|
|
|
v4a_printf(ANDROID_LOG_ERROR, "ViperProcess(), Error [outBuffer = NULL]");
|
2022-08-23 00:26:44 +02:00
|
|
|
return -EINVAL;
|
2021-07-27 09:47:15 +02:00
|
|
|
}
|
|
|
|
|
2022-08-23 07:47:06 +00:00
|
|
|
return pContext->effect->process(inBuffer, outBuffer);
|
2022-08-23 00:26:44 +02:00
|
|
|
}
|
2022-08-23 00:17:32 +02:00
|
|
|
|
2022-08-23 00:26:44 +02:00
|
|
|
static int32_t
|
2022-08-23 07:47:06 +00:00
|
|
|
ViperCommand(effect_handle_t self, uint32_t cmdCode, uint32_t cmdSize, void *pCmdData, uint32_t *replySize,
|
2022-08-23 00:26:44 +02:00
|
|
|
void *pReplyData) {
|
|
|
|
auto pContext = (ViperContext *) self;
|
2022-08-23 00:17:32 +02:00
|
|
|
|
2022-08-23 00:26:44 +02:00
|
|
|
if (pContext == nullptr) {
|
2022-08-23 07:47:06 +00:00
|
|
|
v4a_printf(ANDROID_LOG_ERROR, "ViperCommand(), Error [pContext = NULL]");
|
2022-08-23 00:26:44 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2022-08-23 00:17:32 +02:00
|
|
|
|
2022-08-23 00:26:44 +02:00
|
|
|
return pContext->effect->command(cmdCode, cmdSize, pCmdData, replySize, pReplyData);
|
|
|
|
}
|
2022-08-23 00:17:32 +02:00
|
|
|
|
2022-08-23 07:47:06 +00:00
|
|
|
static int32_t ViperGetDescriptor(effect_handle_t self, effect_descriptor_t *pDescriptor) {
|
2022-08-23 00:26:44 +02:00
|
|
|
auto *pContext = (ViperContext *) self;
|
|
|
|
|
|
|
|
if (pContext == nullptr) {
|
2022-08-23 07:47:06 +00:00
|
|
|
v4a_printf(ANDROID_LOG_ERROR, "ViperGetDescriptor(), Error [pContext = NULL]");
|
2022-08-23 00:26:44 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pDescriptor == nullptr) {
|
2022-08-23 07:47:06 +00:00
|
|
|
v4a_print(ANDROID_LOG_ERROR, "ViperGetDescriptor(), Error [pDescriptor = NULL]");
|
2022-08-23 00:26:44 +02:00
|
|
|
return -EINVAL;
|
2021-07-27 09:47:15 +02:00
|
|
|
}
|
|
|
|
|
2022-08-23 07:47:06 +00:00
|
|
|
*pDescriptor = viper_descriptor;
|
2022-08-23 00:26:44 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const effect_interface_s viper_interface = {
|
2022-08-23 07:47:06 +00:00
|
|
|
.process = ViperProcess,
|
|
|
|
.command = ViperCommand,
|
|
|
|
.get_descriptor = ViperGetDescriptor
|
2022-08-23 00:26:44 +02:00
|
|
|
};
|
2022-08-23 00:17:32 +02:00
|
|
|
|
2022-08-23 07:47:06 +00:00
|
|
|
int32_t ViperEffectCreate(const effect_uuid_t *uuid, int32_t sessionId, int32_t ioId, effect_handle_t *pHandle) {
|
|
|
|
v4a_print(ANDROID_LOG_INFO, "Enter ViperEffectCreate()");
|
2021-07-27 19:00:39 +02:00
|
|
|
|
2022-08-23 00:26:44 +02:00
|
|
|
if (uuid == nullptr) {
|
2022-08-23 07:47:06 +00:00
|
|
|
v4a_printf(ANDROID_LOG_ERROR, "ViperEffectCreate(), Error [uuid = NULL]");
|
2022-08-23 00:26:44 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2021-07-27 09:47:15 +02:00
|
|
|
|
2022-08-23 00:26:44 +02:00
|
|
|
if (pHandle == nullptr) {
|
2022-08-23 07:47:06 +00:00
|
|
|
v4a_printf(ANDROID_LOG_ERROR, "ViperEffectCreate(), Error [pHandle = NULL]");
|
2022-08-23 00:26:44 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2021-07-27 19:00:39 +02:00
|
|
|
|
2022-08-23 00:26:44 +02:00
|
|
|
if (memcmp(uuid, &viper_descriptor.uuid, sizeof(effect_uuid_t)) != 0) {
|
2022-08-23 07:47:06 +00:00
|
|
|
v4a_print(ANDROID_LOG_ERROR, "ViperEffectCreate(), Error [effect not found]");
|
2022-08-23 00:26:44 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2021-07-27 19:00:39 +02:00
|
|
|
|
2022-08-23 07:47:06 +00:00
|
|
|
v4a_printf(ANDROID_LOG_INFO, "ViperEffectCreate(), uuid = %08x-%04x-%04x-%04x-%02x%02x%02x%02x%02x%02x",
|
2022-08-23 00:26:44 +02:00
|
|
|
uuid->timeLow, uuid->timeMid, uuid->timeHiAndVersion, uuid->clockSeq, uuid->node[0], uuid->node[1],
|
|
|
|
uuid->node[2], uuid->node[3], uuid->node[4], uuid->node[5]);
|
2022-08-23 07:47:06 +00:00
|
|
|
v4a_print(ANDROID_LOG_INFO, "ViperEffectCreate(), Constructing ProcessUnit_FX");
|
2022-08-23 00:17:32 +02:00
|
|
|
|
2022-08-24 11:07:15 +02:00
|
|
|
auto *pContext = new ViperContext();
|
2022-08-23 00:26:44 +02:00
|
|
|
pContext->interface = &viper_interface;
|
|
|
|
pContext->effect = new ProcessUnit_FX();
|
2021-07-27 19:00:39 +02:00
|
|
|
|
2022-08-23 00:26:44 +02:00
|
|
|
*pHandle = (effect_handle_t) pContext;
|
2021-07-27 09:47:15 +02:00
|
|
|
|
2022-08-23 00:26:44 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2022-08-23 00:17:32 +02:00
|
|
|
|
2022-08-23 07:47:06 +00:00
|
|
|
int32_t ViperEffectRelease(effect_handle_t handle) {
|
2022-08-23 00:26:44 +02:00
|
|
|
auto *pContext = (ViperContext *) handle;
|
2022-08-23 00:17:32 +02:00
|
|
|
|
2022-08-23 07:47:06 +00:00
|
|
|
v4a_print(ANDROID_LOG_INFO, "Enter ViperEffectRelease()");
|
2022-08-23 00:17:32 +02:00
|
|
|
|
2022-08-23 00:26:44 +02:00
|
|
|
if (pContext == nullptr) {
|
2022-08-23 07:47:06 +00:00
|
|
|
v4a_printf(ANDROID_LOG_ERROR, "ViperEffectRelease(), Error [pContext = NULL]");
|
2022-08-23 00:26:44 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2022-08-23 00:17:32 +02:00
|
|
|
|
2022-08-23 07:47:06 +00:00
|
|
|
v4a_print(ANDROID_LOG_INFO, "ViperEffectRelease(), Deconstructing ProcessUnit");
|
2021-07-27 19:00:39 +02:00
|
|
|
|
2022-08-23 00:26:44 +02:00
|
|
|
if (pContext->effect != nullptr) {
|
|
|
|
delete pContext->effect;
|
|
|
|
pContext->effect = nullptr;
|
2021-07-27 09:47:15 +02:00
|
|
|
}
|
2022-08-23 00:26:44 +02:00
|
|
|
delete pContext;
|
2021-07-27 09:47:15 +02:00
|
|
|
|
2022-08-23 00:26:44 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2022-08-23 00:17:32 +02:00
|
|
|
|
2022-08-23 07:47:06 +00:00
|
|
|
int32_t ViperEffectGetDescriptor(const effect_uuid_t *uuid, effect_descriptor_t *pDescriptor) {
|
|
|
|
v4a_print(ANDROID_LOG_INFO, "Enter ViperEffectGetDescriptor()");
|
2022-08-23 00:17:32 +02:00
|
|
|
|
2022-08-23 00:26:44 +02:00
|
|
|
if (uuid == nullptr) {
|
2022-08-23 07:47:06 +00:00
|
|
|
v4a_printf(ANDROID_LOG_ERROR, "ViperEffectGetDescriptor(), Error [uuid = NULL]");
|
2022-08-23 00:26:44 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2022-08-23 00:17:32 +02:00
|
|
|
|
2022-08-23 00:26:44 +02:00
|
|
|
if (pDescriptor == nullptr) {
|
2022-08-23 07:47:06 +00:00
|
|
|
v4a_printf(ANDROID_LOG_ERROR, "ViperEffectGetDescriptor(), Error [pDescriptor = NULL]");
|
2022-08-23 00:26:44 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2021-07-27 19:00:39 +02:00
|
|
|
|
2022-08-23 00:26:44 +02:00
|
|
|
if (memcmp(uuid, &viper_descriptor.uuid, sizeof(effect_uuid_t)) != 0) {
|
2022-08-23 07:47:06 +00:00
|
|
|
v4a_print(ANDROID_LOG_ERROR, "ViperEffectGetDescriptor(), Error [effect not found]");
|
2022-08-23 00:26:44 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2021-07-27 19:00:39 +02:00
|
|
|
|
2022-08-23 07:47:06 +00:00
|
|
|
v4a_printf(ANDROID_LOG_INFO, "ViperEffectGetDescriptor(), uuid = %08x-%04x-%04x-%04x-%02x%02x%02x%02x%02x%02x",
|
2022-08-23 00:26:44 +02:00
|
|
|
uuid->timeLow, uuid->timeMid, uuid->timeHiAndVersion, uuid->clockSeq, uuid->node[0], uuid->node[1],
|
|
|
|
uuid->node[2], uuid->node[3], uuid->node[4], uuid->node[5]);
|
2021-07-27 09:47:15 +02:00
|
|
|
|
2022-08-23 00:26:44 +02:00
|
|
|
*pDescriptor = viper_descriptor;
|
2021-07-27 09:47:15 +02:00
|
|
|
|
2022-08-23 00:26:44 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
audio_effect_library_t AUDIO_EFFECT_LIBRARY_INFO_SYM = {
|
2021-07-29 17:00:39 +02:00
|
|
|
.tag = AUDIO_EFFECT_LIBRARY_TAG,
|
2022-08-23 00:17:32 +02:00
|
|
|
.version = EFFECT_LIBRARY_API_VERSION,
|
2022-08-23 07:47:06 +00:00
|
|
|
.name = EFFECT_NAME,
|
|
|
|
.implementor = EFFECT_IMPLEMENTOR,
|
|
|
|
.create_effect = ViperEffectCreate,
|
|
|
|
.release_effect = ViperEffectRelease,
|
|
|
|
.get_descriptor = ViperEffectGetDescriptor,
|
2022-08-23 00:26:44 +02:00
|
|
|
};
|
2021-07-27 09:47:15 +02:00
|
|
|
}
|