mirror of
https://github.com/AndroidAudioMods/ViPERFX_RE.git
synced 2024-12-22 22:47:25 +08:00
Improved implementation
This commit is contained in:
parent
2e9a84134b
commit
2c4e153120
@ -8,8 +8,9 @@
|
|||||||
|
|
||||||
#define VIPER_EFFECT_NAME "ViPER4Android"
|
#define VIPER_EFFECT_NAME "ViPER4Android"
|
||||||
|
|
||||||
static effect_descriptor_t viper_descriptor = {
|
extern "C" {
|
||||||
.type = EFFECT_UUID_INITIALIZER,
|
static effect_descriptor_t viperDescriptor = {
|
||||||
|
.type = *EFFECT_UUID_NULL,
|
||||||
.uuid = {0x90380da3, 0x8536, 0x4744, 0xa6a3, {0x57, 0x31, 0x97, 0x0e, 0x64, 0x0f}},
|
.uuid = {0x90380da3, 0x8536, 0x4744, 0xa6a3, {0x57, 0x31, 0x97, 0x0e, 0x64, 0x0f}},
|
||||||
.apiVersion = EFFECT_CONTROL_API_VERSION,
|
.apiVersion = EFFECT_CONTROL_API_VERSION,
|
||||||
.flags = EFFECT_FLAG_OUTPUT_DIRECT | EFFECT_FLAG_INPUT_DIRECT | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_TYPE_INSERT,
|
.flags = EFFECT_FLAG_OUTPUT_DIRECT | EFFECT_FLAG_INPUT_DIRECT | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_TYPE_INSERT,
|
||||||
@ -19,11 +20,20 @@ static effect_descriptor_t viper_descriptor = {
|
|||||||
.implementor = VIPER_AUTHORS
|
.implementor = VIPER_AUTHORS
|
||||||
};
|
};
|
||||||
|
|
||||||
extern "C" {
|
struct ViPERContext {
|
||||||
struct ViperContext {
|
// Interface, MUST be the first member of the structure
|
||||||
const struct effect_interface_s *interface; // Should always be the first struct member
|
const struct effect_interface_s *interface;
|
||||||
|
|
||||||
|
// Config
|
||||||
effect_config_t config;
|
effect_config_t config;
|
||||||
bool isConfigValid;
|
bool isConfigValid;
|
||||||
|
|
||||||
|
// Processing buffer
|
||||||
|
float *buffer;
|
||||||
|
size_t bufferFrameCount;
|
||||||
|
|
||||||
|
// Viper
|
||||||
|
bool enabled;
|
||||||
ViPER *viper;
|
ViPER *viper;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -73,19 +83,38 @@ static void floatToPcm32(int32_t *dst, const float *src, size_t frameCount, bool
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t Viper_IProcess(effect_handle_t self, audio_buffer_t *inBuffer, audio_buffer_t *outBuffer) {
|
static audio_buffer_t *getBuffer(buffer_config_s *config, audio_buffer_t *buffer) {
|
||||||
auto pContext = reinterpret_cast<ViperContext *>(self);
|
if (buffer != nullptr) return buffer;
|
||||||
|
return &config->buffer;
|
||||||
|
}
|
||||||
|
|
||||||
if (pContext == nullptr ||
|
static int32_t ViPERInterfaceProcess(effect_handle_t self, audio_buffer_t *inBuffer, audio_buffer_t *outBuffer) {
|
||||||
inBuffer == nullptr || outBuffer == nullptr ||
|
auto pContext = reinterpret_cast<ViPERContext *>(self);
|
||||||
|
|
||||||
|
if (pContext == nullptr || !pContext->isConfigValid) {
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pContext->enabled) {
|
||||||
|
return -ENODATA;
|
||||||
|
}
|
||||||
|
|
||||||
|
inBuffer = getBuffer(&pContext->config.inputCfg, inBuffer);
|
||||||
|
outBuffer = getBuffer(&pContext->config.outputCfg, outBuffer);
|
||||||
|
if (inBuffer == nullptr || outBuffer == nullptr ||
|
||||||
inBuffer->raw == nullptr || outBuffer->raw == nullptr ||
|
inBuffer->raw == nullptr || outBuffer->raw == nullptr ||
|
||||||
inBuffer->frameCount != outBuffer->frameCount ||
|
inBuffer->frameCount != outBuffer->frameCount ||
|
||||||
inBuffer->frameCount == 0) {
|
inBuffer->frameCount == 0) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
float *buffer = new float[outBuffer->frameCount * 2];
|
size_t frameCount = inBuffer->frameCount;
|
||||||
size_t frameCount = outBuffer->frameCount;
|
if (frameCount > pContext->bufferFrameCount) {
|
||||||
|
delete[] pContext->buffer;
|
||||||
|
pContext->buffer = new float[frameCount * 2];
|
||||||
|
pContext->bufferFrameCount = frameCount;
|
||||||
|
}
|
||||||
|
float *buffer = pContext->buffer;
|
||||||
|
|
||||||
switch (pContext->config.inputCfg.format) {
|
switch (pContext->config.inputCfg.format) {
|
||||||
case AUDIO_FORMAT_PCM_16_BIT:
|
case AUDIO_FORMAT_PCM_16_BIT:
|
||||||
@ -98,7 +127,6 @@ static int32_t Viper_IProcess(effect_handle_t self, audio_buffer_t *inBuffer, au
|
|||||||
floatToFloat(buffer, inBuffer->f32, frameCount, false);
|
floatToFloat(buffer, inBuffer->f32, frameCount, false);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
delete[] buffer;
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,59 +136,69 @@ static int32_t Viper_IProcess(effect_handle_t self, audio_buffer_t *inBuffer, au
|
|||||||
switch (pContext->config.outputCfg.format) {
|
switch (pContext->config.outputCfg.format) {
|
||||||
case AUDIO_FORMAT_PCM_16_BIT:
|
case AUDIO_FORMAT_PCM_16_BIT:
|
||||||
floatToPcm16(outBuffer->s16, buffer, frameCount, accumulate);
|
floatToPcm16(outBuffer->s16, buffer, frameCount, accumulate);
|
||||||
delete[] buffer;
|
|
||||||
break;
|
break;
|
||||||
case AUDIO_FORMAT_PCM_32_BIT:
|
case AUDIO_FORMAT_PCM_32_BIT:
|
||||||
floatToPcm32(outBuffer->s32, buffer, frameCount, accumulate);
|
floatToPcm32(outBuffer->s32, buffer, frameCount, accumulate);
|
||||||
delete[] buffer;
|
|
||||||
break;
|
break;
|
||||||
case AUDIO_FORMAT_PCM_FLOAT:
|
case AUDIO_FORMAT_PCM_FLOAT:
|
||||||
floatToFloat(outBuffer->f32, buffer, frameCount, accumulate);
|
floatToFloat(outBuffer->f32, buffer, frameCount, accumulate);
|
||||||
delete[] buffer;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
delete[] buffer;
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int handleSetConfig(ViperContext *pContext, effect_config_t *newConfig) {
|
static int handleSetConfig(ViPERContext *pContext, effect_config_t *newConfig) {
|
||||||
VIPER_LOGD("Begin handleSetConfig ...");
|
|
||||||
VIPER_LOGI("Checking input and output configuration ...");
|
VIPER_LOGI("Checking input and output configuration ...");
|
||||||
|
|
||||||
|
VIPER_LOGI("Input buffer frame count: %d", newConfig->inputCfg.buffer.frameCount);
|
||||||
VIPER_LOGI("Input sampling rate: %d", newConfig->inputCfg.samplingRate);
|
VIPER_LOGI("Input sampling rate: %d", newConfig->inputCfg.samplingRate);
|
||||||
VIPER_LOGI("Input channels: %d", newConfig->inputCfg.channels);
|
VIPER_LOGI("Input channels: %d", newConfig->inputCfg.channels);
|
||||||
VIPER_LOGI("Input format: %d", newConfig->inputCfg.format);
|
VIPER_LOGI("Input format: %d", newConfig->inputCfg.format);
|
||||||
VIPER_LOGI("Input access mode: %d", newConfig->inputCfg.accessMode);
|
VIPER_LOGI("Input access mode: %d", newConfig->inputCfg.accessMode);
|
||||||
|
VIPER_LOGI("Output buffer frame count: %d", newConfig->outputCfg.buffer.frameCount);
|
||||||
VIPER_LOGI("Output sampling rate: %d", newConfig->outputCfg.samplingRate);
|
VIPER_LOGI("Output sampling rate: %d", newConfig->outputCfg.samplingRate);
|
||||||
VIPER_LOGI("Output channels: %d", newConfig->outputCfg.channels);
|
VIPER_LOGI("Output channels: %d", newConfig->outputCfg.channels);
|
||||||
VIPER_LOGI("Output format: %d", newConfig->outputCfg.format);
|
VIPER_LOGI("Output format: %d", newConfig->outputCfg.format);
|
||||||
VIPER_LOGI("Output access mode: %d", newConfig->outputCfg.accessMode);
|
VIPER_LOGI("Output access mode: %d", newConfig->outputCfg.accessMode);
|
||||||
|
|
||||||
pContext->isConfigValid = false;
|
pContext->isConfigValid = false;
|
||||||
|
delete[] pContext->buffer;
|
||||||
|
pContext->buffer = nullptr;
|
||||||
|
|
||||||
|
if (newConfig->inputCfg.buffer.frameCount != newConfig->outputCfg.buffer.frameCount) {
|
||||||
|
VIPER_LOGE("ViPER4Android disabled, reason [in.FC = %d, out.FC = %d]",
|
||||||
|
newConfig->inputCfg.buffer.frameCount, newConfig->outputCfg.buffer.frameCount);
|
||||||
|
// pContext->disableReason = "Invalid frame count";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (newConfig->inputCfg.samplingRate != newConfig->outputCfg.samplingRate) {
|
if (newConfig->inputCfg.samplingRate != newConfig->outputCfg.samplingRate) {
|
||||||
VIPER_LOGE("ViPER4Android disabled, reason [in.SR = %d, out.SR = %d]",
|
VIPER_LOGE("ViPER4Android disabled, reason [in.SR = %d, out.SR = %d]",
|
||||||
newConfig->inputCfg.samplingRate, newConfig->outputCfg.samplingRate);
|
newConfig->inputCfg.samplingRate, newConfig->outputCfg.samplingRate);
|
||||||
return -EINVAL;
|
// pContext->disableReason = "Invalid sampling rate";
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newConfig->inputCfg.samplingRate > 48000) {
|
if (newConfig->inputCfg.samplingRate > 48000) {
|
||||||
VIPER_LOGE("ViPER4Android disabled, reason [SR out of range]");
|
VIPER_LOGE("ViPER4Android disabled, reason [SR out of range]");
|
||||||
return -EINVAL;
|
// pContext->disableReason = "Sampling rate out of range";
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newConfig->inputCfg.channels != newConfig->outputCfg.channels) {
|
if (newConfig->inputCfg.channels != newConfig->outputCfg.channels) {
|
||||||
VIPER_LOGE("ViPER4Android disabled, reason [in.CH = %d, out.CH = %d]",
|
VIPER_LOGE("ViPER4Android disabled, reason [in.CH = %d, out.CH = %d]",
|
||||||
newConfig->inputCfg.channels, newConfig->outputCfg.channels);
|
newConfig->inputCfg.channels, newConfig->outputCfg.channels);
|
||||||
return -EINVAL;
|
// pContext->disableReason = "Invalid channel count";
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newConfig->inputCfg.channels != AUDIO_CHANNEL_OUT_STEREO) {
|
if (newConfig->inputCfg.channels != AUDIO_CHANNEL_OUT_STEREO) {
|
||||||
VIPER_LOGE("ViPER4Android disabled, reason [CH != 2]");
|
VIPER_LOGE("ViPER4Android disabled, reason [CH != 2]");
|
||||||
return -EINVAL;
|
// pContext->disableReason = "Channel count != 2";
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newConfig->inputCfg.format != AUDIO_FORMAT_PCM_16_BIT &&
|
if (newConfig->inputCfg.format != AUDIO_FORMAT_PCM_16_BIT &&
|
||||||
@ -168,7 +206,8 @@ static int handleSetConfig(ViperContext *pContext, effect_config_t *newConfig) {
|
|||||||
newConfig->inputCfg.format != AUDIO_FORMAT_PCM_FLOAT) {
|
newConfig->inputCfg.format != AUDIO_FORMAT_PCM_FLOAT) {
|
||||||
VIPER_LOGE("ViPER4Android disabled, reason [in.FMT = %d]", newConfig->inputCfg.format);
|
VIPER_LOGE("ViPER4Android disabled, reason [in.FMT = %d]", newConfig->inputCfg.format);
|
||||||
VIPER_LOGE("We only accept AUDIO_FORMAT_PCM_16_BIT, AUDIO_FORMAT_PCM_32_BIT and AUDIO_FORMAT_PCM_FLOAT input format!");
|
VIPER_LOGE("We only accept AUDIO_FORMAT_PCM_16_BIT, AUDIO_FORMAT_PCM_32_BIT and AUDIO_FORMAT_PCM_FLOAT input format!");
|
||||||
return -EINVAL;
|
// pContext->disableReason = "Invalid input format";
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newConfig->outputCfg.format != AUDIO_FORMAT_PCM_16_BIT &&
|
if (newConfig->outputCfg.format != AUDIO_FORMAT_PCM_16_BIT &&
|
||||||
@ -176,22 +215,27 @@ static int handleSetConfig(ViperContext *pContext, effect_config_t *newConfig) {
|
|||||||
newConfig->outputCfg.format != AUDIO_FORMAT_PCM_FLOAT) {
|
newConfig->outputCfg.format != AUDIO_FORMAT_PCM_FLOAT) {
|
||||||
VIPER_LOGE("ViPER4Android disabled, reason [out.FMT = %d]", newConfig->outputCfg.format);
|
VIPER_LOGE("ViPER4Android disabled, reason [out.FMT = %d]", newConfig->outputCfg.format);
|
||||||
VIPER_LOGE("We only accept AUDIO_FORMAT_PCM_16_BIT, AUDIO_FORMAT_PCM_32_BIT and AUDIO_FORMAT_PCM_FLOAT output format!");
|
VIPER_LOGE("We only accept AUDIO_FORMAT_PCM_16_BIT, AUDIO_FORMAT_PCM_32_BIT and AUDIO_FORMAT_PCM_FLOAT output format!");
|
||||||
return -EINVAL;
|
// pContext->disableReason = "Invalid output format";
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
VIPER_LOGI("Input and output configuration checked.");
|
VIPER_LOGI("Input and output configuration checked.");
|
||||||
|
|
||||||
|
// Config
|
||||||
pContext->config = *newConfig;
|
pContext->config = *newConfig;
|
||||||
|
pContext->isConfigValid = true;
|
||||||
|
// pContext->disableReason = "";
|
||||||
|
// Processing buffer
|
||||||
|
pContext->buffer = new float[newConfig->inputCfg.buffer.frameCount * 2];
|
||||||
|
pContext->bufferFrameCount = newConfig->inputCfg.buffer.frameCount;
|
||||||
|
// ViPER
|
||||||
pContext->viper->samplingRate = newConfig->inputCfg.samplingRate;
|
pContext->viper->samplingRate = newConfig->inputCfg.samplingRate;
|
||||||
pContext->viper->ResetAllEffects();
|
pContext->viper->ResetAllEffects();
|
||||||
pContext->isConfigValid = true;
|
|
||||||
|
|
||||||
VIPER_LOGD("Audio handleSetConfig finished");
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t handleSetParam(ViperContext *pContext, effect_param_t *pCmdParam, void *pReplyData) {
|
static int32_t handleSetParam(ViPERContext *pContext, effect_param_t *pCmdParam, void *pReplyData) {
|
||||||
// The value offset of an effect parameter is computed by rounding up
|
// The value offset of an effect parameter is computed by rounding up
|
||||||
// the parameter size to the next 32 bit alignment.
|
// the parameter size to the next 32 bit alignment.
|
||||||
uint32_t vOffset = ((pCmdParam->psize + sizeof(int32_t) - 1) / sizeof(int32_t)) * sizeof(int32_t);
|
uint32_t vOffset = ((pCmdParam->psize + sizeof(int32_t) - 1) / sizeof(int32_t)) * sizeof(int32_t);
|
||||||
@ -200,40 +244,49 @@ static int32_t handleSetParam(ViperContext *pContext, effect_param_t *pCmdParam,
|
|||||||
|
|
||||||
int param = *(int *) (pCmdParam->data);
|
int param = *(int *) (pCmdParam->data);
|
||||||
int *intValues = (int *) (pCmdParam->data + vOffset);
|
int *intValues = (int *) (pCmdParam->data + vOffset);
|
||||||
if (pCmdParam->vsize == sizeof(int)) {
|
switch (pCmdParam->vsize) {
|
||||||
pContext->viper->DispatchCommand(param, intValues[0], 0, 0, 0, 0, nullptr);
|
case sizeof(int): {
|
||||||
return 0;
|
pContext->viper->DispatchCommand(param, intValues[0], 0, 0, 0, 0, nullptr);
|
||||||
} else if (pCmdParam->vsize == sizeof(int) * 2) {
|
return 0;
|
||||||
pContext->viper->DispatchCommand(param, intValues[0], intValues[1], 0, 0, 0, nullptr);
|
}
|
||||||
return 0;
|
case sizeof(int) * 2: {
|
||||||
} else if (pCmdParam->vsize == sizeof(int) * 3) {
|
pContext->viper->DispatchCommand(param, intValues[0], intValues[1], 0, 0, 0, nullptr);
|
||||||
pContext->viper->DispatchCommand(param, intValues[0], intValues[1], intValues[2], 0, 0, nullptr);
|
return 0;
|
||||||
return 0;
|
}
|
||||||
} else if (pCmdParam->vsize == sizeof(int) * 4) {
|
case sizeof(int) * 3: {
|
||||||
pContext->viper->DispatchCommand(param, intValues[0], intValues[1], intValues[2], intValues[3], 0, nullptr);
|
pContext->viper->DispatchCommand(param, intValues[0], intValues[1], intValues[2], 0, 0, nullptr);
|
||||||
return 0;
|
return 0;
|
||||||
} else if (pCmdParam->vsize == 256 || pCmdParam->vsize == 1024) {
|
}
|
||||||
uint32_t arrSize = *(uint32_t *) (pCmdParam->data + vOffset);
|
case sizeof(int) * 4: {
|
||||||
signed char *arr = (signed char *) (pCmdParam->data + vOffset + sizeof(uint32_t));
|
pContext->viper->DispatchCommand(param, intValues[0], intValues[1], intValues[2], intValues[3], 0, nullptr);
|
||||||
pContext->viper->DispatchCommand(param, 0, 0, 0, 0, arrSize, arr);
|
return 0;
|
||||||
return 0;
|
}
|
||||||
} else if (pCmdParam->vsize == 8192) {
|
case 256:
|
||||||
int value1 = *(int *) (pCmdParam->data + vOffset);
|
case 1024: {
|
||||||
uint32_t arrSize = *(uint32_t *) (pCmdParam->data + vOffset + sizeof(int));
|
uint32_t arrSize = *(uint32_t *) (pCmdParam->data + vOffset);
|
||||||
signed char *arr = (signed char *) (pCmdParam->data + vOffset + sizeof(int) + sizeof(uint32_t));
|
signed char *arr = (signed char *) (pCmdParam->data + vOffset + sizeof(uint32_t));
|
||||||
pContext->viper->DispatchCommand(param, value1, 0, 0, 0, arrSize, arr);
|
pContext->viper->DispatchCommand(param, 0, 0, 0, 0, arrSize, arr);
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
case 8192: {
|
||||||
|
int value1 = *(int *) (pCmdParam->data + vOffset);
|
||||||
|
uint32_t arrSize = *(uint32_t *) (pCmdParam->data + vOffset + sizeof(int));
|
||||||
|
signed char *arr = (signed char *) (pCmdParam->data + vOffset + sizeof(int) + sizeof(uint32_t));
|
||||||
|
pContext->viper->DispatchCommand(param, value1, 0, 0, 0, arrSize, arr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t handleGetParam(ViperContext *pContext, effect_param_t *pCmdParam, effect_param_t *pReplyParam, uint32_t *pReplySize) {
|
static int32_t handleGetParam(ViPERContext *pContext, effect_param_t *pCmdParam, effect_param_t *pReplyParam, uint32_t *pReplySize) {
|
||||||
// The value offset of an effect parameter is computed by rounding up
|
// The value offset of an effect parameter is computed by rounding up
|
||||||
// the parameter size to the next 32 bit alignment.
|
// the parameter size to the next 32 bit alignment.
|
||||||
uint32_t vOffset = ((pCmdParam->psize + sizeof(int32_t) - 1) / sizeof(int32_t)) * sizeof(int32_t);
|
uint32_t vOffset = ((pCmdParam->psize + sizeof(int32_t) - 1) / sizeof(int32_t)) * sizeof(int32_t);
|
||||||
|
|
||||||
VIPER_LOGD("Viper_ICommand() EFFECT_CMD_GET_PARAM called with data = %d, psize = %d, vsize = %d", *(uint32_t *) pCmdParam->data, pCmdParam->psize, pCmdParam->vsize);
|
VIPER_LOGD("ViPERInterfaceCommand() EFFECT_CMD_GET_PARAM called with data = %d, psize = %d, vsize = %d", *(uint32_t *) pCmdParam->data, pCmdParam->psize, pCmdParam->vsize);
|
||||||
|
|
||||||
memcpy(pReplyParam, pCmdParam, sizeof(effect_param_t) + pCmdParam->psize);
|
memcpy(pReplyParam, pCmdParam, sizeof(effect_param_t) + pCmdParam->psize);
|
||||||
|
|
||||||
@ -241,7 +294,7 @@ static int32_t handleGetParam(ViperContext *pContext, effect_param_t *pCmdParam,
|
|||||||
case PARAM_GET_ENABLED: {
|
case PARAM_GET_ENABLED: {
|
||||||
pReplyParam->status = 0;
|
pReplyParam->status = 0;
|
||||||
pReplyParam->vsize = sizeof(int32_t);
|
pReplyParam->vsize = sizeof(int32_t);
|
||||||
*(int32_t *) (pReplyParam->data + vOffset) = pContext->viper->enabled;
|
*(int32_t *) (pReplyParam->data + vOffset) = pContext->enabled;
|
||||||
*pReplySize = sizeof(effect_param_t) + pReplyParam->psize + vOffset + pReplyParam->vsize;
|
*pReplySize = sizeof(effect_param_t) + pReplyParam->psize + vOffset + pReplyParam->vsize;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -300,137 +353,149 @@ static int32_t handleGetParam(ViperContext *pContext, effect_param_t *pCmdParam,
|
|||||||
*pReplySize = sizeof(effect_param_t) + pReplyParam->psize + vOffset + pReplyParam->vsize;
|
*pReplySize = sizeof(effect_param_t) + pReplyParam->psize + vOffset + pReplyParam->vsize;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
default: {
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t Viper_ICommand(effect_handle_t self,
|
#define SET_INT32(ptr, value) (*(int32_t *) (ptr) = (value))
|
||||||
uint32_t cmdCode, uint32_t cmdSize, void *pCmdData,
|
#define GET_REPLY_SIZE(ptr) (ptr == nullptr ? 0 : *ptr)
|
||||||
uint32_t *replySize, void *pReplyData) {
|
|
||||||
VIPER_LOGD("Viper_ICommand(self = %p, cmdCode = %d, cmdSize = %d, pCmdData = %p, replySize = %p, pReplyData = %p)", self, cmdCode, cmdSize, pCmdData, replySize, pReplyData);
|
|
||||||
|
|
||||||
auto pContext = reinterpret_cast<ViperContext *>(self);
|
static int32_t ViPERInterfaceCommand(effect_handle_t self,
|
||||||
|
uint32_t cmdCode, uint32_t cmdSize, void *pCmdData,
|
||||||
if (pContext == nullptr || replySize == nullptr || pReplyData == nullptr) {
|
uint32_t *replySize, void *pReplyData) {
|
||||||
VIPER_LOGD("Viper_ICommand() called with null self or replySize or pReplyData");
|
auto context = reinterpret_cast<ViPERContext *>(self);
|
||||||
return -EINVAL;
|
if (context == nullptr) return -EINVAL;
|
||||||
}
|
|
||||||
|
|
||||||
switch (cmdCode) {
|
switch (cmdCode) {
|
||||||
case EFFECT_CMD_INIT:
|
case EFFECT_CMD_INIT: {
|
||||||
*((int *) pReplyData) = 0;
|
if (GET_REPLY_SIZE(replySize) != sizeof(int32_t) || pReplyData == nullptr) {
|
||||||
|
VIPER_LOGE("EFFECT_CMD_INIT called with invalid replySize = %d, pReplyData = %p, expected replySize = %d", GET_REPLY_SIZE(replySize), pReplyData, sizeof(int32_t));
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
SET_INT32(pReplyData, 0);
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
case EFFECT_CMD_SET_CONFIG: {
|
case EFFECT_CMD_SET_CONFIG: {
|
||||||
*(int *) pReplyData = handleSetConfig(pContext, (effect_config_t *) pCmdData);
|
if (cmdSize < sizeof(effect_config_t) || pCmdData == nullptr || GET_REPLY_SIZE(replySize) != sizeof(int32_t) || pReplyData == nullptr) {
|
||||||
|
VIPER_LOGE("EFFECT_CMD_SET_CONFIG called with invalid cmdSize = %d, pCmdData = %p, replySize = %d, pReplyData = %p, expected cmdSize = %d, replySize = %d", cmdSize, pCmdData, GET_REPLY_SIZE(replySize), pReplyData, sizeof(effect_config_t), sizeof(int32_t));
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
SET_INT32(pReplyData, handleSetConfig(context, (effect_config_t *) pCmdData));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case EFFECT_CMD_RESET: {
|
case EFFECT_CMD_RESET: {
|
||||||
pContext->viper->ResetAllEffects();
|
if (GET_REPLY_SIZE(replySize) != sizeof(int32_t) || pReplyData == nullptr) {
|
||||||
*((int *) pReplyData) = 0;
|
VIPER_LOGE("EFFECT_CMD_RESET called with invalid replySize = %d, pReplyData = %p, expected replySize = %d", GET_REPLY_SIZE(replySize), pReplyData, sizeof(int32_t));
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
context->viper->ResetAllEffects();
|
||||||
|
SET_INT32(pReplyData, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case EFFECT_CMD_ENABLE: {
|
case EFFECT_CMD_ENABLE: {
|
||||||
pContext->viper->ResetAllEffects();
|
if (GET_REPLY_SIZE(replySize) != sizeof(int32_t) || pReplyData == nullptr) {
|
||||||
pContext->viper->enabled = true;
|
VIPER_LOGE("EFFECT_CMD_ENABLE called with invalid replySize = %d, pReplyData = %p, expected replySize = %d", GET_REPLY_SIZE(replySize), pReplyData, sizeof(int32_t));
|
||||||
*((int *) pReplyData) = 0;
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
context->viper->ResetAllEffects();
|
||||||
|
context->enabled = true;
|
||||||
|
SET_INT32(pReplyData, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case EFFECT_CMD_DISABLE: {
|
case EFFECT_CMD_DISABLE: {
|
||||||
pContext->viper->enabled = false;
|
if (GET_REPLY_SIZE(replySize) != sizeof(int32_t) || pReplyData == nullptr) {
|
||||||
*((int *) pReplyData) = 0;
|
VIPER_LOGE("EFFECT_CMD_DISABLE called with invalid replySize = %d, pReplyData = %p, expected replySize = %d", GET_REPLY_SIZE(replySize), pReplyData, sizeof(int32_t));
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
context->enabled = false;
|
||||||
|
SET_INT32(pReplyData, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case EFFECT_CMD_SET_PARAM: {
|
case EFFECT_CMD_SET_PARAM: {
|
||||||
return handleSetParam(pContext, (effect_param_t *) pCmdData, pReplyData);
|
if (cmdSize < sizeof(effect_param_t) || pCmdData == nullptr || GET_REPLY_SIZE(replySize) != sizeof(int32_t) || pReplyData == nullptr) {
|
||||||
|
VIPER_LOGE("EFFECT_CMD_SET_PARAM called with invalid cmdSize = %d, pCmdData = %p, replySize = %d, pReplyData = %p, expected cmdSize = %d, replySize = %d", cmdSize, pCmdData, GET_REPLY_SIZE(replySize), pReplyData, sizeof(effect_param_t), sizeof(int32_t));
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
return handleSetParam(context, (effect_param_t *) pCmdData, pReplyData);
|
||||||
}
|
}
|
||||||
case EFFECT_CMD_GET_PARAM: {
|
case EFFECT_CMD_GET_PARAM: {
|
||||||
return handleGetParam(pContext, (effect_param_t *) pCmdData, (effect_param_t *) pReplyData, replySize);
|
if (cmdSize < sizeof(effect_param_t) || pCmdData == nullptr || GET_REPLY_SIZE(replySize) < sizeof(effect_param_t) || pReplyData == nullptr) {
|
||||||
|
VIPER_LOGE("EFFECT_CMD_GET_PARAM called with invalid cmdSize = %d, pCmdData = %p, replySize = %d, pReplyData = %p, expected cmdSize = %d, replySize = %d", cmdSize, pCmdData, GET_REPLY_SIZE(replySize), pReplyData, sizeof(effect_param_t), sizeof(effect_param_t));
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
return handleGetParam(context, (effect_param_t *) pCmdData, (effect_param_t *) pReplyData, replySize);
|
||||||
}
|
}
|
||||||
case EFFECT_CMD_GET_CONFIG: {
|
case EFFECT_CMD_GET_CONFIG: {
|
||||||
*(effect_config_t *) pReplyData = pContext->config;
|
if (GET_REPLY_SIZE(replySize) != sizeof(effect_config_t) || pReplyData == nullptr) {
|
||||||
|
VIPER_LOGE("EFFECT_CMD_GET_CONFIG called with invalid replySize = %d, pReplyData = %p, expected replySize = %d", GET_REPLY_SIZE(replySize), pReplyData, sizeof(effect_config_t));
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
*(effect_config_t *) pReplyData = context->config;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
default: {
|
||||||
|
VIPER_LOGE("ViPERInterfaceCommand called with unknown command: %d", cmdCode);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t Viper_IGetDescriptor(effect_handle_t self, effect_descriptor_t *pDescriptor) {
|
static int32_t ViPERInterfaceGetDescriptor(effect_handle_t self, effect_descriptor_t *pDescriptor) {
|
||||||
auto pContext = reinterpret_cast<ViperContext *>(self);
|
auto context = reinterpret_cast<ViPERContext *>(self);
|
||||||
|
if (context == nullptr || pDescriptor == nullptr) return -EINVAL;
|
||||||
if (pContext == nullptr || pDescriptor == nullptr) return -EINVAL;
|
|
||||||
|
|
||||||
*pDescriptor = viper_descriptor;
|
|
||||||
|
|
||||||
|
*pDescriptor = viperDescriptor;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const effect_interface_s viper_interface = {
|
static const effect_interface_s viper_interface = {
|
||||||
.process = Viper_IProcess,
|
.process = ViPERInterfaceProcess,
|
||||||
.command = Viper_ICommand,
|
.command = ViPERInterfaceCommand,
|
||||||
.get_descriptor = Viper_IGetDescriptor
|
.get_descriptor = ViPERInterfaceGetDescriptor
|
||||||
};
|
};
|
||||||
|
|
||||||
static void Viper_Init(ViperContext *pContext) {
|
static ViPERContext *createViPERContext() {
|
||||||
pContext->interface = &viper_interface;
|
auto context = new ViPERContext();
|
||||||
memset(&pContext->config, 0, sizeof(effect_config_t));
|
context->interface = &viper_interface;
|
||||||
pContext->viper = new ViPER();
|
context->viper = new ViPER();
|
||||||
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t
|
static int32_t
|
||||||
Viper_Create(const effect_uuid_t *uuid, int32_t sessionId __unused, int32_t ioId __unused, effect_handle_t *pHandle) {
|
ViPERCreate(const effect_uuid_t *uuid, int32_t sessionId __unused, int32_t ioId __unused, effect_handle_t *pHandle) {
|
||||||
VIPER_LOGD("Viper_Create(uuid = %p, sessionId = %d, ioId = %d, pHandle = %p)", uuid, sessionId, ioId, pHandle);
|
if (uuid == nullptr || pHandle == nullptr) return -EINVAL;
|
||||||
|
if (memcmp(uuid, &viperDescriptor.uuid, sizeof(effect_uuid_t)) != 0) return -ENOENT;
|
||||||
|
|
||||||
if (uuid == nullptr || pHandle == nullptr) {
|
VIPER_LOGD("Creating ViPER");
|
||||||
VIPER_LOGD("Viper_Create() called with null uuid or pHandle");
|
auto context = createViPERContext();
|
||||||
return -EINVAL;
|
*pHandle = reinterpret_cast<effect_handle_t>(context);
|
||||||
}
|
|
||||||
|
|
||||||
if (memcmp(uuid, &viper_descriptor.uuid, sizeof(effect_uuid_t)) != 0) {
|
|
||||||
VIPER_LOGD("Viper_Create() called with wrong uuid");
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
VIPER_LOGD("Creating new ViPER instance");
|
|
||||||
auto *pContext = new ViperContext;
|
|
||||||
Viper_Init(pContext);
|
|
||||||
*pHandle = reinterpret_cast<effect_handle_t>(pContext);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t Viper_Release(effect_handle_t handle) {
|
static void deleteViPERContext(ViPERContext *context) {
|
||||||
VIPER_LOGD("Viper_Release(handle = %p)", handle);
|
delete[] context->buffer;
|
||||||
|
delete context->viper;
|
||||||
|
delete context;
|
||||||
|
}
|
||||||
|
|
||||||
auto pContext = reinterpret_cast<ViperContext *>(handle);
|
static int32_t ViPERRelease(effect_handle_t handle) {
|
||||||
|
auto context = reinterpret_cast<ViPERContext *>(handle);
|
||||||
|
if (context == nullptr) return -EINVAL;
|
||||||
|
|
||||||
if (pContext == nullptr) {
|
VIPER_LOGD("Releasing ViPER");
|
||||||
VIPER_LOGD("Viper_Release() called with null handle");
|
deleteViPERContext(context);
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
VIPER_LOGD("Releasing ViPER instance");
|
|
||||||
delete pContext->viper;
|
|
||||||
delete pContext;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t Viper_GetDescriptor(const effect_uuid_t *uuid, effect_descriptor_t *pDescriptor) {
|
static int32_t ViPERGetDescriptor(const effect_uuid_t *uuid, effect_descriptor_t *pDescriptor) {
|
||||||
VIPER_LOGD("Viper_GetDescriptor(uuid = %p, pDescriptor = %p)", uuid, pDescriptor);
|
if (uuid == nullptr || pDescriptor == nullptr) return -EINVAL;
|
||||||
|
if (memcmp(uuid, &viperDescriptor.uuid, sizeof(effect_uuid_t)) != 0) return -ENOENT;
|
||||||
if (uuid == nullptr || pDescriptor == nullptr) {
|
|
||||||
VIPER_LOGD("Viper_GetDescriptor() called with null uuid or pDescriptor");
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (memcmp(uuid, &viper_descriptor.uuid, sizeof(effect_uuid_t)) != 0) {
|
|
||||||
VIPER_LOGD("Viper_GetDescriptor() called with wrong uuid");
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
*pDescriptor = viper_descriptor;
|
|
||||||
|
|
||||||
|
*pDescriptor = viperDescriptor;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -440,9 +505,9 @@ audio_effect_library_t AUDIO_EFFECT_LIBRARY_INFO_SYM = {
|
|||||||
.version = EFFECT_LIBRARY_API_VERSION,
|
.version = EFFECT_LIBRARY_API_VERSION,
|
||||||
.name = VIPER_EFFECT_NAME,
|
.name = VIPER_EFFECT_NAME,
|
||||||
.implementor = VIPER_AUTHORS,
|
.implementor = VIPER_AUTHORS,
|
||||||
.create_effect = Viper_Create,
|
.create_effect = ViPERCreate,
|
||||||
.release_effect = Viper_Release,
|
.release_effect = ViPERRelease,
|
||||||
.get_descriptor = Viper_GetDescriptor,
|
.get_descriptor = ViPERGetDescriptor,
|
||||||
};
|
};
|
||||||
|
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
@ -106,7 +106,6 @@ ViPER::ViPER() {
|
|||||||
this->rightPan = 1.0;
|
this->rightPan = 1.0;
|
||||||
this->updateProcessTime = false;
|
this->updateProcessTime = false;
|
||||||
this->processTimeMs = 0;
|
this->processTimeMs = 0;
|
||||||
this->enabled = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ViPER::~ViPER() {
|
ViPER::~ViPER() {
|
||||||
@ -136,10 +135,6 @@ ViPER::~ViPER() {
|
|||||||
|
|
||||||
// TODO: Return int
|
// TODO: Return int
|
||||||
void ViPER::processBuffer(float *buffer, uint32_t size) {
|
void ViPER::processBuffer(float *buffer, uint32_t size) {
|
||||||
if (!this->enabled) {
|
|
||||||
VIPER_LOGD("ViPER is disabled, skip processing");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
VIPER_LOGD("Buffer size is 0, skip processing");
|
VIPER_LOGD("Buffer size is 0, skip processing");
|
||||||
return;
|
return;
|
||||||
|
@ -35,7 +35,6 @@ public:
|
|||||||
//private:
|
//private:
|
||||||
bool updateProcessTime;
|
bool updateProcessTime;
|
||||||
uint64_t processTimeMs;
|
uint64_t processTimeMs;
|
||||||
bool enabled;
|
|
||||||
uint32_t samplingRate;
|
uint32_t samplingRate;
|
||||||
|
|
||||||
// Effects
|
// Effects
|
||||||
|
Loading…
Reference in New Issue
Block a user