ViPER: Start implementing command function

This commit is contained in:
Iscle 2022-08-28 20:31:15 +02:00
parent 574ae5d1e7
commit 11fbdcb7fb
3 changed files with 143 additions and 7 deletions

View File

@ -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;
}

View File

@ -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
};

View File

@ -2,6 +2,7 @@
// Created by mart on 7/25/21.
//
#include <ctime>
#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) {