2022-08-28 19:02:27 +02:00
|
|
|
#include <cstring>
|
2022-09-27 03:48:49 +02:00
|
|
|
#include <ctime>
|
2023-01-06 03:24:08 +01:00
|
|
|
#include <cstdlib>
|
2022-08-28 19:02:27 +02:00
|
|
|
#include "viper/ViPER.h"
|
2022-09-27 03:48:49 +02:00
|
|
|
#include "essential.h"
|
2022-08-28 19:02:27 +02:00
|
|
|
#include "viper/constants.h"
|
2023-05-15 02:15:46 +02:00
|
|
|
#include "ViperContext.h"
|
2022-08-28 19:02:27 +02:00
|
|
|
|
2023-05-15 02:15:46 +02:00
|
|
|
struct ViperHandle {
|
|
|
|
const struct effect_interface_s *iface; // Always keep as first member
|
|
|
|
struct ViperContext *context;
|
|
|
|
};
|
2022-08-28 19:02:27 +02:00
|
|
|
|
2023-05-15 02:15:46 +02:00
|
|
|
static const effect_descriptor_t viperDescriptor = {
|
2023-01-26 00:19:45 +01:00
|
|
|
.type = *EFFECT_UUID_NULL,
|
2023-01-06 03:24:08 +01:00
|
|
|
.uuid = {0x90380da3, 0x8536, 0x4744, 0xa6a3, {0x57, 0x31, 0x97, 0x0e, 0x64, 0x0f}},
|
2022-08-28 19:02:27 +02:00
|
|
|
.apiVersion = EFFECT_CONTROL_API_VERSION,
|
2023-05-15 02:15:46 +02:00
|
|
|
.flags = EFFECT_FLAG_OUTPUT_DIRECT | EFFECT_FLAG_INPUT_DIRECT | EFFECT_FLAG_INSERT_LAST |
|
|
|
|
EFFECT_FLAG_TYPE_INSERT,
|
2022-08-28 19:02:27 +02:00
|
|
|
.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
|
2023-05-15 02:15:46 +02:00
|
|
|
.name = VIPER_NAME,
|
2022-08-28 19:02:27 +02:00
|
|
|
.implementor = VIPER_AUTHORS
|
|
|
|
};
|
|
|
|
|
2023-05-15 02:15:46 +02:00
|
|
|
static int32_t viperInterfaceProcess(effect_handle_t self, audio_buffer_t *inBuffer, audio_buffer_t *outBuffer) {
|
|
|
|
auto viperHandle = reinterpret_cast<ViperHandle *>(self);
|
|
|
|
if (viperHandle == nullptr) return -EINVAL;
|
2023-01-06 03:24:08 +01:00
|
|
|
|
2023-05-15 02:15:46 +02:00
|
|
|
return viperHandle->context->process(inBuffer, outBuffer);
|
2022-09-27 03:48:49 +02:00
|
|
|
}
|
|
|
|
|
2023-05-15 02:15:46 +02:00
|
|
|
static int32_t viperInterfaceCommand(effect_handle_t self,
|
2023-01-26 00:19:45 +01:00
|
|
|
uint32_t cmdCode, uint32_t cmdSize, void *pCmdData,
|
|
|
|
uint32_t *replySize, void *pReplyData) {
|
2023-05-15 02:15:46 +02:00
|
|
|
auto viperHandle = reinterpret_cast<ViperHandle *>(self);
|
|
|
|
if (viperHandle == nullptr) return -EINVAL;
|
|
|
|
|
|
|
|
return viperHandle->context->handleCommand(cmdCode, cmdSize, pCmdData, replySize, pReplyData);
|
2022-08-28 19:02:27 +02:00
|
|
|
}
|
|
|
|
|
2023-05-15 02:15:46 +02:00
|
|
|
static int32_t viperInterfaceGetDescriptor(effect_handle_t self, effect_descriptor_t *pDescriptor) {
|
|
|
|
if (pDescriptor == nullptr) return -EINVAL;
|
2023-01-26 00:19:45 +01:00
|
|
|
*pDescriptor = viperDescriptor;
|
2022-08-28 19:02:27 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const effect_interface_s viper_interface = {
|
2023-05-15 02:15:46 +02:00
|
|
|
.process = viperInterfaceProcess,
|
|
|
|
.command = viperInterfaceCommand,
|
|
|
|
.get_descriptor = viperInterfaceGetDescriptor
|
2022-08-28 19:02:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static int32_t
|
2023-05-15 02:15:46 +02:00
|
|
|
viperLibraryCreate(const effect_uuid_t *uuid, int32_t sessionId __unused, int32_t ioId __unused, effect_handle_t *pHandle) {
|
2023-01-26 00:19:45 +01:00
|
|
|
if (uuid == nullptr || pHandle == nullptr) return -EINVAL;
|
|
|
|
if (memcmp(uuid, &viperDescriptor.uuid, sizeof(effect_uuid_t)) != 0) return -ENOENT;
|
2022-08-28 19:02:27 +02:00
|
|
|
|
2023-05-15 02:15:46 +02:00
|
|
|
auto viperHandle = new ViperHandle();
|
|
|
|
viperHandle->iface = &viper_interface;
|
|
|
|
viperHandle->context = new ViperContext();
|
|
|
|
*pHandle = reinterpret_cast<effect_handle_t>(viperHandle);
|
2022-08-28 19:02:27 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-05-15 02:15:46 +02:00
|
|
|
static int32_t viperLibraryRelease(effect_handle_t handle) {
|
|
|
|
auto viperHandle = reinterpret_cast<ViperHandle *>(handle);
|
|
|
|
if (viperHandle == nullptr) return -EINVAL;
|
2022-08-28 19:02:27 +02:00
|
|
|
|
2023-05-15 02:15:46 +02:00
|
|
|
delete viperHandle->context;
|
2022-08-28 19:02:27 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-05-15 02:15:46 +02:00
|
|
|
static int32_t viperLibraryGetDescriptor(const effect_uuid_t *uuid, effect_descriptor_t *pDescriptor) {
|
2023-01-26 00:19:45 +01:00
|
|
|
if (uuid == nullptr || pDescriptor == nullptr) return -EINVAL;
|
|
|
|
if (memcmp(uuid, &viperDescriptor.uuid, sizeof(effect_uuid_t)) != 0) return -ENOENT;
|
2022-08-28 19:02:27 +02:00
|
|
|
|
2023-01-26 00:19:45 +01:00
|
|
|
*pDescriptor = viperDescriptor;
|
2022-08-28 19:02:27 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-05-15 02:15:46 +02:00
|
|
|
extern "C" __attribute__ ((visibility ("default")))
|
|
|
|
const audio_effect_library_t AUDIO_EFFECT_LIBRARY_INFO_SYM = {
|
2022-08-28 19:02:27 +02:00
|
|
|
.tag = AUDIO_EFFECT_LIBRARY_TAG,
|
|
|
|
.version = EFFECT_LIBRARY_API_VERSION,
|
2023-05-15 02:15:46 +02:00
|
|
|
.name = VIPER_NAME,
|
2022-08-28 19:02:27 +02:00
|
|
|
.implementor = VIPER_AUTHORS,
|
2023-05-15 02:15:46 +02:00
|
|
|
.create_effect = viperLibraryCreate,
|
|
|
|
.release_effect = viperLibraryRelease,
|
|
|
|
.get_descriptor = viperLibraryGetDescriptor,
|
2022-08-28 19:02:27 +02:00
|
|
|
};
|