From 11fbdcb7fbbed3328dc7f1d932443dc65390098e Mon Sep 17 00:00:00 2001 From: Iscle Date: Sun, 28 Aug 2022 20:31:15 +0200 Subject: [PATCH] ViPER: Start implementing command function --- src/cpp/ViPER4Android.cpp | 8 +-- src/cpp/ViPER4Android.h | 9 ++- src/cpp/viper/ViPER.cpp | 133 +++++++++++++++++++++++++++++++++++++- 3 files changed, 143 insertions(+), 7 deletions(-) diff --git a/src/cpp/ViPER4Android.cpp b/src/cpp/ViPER4Android.cpp index 4c8c094..45af8cd 100644 --- a/src/cpp/ViPER4Android.cpp +++ b/src/cpp/ViPER4Android.cpp @@ -28,8 +28,8 @@ struct ViperContext { static int32_t Viper_IProcess(effect_handle_t self, audio_buffer_t *inBuffer, audio_buffer_t *outBuffer) { auto pContext = (ViperContext *) self; - if (pContext == nullptr || inBuffer == nullptr || outBuffer == nullptr) { - VIPER_LOGE("Viper_IProcess: pContext, inBuffer or outBuffer is null!"); + if (pContext == nullptr || pContext->viper == nullptr || inBuffer == nullptr || outBuffer == nullptr) { + VIPER_LOGE("Viper_IProcess: pContext, pContext->viper, inBuffer or outBuffer is null!"); return -EINVAL; } @@ -41,8 +41,8 @@ static int32_t Viper_ICommand(effect_handle_t self, uint32_t *replySize, void *pReplyData) { auto pContext = (ViperContext *) self; - if (pContext == nullptr) { - VIPER_LOGE("Viper_ICommand: pContext is null!"); + if (pContext == nullptr || pContext->viper == nullptr) { + VIPER_LOGE("Viper_ICommand: pContext or pContext->viper is null!"); return -EINVAL; } diff --git a/src/cpp/ViPER4Android.h b/src/cpp/ViPER4Android.h index 8cba96b..b1a46d5 100644 --- a/src/cpp/ViPER4Android.h +++ b/src/cpp/ViPER4Android.h @@ -5,6 +5,7 @@ #pragma once // Source: https://github.com/vipersaudio/viperfx_core_binary/blob/master/viperfx_intf.h +// Updated parameters source: https://github.com/vipersaudio/viper4android_fx/blob/master/android_4.x/src/com/vipercn/viper4android_v2/service/ViPER4AndroidService.java extern "C" { enum ParamsMode { @@ -17,18 +18,24 @@ enum ParamsGet { PARAM_GET_DRIVER_VERSION, PARAM_GET_NEONENABLED, PARAM_GET_ENABLED, + PARAM_GET_CONFIGURE, PARAM_GET_DRVCANWORK, + PARAM_GET_STREAMING, PARAM_GET_EFFECT_TYPE, PARAM_GET_SAMPLINGRATE, + PARAM_GET_CONVUSABLE, PARAM_GET_CONVKNLID, PARAM_GET_STATUS_END }; enum ParamsSet { PARAM_SET_STATUS_BEGIN = 0x09000, + PARAM_SET_UNKNOWN, + PARAM_SET_UPDATE_STATUS, PARAM_SET_RESET_STATUS, - PARAM_SET_SAMPLINGRATE, PARAM_SET_DOPROCESS_STATUS, + PARAM_SET_FORCEENABLE_STATUS, + PARAM_SET_SELFDIAGNOSE_STATUS, PARAM_SET_STATUS_END }; diff --git a/src/cpp/viper/ViPER.cpp b/src/cpp/viper/ViPER.cpp index e909247..0de5cf6 100644 --- a/src/cpp/viper/ViPER.cpp +++ b/src/cpp/viper/ViPER.cpp @@ -2,6 +2,7 @@ // Created by mart on 7/25/21. // +#include #include "ViPER.h" #include "Effect.h" #include "constants.h" @@ -179,8 +180,136 @@ ViPER::~ViPER() { int32_t ViPER::command(uint32_t cmdCode, uint32_t cmdSize, void *pCmdData, uint32_t *replySize, void *pReplyData) { - // TODO - return -1; + switch (cmdCode) { + case EFFECT_CMD_ENABLE: { + if (!this->enabled) { + ResetAllEffects(); + break; + } + return 0; + } + case EFFECT_CMD_RESET: { + ResetAllEffects(); + break; + } + case EFFECT_CMD_SET_CONFIG: { + if (cmdSize != 64 || *replySize != 4) { + return -EINVAL; + } + + auto currentSampleRate = this->sampleRate; + + *(int32_t *) pReplyData = this->configure((effect_config_t *) pCmdData); + if (*(int32_t *) pReplyData == 0) { + if (currentSampleRate != this->sampleRate) { + ResetAllEffects(); + } + } + + return 0; + } + case EFFECT_CMD_SET_PARAM: { + auto pCmdParam = (effect_param_t *) pCmdData; + + if (pCmdParam->psize != sizeof(int32_t)) { + *(int32_t *) pReplyData = -EINVAL; + return 0; + } + + // TODO: implement + } + case EFFECT_CMD_GET_PARAM: { + auto *pCmdParam = (effect_param_t *) pCmdData; + auto *pReplyParam = (effect_param_t *) pReplyData; + + if (pCmdParam->psize != sizeof(int32_t)) break; + + switch (*(int *) pCmdParam->data) { + case PARAM_GET_DRIVER_VERSION: { + pReplyParam->status = 0; + //pReplyParam->psize = sizeof(int32_t); // TODO + pReplyParam->vsize = sizeof(int32_t); + *(int32_t *) pReplyParam->data = 0x2050004; // As original, change as needed + *replySize = 0x14; // As original, TODO: calculate correctly + return 0; + } + case PARAM_GET_NEONENABLED: { + pReplyParam->status = 0; + //pReplyParam->psize = sizeof(int32_t); // TODO + pReplyParam->vsize = sizeof(int32_t); + *(int32_t *) pReplyParam->data = 1; // TODO: check if neon is enabled + *replySize = 0x14; // As original, TODO: calculate correctly + return 0; + } + case PARAM_GET_ENABLED: { + pReplyParam->status = 0; + //pReplyParam->psize = sizeof(int32_t); // TODO + pReplyParam->vsize = sizeof(int32_t); + *(int32_t *) pReplyParam->data = this->enabled; + *replySize = 0x14; // As original, TODO: calculate correctly + return 0; + } + case PARAM_GET_CONFIGURE: { + pReplyParam->status = 0; + //pReplyParam->psize = sizeof(int32_t); // TODO + pReplyParam->vsize = sizeof(int32_t); + *(int32_t *) pReplyParam->data = this->configureOk; + *replySize = 0x14; // As original, TODO: calculate correctly + return 0; + } + case PARAM_GET_DRVCANWORK: { + pReplyParam->status = 0; + //pReplyParam->psize = sizeof(int32_t); // TODO + pReplyParam->vsize = sizeof(int32_t); + *(int32_t *) pReplyParam->data = this->init_ok; + *replySize = 0x14; // As original, TODO: calculate correctly + return 0; + } + case PARAM_GET_STREAMING: { + struct timeval time{}; + gettimeofday(&time, nullptr); + + // TODO: Do some calculations + + return 0; + } + case PARAM_GET_EFFECT_TYPE: { + pReplyParam->status = 0; + //pReplyParam->psize = sizeof(int32_t); // TODO + pReplyParam->vsize = sizeof(int32_t); + *(int32_t *) pReplyParam->data = this->mode; + *replySize = 0x14; // As original, TODO: calculate correctly + return 0; + } + case PARAM_GET_SAMPLINGRATE: { + pReplyParam->status = 0; + //pReplyParam->psize = sizeof(int32_t); // TODO + pReplyParam->vsize = sizeof(int32_t); + *(uint32_t *) pReplyParam->data = this->sampleRate; + *replySize = 0x14; // As original, TODO: calculate correctly + return 0; + } + case PARAM_GET_CONVUSABLE: { + pReplyParam->status = 0; + //pReplyParam->psize = sizeof(int32_t); // TODO + pReplyParam->vsize = sizeof(int32_t); + *(int32_t *) pReplyParam->data = 1; // TODO: Figure out what is this + *replySize = 0x14; // As original, TODO: calculate correctly + return 0; + } + case PARAM_GET_CONVKNLID: { + pReplyParam->status = 0; + //pReplyParam->psize = sizeof(int32_t); // TODO + pReplyParam->vsize = sizeof(int32_t); +// *(int32_t *) pReplyParam->data = this->convolver->GetKernelID(); // TODO: Uncomment when function is implemented + *replySize = 0x14; // As original, TODO: calculate correctly + return 0; + } + } + } + } + + return this->Effect::command(cmdCode, cmdSize, pCmdData, replySize, pReplyData); } void ViPER::processBuffer(float *buffer, int frameSize) {