C++ hackery

This commit is contained in:
Iscle 2023-05-15 18:09:07 +02:00
parent 0310b01599
commit 5a053df9ce
7 changed files with 123 additions and 483 deletions

View File

@ -8,11 +8,11 @@ set(CMAKE_CXX_COMPILER_VERSION 20)
#add_compile_definitions(ANDROID_PLATFORM=android-24)
project("ViPER4Android")
add_compile_definitions(VERSION_CODE=20230311)
add_compile_definitions(VERSION_NAME="0.3.0")
add_compile_definitions(VERSION_CODE=20230515)
add_compile_definitions(VERSION_NAME="0.4.0")
# FFTS
add_subdirectory(src/viper/ffts)
#add_subdirectory(src/viper/ffts)
# ViPERFX
include_directories(src/include)

View File

@ -1,14 +1,13 @@
#include <cstring>
#include <ctime>
#include <cstdlib>
#include "viper/ViPER.h"
#include "essential.h"
#include "viper/constants.h"
#include "ViperContext.h"
extern "C" {
struct ViperHandle {
const struct effect_interface_s *iface; // Always keep as first member
struct ViperContext *context;
ViperContext *context;
};
static const effect_descriptor_t viperDescriptor = {
@ -24,6 +23,7 @@ static const effect_descriptor_t viperDescriptor = {
};
static int32_t viperInterfaceProcess(effect_handle_t self, audio_buffer_t *inBuffer, audio_buffer_t *outBuffer) {
VIPER_LOGD("viperInterfaceProcess() called");
auto viperHandle = reinterpret_cast<ViperHandle *>(self);
if (viperHandle == nullptr) return -EINVAL;
@ -33,37 +33,42 @@ static int32_t viperInterfaceProcess(effect_handle_t self, audio_buffer_t *inBuf
static int32_t viperInterfaceCommand(effect_handle_t self,
uint32_t cmdCode, uint32_t cmdSize, void *pCmdData,
uint32_t *replySize, void *pReplyData) {
VIPER_LOGD("viperInterfaceCommand() called");
auto viperHandle = reinterpret_cast<ViperHandle *>(self);
if (viperHandle == nullptr) return -EINVAL;
return viperHandle->context->handleCommand(cmdCode, cmdSize, pCmdData, replySize, pReplyData);
}
static int32_t viperInterfaceGetDescriptor(effect_handle_t self, effect_descriptor_t *pDescriptor) {
VIPER_LOGD("viperInterfaceGetDescriptor() called");
if (pDescriptor == nullptr) return -EINVAL;
*pDescriptor = viperDescriptor;
return 0;
}
static const effect_interface_s viper_interface = {
static const effect_interface_s viperInterface = {
.process = viperInterfaceProcess,
.command = viperInterfaceCommand,
.get_descriptor = viperInterfaceGetDescriptor
};
static int32_t
viperLibraryCreate(const effect_uuid_t *uuid, int32_t sessionId __unused, int32_t ioId __unused, effect_handle_t *pHandle) {
viperLibraryCreate(const effect_uuid_t *uuid, int32_t sessionId __unused, int32_t ioId __unused,
effect_handle_t *pHandle) {
VIPER_LOGD("viperLibraryCreate() called");
if (uuid == nullptr || pHandle == nullptr) return -EINVAL;
if (memcmp(uuid, &viperDescriptor.uuid, sizeof(effect_uuid_t)) != 0) return -ENOENT;
auto viperHandle = new ViperHandle();
viperHandle->iface = &viper_interface;
ViperHandle *viperHandle = new ViperHandle();
viperHandle->iface = &viperInterface;
viperHandle->context = new ViperContext();
*pHandle = reinterpret_cast<effect_handle_t>(viperHandle);
return 0;
}
static int32_t viperLibraryRelease(effect_handle_t handle) {
VIPER_LOGD("viperLibraryRelease() called");
auto viperHandle = reinterpret_cast<ViperHandle *>(handle);
if (viperHandle == nullptr) return -EINVAL;
@ -72,6 +77,7 @@ static int32_t viperLibraryRelease(effect_handle_t handle) {
}
static int32_t viperLibraryGetDescriptor(const effect_uuid_t *uuid, effect_descriptor_t *pDescriptor) {
VIPER_LOGD("viperLibraryGetDescriptor() called");
if (uuid == nullptr || pDescriptor == nullptr) return -EINVAL;
if (memcmp(uuid, &viperDescriptor.uuid, sizeof(effect_uuid_t)) != 0) return -ENOENT;
@ -79,8 +85,8 @@ static int32_t viperLibraryGetDescriptor(const effect_uuid_t *uuid, effect_descr
return 0;
}
extern "C" __attribute__ ((visibility ("default")))
const audio_effect_library_t AUDIO_EFFECT_LIBRARY_INFO_SYM = {
__attribute__ ((visibility ("default")))
audio_effect_library_t AUDIO_EFFECT_LIBRARY_INFO_SYM = {
.tag = AUDIO_EFFECT_LIBRARY_TAG,
.version = EFFECT_LIBRARY_API_VERSION,
.name = VIPER_NAME,
@ -89,3 +95,4 @@ const audio_effect_library_t AUDIO_EFFECT_LIBRARY_INFO_SYM = {
.release_effect = viperLibraryRelease,
.get_descriptor = viperLibraryGetDescriptor,
};
} // extern "C"

View File

@ -7,14 +7,14 @@
ViperContext::ViperContext() :
config({}),
isConfigValid(false),
disableReason(DisableReason::NONE),
buffer(std::vector<float>()),
bufferFrameCount(0),
enabled(false) {
VIPER_LOGI("ViperContext created");
}
int ViperContext::handleSetConfig(effect_config_t *newConfig) {
void ViperContext::handleSetConfig(effect_config_t *newConfig) {
VIPER_LOGI("Checking input and output configuration ...");
VIPER_LOGI("Input buffer frame count: %ld", newConfig->inputCfg.buffer.frameCount);
@ -28,39 +28,39 @@ int ViperContext::handleSetConfig(effect_config_t *newConfig) {
VIPER_LOGI("Output format: %d", newConfig->outputCfg.format);
VIPER_LOGI("Output access mode: %d", newConfig->outputCfg.accessMode);
isConfigValid = false;
setDisableReason(DisableReason::UNKNOWN);
if (newConfig->inputCfg.buffer.frameCount != newConfig->outputCfg.buffer.frameCount) {
VIPER_LOGE("ViPER4Android disabled, reason [in.FC = %ld, out.FC = %ld]",
newConfig->inputCfg.buffer.frameCount, newConfig->outputCfg.buffer.frameCount);
// disableReason = "Invalid frame count";
return 0;
setDisableReason(DisableReason::INVALID_FRAME_COUNT);
return;
}
if (newConfig->inputCfg.samplingRate != newConfig->outputCfg.samplingRate) {
VIPER_LOGE("ViPER4Android disabled, reason [in.SR = %d, out.SR = %d]",
newConfig->inputCfg.samplingRate, newConfig->outputCfg.samplingRate);
// disableReason = "Invalid sampling rate";
return 0;
setDisableReason(DisableReason::INVALID_SAMPLING_RATE);
return;
}
if (newConfig->inputCfg.samplingRate > 48000) {
VIPER_LOGE("ViPER4Android disabled, reason [SR out of range]");
// disableReason = "Sampling rate out of range";
return 0;
setDisableReason(DisableReason::INVALID_SAMPLING_RATE, "Sampling rate out of range: " + std::to_string(newConfig->inputCfg.samplingRate));
return;
}
if (newConfig->inputCfg.channels != newConfig->outputCfg.channels) {
VIPER_LOGE("ViPER4Android disabled, reason [in.CH = %d, out.CH = %d]",
newConfig->inputCfg.channels, newConfig->outputCfg.channels);
// disableReason = "Invalid channel count";
return 0;
setDisableReason(DisableReason::INVALID_CHANNEL_COUNT);
return;
}
if (newConfig->inputCfg.channels != AUDIO_CHANNEL_OUT_STEREO) {
VIPER_LOGE("ViPER4Android disabled, reason [CH != 2]");
// disableReason = "Channel count != 2";
return 0;
setDisableReason(DisableReason::INVALID_CHANNEL_COUNT, "Invalid channel count: " + std::to_string(newConfig->inputCfg.channels));
return;
}
if (newConfig->inputCfg.format != AUDIO_FORMAT_PCM_16_BIT &&
@ -68,8 +68,8 @@ int ViperContext::handleSetConfig(effect_config_t *newConfig) {
newConfig->inputCfg.format != AUDIO_FORMAT_PCM_FLOAT) {
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!");
// disableReason = "Invalid input format";
return 0;
setDisableReason(DisableReason::INVALID_FORMAT, "Invalid input format: " + std::to_string(newConfig->inputCfg.format));
return;
}
if (newConfig->outputCfg.format != AUDIO_FORMAT_PCM_16_BIT &&
@ -77,24 +77,23 @@ int ViperContext::handleSetConfig(effect_config_t *newConfig) {
newConfig->outputCfg.format != AUDIO_FORMAT_PCM_FLOAT) {
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!");
// disableReason = "Invalid output format";
return 0;
setDisableReason(DisableReason::INVALID_FORMAT, "Invalid output format: " + std::to_string(newConfig->outputCfg.format));
return;
}
VIPER_LOGI("Input and output configuration checked.");
// Config
config = *newConfig;
isConfigValid = true;
// disableReason = "";
setDisableReason(DisableReason::NONE);
// Processing buffer
buffer.resize(newConfig->inputCfg.buffer.frameCount * 2);
bufferFrameCount = newConfig->inputCfg.buffer.frameCount;
// ViPER
viper.samplingRate = newConfig->inputCfg.samplingRate;
viper.ResetAllEffects();
return 0;
viper.resetAllEffects();
}
int32_t ViperContext::handleSetParam(effect_param_t *pCmdParam, void *pReplyData) {
@ -148,7 +147,7 @@ int32_t ViperContext::handleGetParam(effect_param_t *pCmdParam, effect_param_t *
// the parameter size to the next 32 bit alignment.
uint32_t vOffset = ((pCmdParam->psize + sizeof(int32_t) - 1) / sizeof(int32_t)) * sizeof(int32_t);
VIPER_LOGD("viperInterfaceCommand() EFFECT_CMD_GET_PARAM called with data = %d, psize = %d, vsize = %d", *(uint32_t *) pCmdParam->data, pCmdParam->psize, pCmdParam->vsize);
VIPER_LOGD("handleGetParam() 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);
@ -163,7 +162,7 @@ int32_t ViperContext::handleGetParam(effect_param_t *pCmdParam, effect_param_t *
case PARAM_GET_CONFIGURE: {
pReplyParam->status = 0;
pReplyParam->vsize = sizeof(int32_t);
*(int32_t *) (pReplyParam->data + vOffset) = isConfigValid;
*(int32_t *) (pReplyParam->data + vOffset) = disableReason == DisableReason::NONE;
*pReplySize = sizeof(effect_param_t) + pReplyParam->psize + vOffset + pReplyParam->vsize;
return 0;
}
@ -174,16 +173,16 @@ int32_t ViperContext::handleGetParam(effect_param_t *pCmdParam, effect_param_t *
uint64_t currentMs = now_ms.time_since_epoch().count();
uint64_t lastProcessTime = viper.processTimeMs;
uint64_t diff;
if (currentMs > lastProcessTime) {
diff = currentMs - lastProcessTime;
bool isProcessing;
if (currentMs >= lastProcessTime) {
isProcessing = currentMs - lastProcessTime < 5000;
} else {
diff = lastProcessTime - currentMs;
isProcessing = false;
}
pReplyParam->status = 0;
pReplyParam->vsize = sizeof(int32_t);
*(int32_t *) (pReplyParam->data + vOffset) = diff > 5000 ? 0 : 1;
*(int32_t *) (pReplyParam->data + vOffset) = isProcessing;
*pReplySize = sizeof(effect_param_t) + pReplyParam->psize + vOffset + pReplyParam->vsize;
return 0;
}
@ -221,79 +220,79 @@ int32_t ViperContext::handleGetParam(effect_param_t *pCmdParam, effect_param_t *
}
}
#define SET_INT32(ptr, value) (*(int32_t *) (ptr) = (value))
#define GET_REPLY_SIZE(ptr) (ptr == nullptr ? 0 : *ptr)
#define SET(type, ptr, value) (*(type *) (ptr) = (value))
int32_t ViperContext::handleCommand(uint32_t cmdCode, uint32_t cmdSize, void *pCmdData, uint32_t *replySize, void *pReplyData) {
int32_t ViperContext::handleCommand(uint32_t cmdCode, uint32_t cmdSize, void *pCmdData, uint32_t *pReplySize, void *pReplyData) {
uint32_t replySize = pReplySize == nullptr ? 0 : *pReplySize;
switch (cmdCode) {
case EFFECT_CMD_INIT: {
if (GET_REPLY_SIZE(replySize) != sizeof(int32_t) || pReplyData == nullptr) {
VIPER_LOGE("EFFECT_CMD_INIT called with invalid replySize = %d, pReplyData = %p, expected replySize = %lu", GET_REPLY_SIZE(replySize), pReplyData, sizeof(int32_t));
if (replySize != sizeof(int32_t) || pReplyData == nullptr) {
VIPER_LOGE("EFFECT_CMD_INIT called with invalid replySize = %d, pReplyData = %p, expected replySize = %lu", replySize, pReplyData, sizeof(int32_t));
return -EINVAL;
}
SET_INT32(pReplyData, 0);
SET(int32_t, pReplyData, 0);
return 0;
}
case EFFECT_CMD_SET_CONFIG: {
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 = %lu, replySize = %lu", cmdSize, pCmdData, GET_REPLY_SIZE(replySize), pReplyData, sizeof(effect_config_t), sizeof(int32_t));
if (cmdSize < sizeof(effect_config_t) || pCmdData == nullptr || 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 = %lu, replySize = %lu", cmdSize, pCmdData, replySize, pReplyData, sizeof(effect_config_t), sizeof(int32_t));
return -EINVAL;
}
SET_INT32(pReplyData, handleSetConfig((effect_config_t *) pCmdData));
handleSetConfig((effect_config_t *) pCmdData);
SET(int32_t, pReplyData, 0);
return 0;
}
case EFFECT_CMD_RESET: {
if (GET_REPLY_SIZE(replySize) != sizeof(int32_t) || pReplyData == nullptr) {
VIPER_LOGE("EFFECT_CMD_RESET called with invalid replySize = %d, pReplyData = %p, expected replySize = %lu", GET_REPLY_SIZE(replySize), pReplyData, sizeof(int32_t));
if (replySize != sizeof(int32_t) || pReplyData == nullptr) {
VIPER_LOGE("EFFECT_CMD_RESET called with invalid replySize = %d, pReplyData = %p, expected replySize = %lu", replySize, pReplyData, sizeof(int32_t));
return -EINVAL;
}
viper.ResetAllEffects();
SET_INT32(pReplyData, 0);
viper.resetAllEffects();
SET(int32_t, pReplyData, 0);
return 0;
}
case EFFECT_CMD_ENABLE: {
if (GET_REPLY_SIZE(replySize) != sizeof(int32_t) || pReplyData == nullptr) {
VIPER_LOGE("EFFECT_CMD_ENABLE called with invalid replySize = %d, pReplyData = %p, expected replySize = %lu", GET_REPLY_SIZE(replySize), pReplyData, sizeof(int32_t));
if (replySize != sizeof(int32_t) || pReplyData == nullptr) {
VIPER_LOGE("EFFECT_CMD_ENABLE called with invalid replySize = %d, pReplyData = %p, expected replySize = %lu", replySize, pReplyData, sizeof(int32_t));
return -EINVAL;
}
viper.ResetAllEffects();
enabled = true;
SET_INT32(pReplyData, 0);
SET(int32_t, pReplyData, 0);
return 0;
}
case EFFECT_CMD_DISABLE: {
if (GET_REPLY_SIZE(replySize) != sizeof(int32_t) || pReplyData == nullptr) {
VIPER_LOGE("EFFECT_CMD_DISABLE called with invalid replySize = %d, pReplyData = %p, expected replySize = %lu", GET_REPLY_SIZE(replySize), pReplyData, sizeof(int32_t));
if (replySize != sizeof(int32_t) || pReplyData == nullptr) {
VIPER_LOGE("EFFECT_CMD_DISABLE called with invalid replySize = %d, pReplyData = %p, expected replySize = %lu", replySize, pReplyData, sizeof(int32_t));
return -EINVAL;
}
enabled = false;
SET_INT32(pReplyData, 0);
SET(int32_t, pReplyData, 0);
return 0;
}
case EFFECT_CMD_SET_PARAM: {
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 = %lu, replySize = %lu", cmdSize, pCmdData, GET_REPLY_SIZE(replySize), pReplyData, sizeof(effect_param_t), sizeof(int32_t));
if (cmdSize < sizeof(effect_param_t) || pCmdData == nullptr || 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 = %lu, replySize = %lu", cmdSize, pCmdData, replySize, pReplyData, sizeof(effect_param_t), sizeof(int32_t));
return -EINVAL;
}
return handleSetParam((effect_param_t *) pCmdData, pReplyData);
}
case EFFECT_CMD_GET_PARAM: {
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 = %lu, replySize = %lu", cmdSize, pCmdData, GET_REPLY_SIZE(replySize), pReplyData, sizeof(effect_param_t), sizeof(effect_param_t));
if (cmdSize < sizeof(effect_param_t) || pCmdData == nullptr || 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 = %lu, replySize = %lu", cmdSize, pCmdData, replySize, pReplyData, sizeof(effect_param_t), sizeof(effect_param_t));
return -EINVAL;
}
return handleGetParam((effect_param_t *) pCmdData, (effect_param_t *) pReplyData, replySize);
return handleGetParam((effect_param_t *) pCmdData, (effect_param_t *) pReplyData, pReplySize);
}
case EFFECT_CMD_GET_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 = %lu", GET_REPLY_SIZE(replySize), pReplyData, sizeof(effect_config_t));
if (replySize != sizeof(effect_config_t) || pReplyData == nullptr) {
VIPER_LOGE("EFFECT_CMD_GET_CONFIG called with invalid replySize = %d, pReplyData = %p, expected replySize = %lu", replySize, pReplyData, sizeof(effect_config_t));
return -EINVAL;
}
*(effect_config_t *) pReplyData = config;
return 0;
}
default: {
VIPER_LOGE("viperInterfaceCommand called with unknown command: %d", cmdCode);
VIPER_LOGE("handleCommand called with unknown command: %d", cmdCode);
return -EINVAL;
}
}
@ -324,11 +323,11 @@ static void floatToFloat(float *dst, const float *src, size_t frameCount, bool a
static void floatToPcm16(int16_t *dst, const float *src, size_t frameCount, bool accumulate) {
if (accumulate) {
for (size_t i = 0; i < frameCount * 2; i++) {
dst[i] += static_cast<int16_t>(std::round(src[i] * static_cast<float>(1 << 15)));
dst[i] += static_cast<int16_t>(std::roundf(src[i] * static_cast<float>(1 << 15)));
}
} else {
for (size_t i = 0; i < frameCount * 2; i++) {
dst[i] = static_cast<int16_t>(std::round(src[i] * static_cast<float>(1 << 15)));
dst[i] = static_cast<int16_t>(std::roundf(src[i] * static_cast<float>(1 << 15)));
}
}
}
@ -336,11 +335,11 @@ static void floatToPcm16(int16_t *dst, const float *src, size_t frameCount, bool
static void floatToPcm32(int32_t *dst, const float *src, size_t frameCount, bool accumulate) {
if (accumulate) {
for (size_t i = 0; i < frameCount * 2; i++) {
dst[i] += static_cast<int32_t>(std::round(src[i] * static_cast<float>(1 << 31)));
dst[i] += static_cast<int32_t>(std::roundf(src[i] * static_cast<float>(1 << 31)));
}
} else {
for (size_t i = 0; i < frameCount * 2; i++) {
dst[i] = static_cast<int32_t>(std::round(src[i] * static_cast<float>(1 << 31)));
dst[i] = static_cast<int32_t>(std::roundf(src[i] * static_cast<float>(1 << 31)));
}
}
}
@ -351,7 +350,7 @@ static audio_buffer_t *getBuffer(buffer_config_s *config, audio_buffer_t *buffer
}
int32_t ViperContext::process(audio_buffer_t *inBuffer, audio_buffer_t *outBuffer) {
if (!isConfigValid) {
if (disableReason != DisableReason::NONE) {
return -EINVAL;
}
@ -388,7 +387,7 @@ int32_t ViperContext::process(audio_buffer_t *inBuffer, audio_buffer_t *outBuffe
return -EINVAL;
}
viper.processBuffer(buffer.data(), frameCount);
viper.process(buffer, frameCount);
const bool accumulate = config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE;
switch (config.outputCfg.format) {
@ -407,3 +406,12 @@ int32_t ViperContext::process(audio_buffer_t *inBuffer, audio_buffer_t *outBuffe
return 0;
}
void ViperContext::setDisableReason(DisableReason reason) {
setDisableReason(reason, "");
}
void ViperContext::setDisableReason(DisableReason reason, std::string message) {
this->disableReason = reason;
this->disableReasonMessage = std::move(message);
}

View File

@ -4,11 +4,28 @@
#include <cstddef>
#include "essential.h"
#include "viper/ViPER.h"
#include <string>
class ViperContext {
public:
enum class DisableReason {
NONE,
UNKNOWN,
INVALID_FRAME_COUNT,
INVALID_SAMPLING_RATE,
INVALID_CHANNEL_COUNT,
INVALID_FORMAT,
};
ViperContext();
int32_t handleCommand(uint32_t cmdCode, uint32_t cmdSize, void *pCmdData, uint32_t *replySize, void *pReplyData);
int32_t process(audio_buffer_t *inBuffer, audio_buffer_t *outBuffer);
private:
effect_config_t config;
bool isConfigValid;
DisableReason disableReason;
std::string disableReasonMessage;
// Processing buffer
std::vector<float> buffer;
@ -18,15 +35,10 @@ public:
bool enabled;
ViPER viper;
ViperContext();
int32_t handleCommand(uint32_t cmdCode, uint32_t cmdSize, void *pCmdData, uint32_t *replySize, void *pReplyData);
int32_t process(audio_buffer_t *inBuffer, audio_buffer_t *outBuffer);
int handleSetConfig(effect_config_t *newConfig);
void handleSetConfig(effect_config_t *newConfig);
int32_t handleSetParam(effect_param_t *pCmdParam, void *pReplyData);
int32_t handleGetParam(effect_param_t *pCmdParam, effect_param_t *pReplyParam, uint32_t *pReplySize);
void setDisableReason(DisableReason reason);
void setDisableReason(DisableReason reason, std::string message);
};

View File

@ -927,64 +927,6 @@ typedef struct audio_effect_library_s
EFFECT_CONFIG_CHANNELS | EFFECT_CONFIG_FORMAT | \
EFFECT_CONFIG_ACC_MODE | EFFECT_CONFIG_PROVIDER)
enum {
AUDIO_IO_HANDLE_NONE = 0,
AUDIO_MODULE_HANDLE_NONE = 0,
AUDIO_PORT_HANDLE_NONE = 0,
AUDIO_PATCH_HANDLE_NONE = 0,
};
typedef enum {
AUDIO_STREAM_DEFAULT = -1, // (-1)
AUDIO_STREAM_MIN = 0,
AUDIO_STREAM_VOICE_CALL = 0,
AUDIO_STREAM_SYSTEM = 1,
AUDIO_STREAM_RING = 2,
AUDIO_STREAM_MUSIC = 3,
AUDIO_STREAM_ALARM = 4,
AUDIO_STREAM_NOTIFICATION = 5,
AUDIO_STREAM_BLUETOOTH_SCO = 6,
AUDIO_STREAM_ENFORCED_AUDIBLE = 7,
AUDIO_STREAM_DTMF = 8,
AUDIO_STREAM_TTS = 9,
AUDIO_STREAM_ACCESSIBILITY = 10,
#ifndef AUDIO_NO_SYSTEM_DECLARATIONS
/** For dynamic policy output mixes. Only used by the audio policy */
AUDIO_STREAM_REROUTING = 11,
/** For audio flinger tracks volume. Only used by the audioflinger */
AUDIO_STREAM_PATCH = 12,
#endif // AUDIO_NO_SYSTEM_DECLARATIONS
} audio_stream_type_t;
typedef enum {
AUDIO_SOURCE_DEFAULT = 0,
AUDIO_SOURCE_MIC = 1,
AUDIO_SOURCE_VOICE_UPLINK = 2,
AUDIO_SOURCE_VOICE_DOWNLINK = 3,
AUDIO_SOURCE_VOICE_CALL = 4,
AUDIO_SOURCE_CAMCORDER = 5,
AUDIO_SOURCE_VOICE_RECOGNITION = 6,
AUDIO_SOURCE_VOICE_COMMUNICATION = 7,
AUDIO_SOURCE_REMOTE_SUBMIX = 8,
AUDIO_SOURCE_UNPROCESSED = 9,
AUDIO_SOURCE_FM_TUNER = 1998,
#ifndef AUDIO_NO_SYSTEM_DECLARATIONS
/**
* A low-priority, preemptible audio source for for background software
* hotword detection. Same tuning as VOICE_RECOGNITION.
* Used only internally by the framework.
*/
AUDIO_SOURCE_HOTWORD = 1999,
#endif // AUDIO_NO_SYSTEM_DECLARATIONS
} audio_source_t;
typedef enum {
AUDIO_SESSION_OUTPUT_STAGE = -1, // (-1)
AUDIO_SESSION_OUTPUT_MIX = 0,
AUDIO_SESSION_ALLOCATE = 0,
AUDIO_SESSION_NONE = 0,
} audio_session_t;
typedef enum {
AUDIO_FORMAT_INVALID = 0xFFFFFFFFu,
AUDIO_FORMAT_DEFAULT = 0,
@ -1094,179 +1036,6 @@ typedef enum {
AUDIO_FORMAT_MAT_2_1 = 0x24000003u, // (MAT | MAT_SUB_2_1)
} audio_format_t;
typedef enum {
#ifndef AUDIO_NO_SYSTEM_DECLARATIONS
AUDIO_MODE_INVALID = -2, // (-2)
AUDIO_MODE_CURRENT = -1, // (-1)
#endif // AUDIO_NO_SYSTEM_DECLARATIONS
AUDIO_MODE_NORMAL = 0,
AUDIO_MODE_RINGTONE = 1,
AUDIO_MODE_IN_CALL = 2,
AUDIO_MODE_IN_COMMUNICATION = 3,
} audio_mode_t;
enum {
AUDIO_DEVICE_NONE = 0x0u,
AUDIO_DEVICE_BIT_IN = 0x80000000u,
AUDIO_DEVICE_BIT_DEFAULT = 0x40000000u,
AUDIO_DEVICE_OUT_EARPIECE = 0x1u,
AUDIO_DEVICE_OUT_SPEAKER = 0x2u,
AUDIO_DEVICE_OUT_WIRED_HEADSET = 0x4u,
AUDIO_DEVICE_OUT_WIRED_HEADPHONE = 0x8u,
AUDIO_DEVICE_OUT_BLUETOOTH_SCO = 0x10u,
AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET = 0x20u,
AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT = 0x40u,
AUDIO_DEVICE_OUT_BLUETOOTH_A2DP = 0x80u,
AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100u,
AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200u,
AUDIO_DEVICE_OUT_AUX_DIGITAL = 0x400u,
AUDIO_DEVICE_OUT_HDMI = 0x400u, // OUT_AUX_DIGITAL
AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET = 0x800u,
AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET = 0x1000u,
AUDIO_DEVICE_OUT_USB_ACCESSORY = 0x2000u,
AUDIO_DEVICE_OUT_USB_DEVICE = 0x4000u,
AUDIO_DEVICE_OUT_REMOTE_SUBMIX = 0x8000u,
AUDIO_DEVICE_OUT_TELEPHONY_TX = 0x10000u,
AUDIO_DEVICE_OUT_LINE = 0x20000u,
AUDIO_DEVICE_OUT_HDMI_ARC = 0x40000u,
AUDIO_DEVICE_OUT_SPDIF = 0x80000u,
AUDIO_DEVICE_OUT_FM = 0x100000u,
AUDIO_DEVICE_OUT_AUX_LINE = 0x200000u,
AUDIO_DEVICE_OUT_SPEAKER_SAFE = 0x400000u,
AUDIO_DEVICE_OUT_IP = 0x800000u,
AUDIO_DEVICE_OUT_BUS = 0x1000000u,
AUDIO_DEVICE_OUT_PROXY = 0x2000000u,
AUDIO_DEVICE_OUT_USB_HEADSET = 0x4000000u,
AUDIO_DEVICE_OUT_HEARING_AID = 0x8000000u,
AUDIO_DEVICE_OUT_ECHO_CANCELLER = 0x10000000u,
AUDIO_DEVICE_OUT_DEFAULT = 0x40000000u, // BIT_DEFAULT
AUDIO_DEVICE_IN_COMMUNICATION = 0x80000001u, // BIT_IN | 0x1
AUDIO_DEVICE_IN_AMBIENT = 0x80000002u, // BIT_IN | 0x2
AUDIO_DEVICE_IN_BUILTIN_MIC = 0x80000004u, // BIT_IN | 0x4
AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET = 0x80000008u, // BIT_IN | 0x8
AUDIO_DEVICE_IN_WIRED_HEADSET = 0x80000010u, // BIT_IN | 0x10
AUDIO_DEVICE_IN_AUX_DIGITAL = 0x80000020u, // BIT_IN | 0x20
AUDIO_DEVICE_IN_HDMI = 0x80000020u, // IN_AUX_DIGITAL
AUDIO_DEVICE_IN_VOICE_CALL = 0x80000040u, // BIT_IN | 0x40
AUDIO_DEVICE_IN_TELEPHONY_RX = 0x80000040u, // IN_VOICE_CALL
AUDIO_DEVICE_IN_BACK_MIC = 0x80000080u, // BIT_IN | 0x80
AUDIO_DEVICE_IN_REMOTE_SUBMIX = 0x80000100u, // BIT_IN | 0x100
AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET = 0x80000200u, // BIT_IN | 0x200
AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET = 0x80000400u, // BIT_IN | 0x400
AUDIO_DEVICE_IN_USB_ACCESSORY = 0x80000800u, // BIT_IN | 0x800
AUDIO_DEVICE_IN_USB_DEVICE = 0x80001000u, // BIT_IN | 0x1000
AUDIO_DEVICE_IN_FM_TUNER = 0x80002000u, // BIT_IN | 0x2000
AUDIO_DEVICE_IN_TV_TUNER = 0x80004000u, // BIT_IN | 0x4000
AUDIO_DEVICE_IN_LINE = 0x80008000u, // BIT_IN | 0x8000
AUDIO_DEVICE_IN_SPDIF = 0x80010000u, // BIT_IN | 0x10000
AUDIO_DEVICE_IN_BLUETOOTH_A2DP = 0x80020000u, // BIT_IN | 0x20000
AUDIO_DEVICE_IN_LOOPBACK = 0x80040000u, // BIT_IN | 0x40000
AUDIO_DEVICE_IN_IP = 0x80080000u, // BIT_IN | 0x80000
AUDIO_DEVICE_IN_BUS = 0x80100000u, // BIT_IN | 0x100000
AUDIO_DEVICE_IN_PROXY = 0x81000000u, // BIT_IN | 0x1000000
AUDIO_DEVICE_IN_USB_HEADSET = 0x82000000u, // BIT_IN | 0x2000000
AUDIO_DEVICE_IN_BLUETOOTH_BLE = 0x84000000u, // BIT_IN | 0x4000000
AUDIO_DEVICE_IN_DEFAULT = 0xC0000000u, // BIT_IN | BIT_DEFAULT
};
typedef enum {
AUDIO_OUTPUT_FLAG_NONE = 0x0,
AUDIO_OUTPUT_FLAG_DIRECT = 0x1,
AUDIO_OUTPUT_FLAG_PRIMARY = 0x2,
AUDIO_OUTPUT_FLAG_FAST = 0x4,
AUDIO_OUTPUT_FLAG_DEEP_BUFFER = 0x8,
AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD = 0x10,
AUDIO_OUTPUT_FLAG_NON_BLOCKING = 0x20,
AUDIO_OUTPUT_FLAG_HW_AV_SYNC = 0x40,
AUDIO_OUTPUT_FLAG_TTS = 0x80,
AUDIO_OUTPUT_FLAG_RAW = 0x100,
AUDIO_OUTPUT_FLAG_SYNC = 0x200,
AUDIO_OUTPUT_FLAG_IEC958_NONAUDIO = 0x400,
AUDIO_OUTPUT_FLAG_DIRECT_PCM = 0x2000,
AUDIO_OUTPUT_FLAG_MMAP_NOIRQ = 0x4000,
AUDIO_OUTPUT_FLAG_VOIP_RX = 0x8000,
AUDIO_OUTPUT_FLAG_INCALL_MUSIC = 0x10000,
} audio_output_flags_t;
typedef enum {
AUDIO_INPUT_FLAG_NONE = 0x0,
AUDIO_INPUT_FLAG_FAST = 0x1,
AUDIO_INPUT_FLAG_HW_HOTWORD = 0x2,
AUDIO_INPUT_FLAG_RAW = 0x4,
AUDIO_INPUT_FLAG_SYNC = 0x8,
AUDIO_INPUT_FLAG_MMAP_NOIRQ = 0x10,
AUDIO_INPUT_FLAG_VOIP_TX = 0x20,
AUDIO_INPUT_FLAG_HW_AV_SYNC = 0x40,
} audio_input_flags_t;
typedef enum {
AUDIO_USAGE_UNKNOWN = 0,
AUDIO_USAGE_MEDIA = 1,
AUDIO_USAGE_VOICE_COMMUNICATION = 2,
AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING = 3,
AUDIO_USAGE_ALARM = 4,
AUDIO_USAGE_NOTIFICATION = 5,
AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE = 6,
#ifndef AUDIO_NO_SYSTEM_DECLARATIONS
AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST = 7,
AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT = 8,
AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED = 9,
AUDIO_USAGE_NOTIFICATION_EVENT = 10,
#endif // AUDIO_NO_SYSTEM_DECLARATIONS
AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY = 11,
AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE = 12,
AUDIO_USAGE_ASSISTANCE_SONIFICATION = 13,
AUDIO_USAGE_GAME = 14,
AUDIO_USAGE_VIRTUAL_SOURCE = 15,
AUDIO_USAGE_ASSISTANT = 16,
} audio_usage_t;
typedef enum {
AUDIO_CONTENT_TYPE_UNKNOWN = 0u,
AUDIO_CONTENT_TYPE_SPEECH = 1u,
AUDIO_CONTENT_TYPE_MUSIC = 2u,
AUDIO_CONTENT_TYPE_MOVIE = 3u,
AUDIO_CONTENT_TYPE_SONIFICATION = 4u,
} audio_content_type_t;
enum {
AUDIO_GAIN_MODE_JOINT = 0x1u,
AUDIO_GAIN_MODE_CHANNELS = 0x2u,
AUDIO_GAIN_MODE_RAMP = 0x4u,
};
typedef enum {
AUDIO_PORT_ROLE_NONE = 0,
AUDIO_PORT_ROLE_SOURCE = 1, // (::android::hardware::audio::common::V4_0::AudioPortRole.NONE implicitly + 1)
AUDIO_PORT_ROLE_SINK = 2, // (::android::hardware::audio::common::V4_0::AudioPortRole.SOURCE implicitly + 1)
} audio_port_role_t;
typedef enum {
AUDIO_PORT_TYPE_NONE = 0,
AUDIO_PORT_TYPE_DEVICE = 1, // (::android::hardware::audio::common::V4_0::AudioPortType.NONE implicitly + 1)
AUDIO_PORT_TYPE_MIX = 2, // (::android::hardware::audio::common::V4_0::AudioPortType.DEVICE implicitly + 1)
AUDIO_PORT_TYPE_SESSION = 3, // (::android::hardware::audio::common::V4_0::AudioPortType.MIX implicitly + 1)
} audio_port_type_t;
enum {
AUDIO_PORT_CONFIG_SAMPLE_RATE = 0x1u,
AUDIO_PORT_CONFIG_CHANNEL_MASK = 0x2u,
AUDIO_PORT_CONFIG_FORMAT = 0x4u,
AUDIO_PORT_CONFIG_GAIN = 0x8u,
};
typedef enum {
AUDIO_LATENCY_LOW = 0,
AUDIO_LATENCY_NORMAL = 1, // (::android::hardware::audio::common::V4_0::AudioMixLatencyClass.LOW implicitly + 1)
} audio_mix_latency_class_t;
enum {
FCC_2 = 2,
FCC_8 = 8,
};
enum {
AUDIO_CHANNEL_REPRESENTATION_POSITION = 0x0u,
AUDIO_CHANNEL_REPRESENTATION_INDEX = 0x2u,
@ -1359,153 +1128,3 @@ enum {
AUDIO_CHANNEL_INDEX_MASK_7 = 0x8000007Fu, // INDEX_HDR | (1 << 7) - 1
AUDIO_CHANNEL_INDEX_MASK_8 = 0x800000FFu, // INDEX_HDR | (1 << 8) - 1
};
enum {
/** Number of audio stream available to vendors. */
AUDIO_STREAM_PUBLIC_CNT = AUDIO_STREAM_ACCESSIBILITY + 1,
#ifndef AUDIO_NO_SYSTEM_DECLARATIONS
/** Total number of stream handled by the policy*/
AUDIO_STREAM_FOR_POLICY_CNT= AUDIO_STREAM_REROUTING + 1,
#endif
/** Total number of stream. */
AUDIO_STREAM_CNT = AUDIO_STREAM_PATCH + 1,
AUDIO_SOURCE_MAX = AUDIO_SOURCE_UNPROCESSED,
AUDIO_SOURCE_CNT = AUDIO_SOURCE_MAX + 1,
AUDIO_MODE_MAX = AUDIO_MODE_IN_COMMUNICATION,
AUDIO_MODE_CNT = AUDIO_MODE_MAX + 1,
/** For retrocompatibility AUDIO_MODE_* and AUDIO_STREAM_* must be signed. */
AUDIO_DETAIL_NEGATIVE_VALUE = -1,
};
enum {
AUDIO_CHANNEL_OUT_ALL = AUDIO_CHANNEL_OUT_FRONT_LEFT |
AUDIO_CHANNEL_OUT_FRONT_RIGHT |
AUDIO_CHANNEL_OUT_FRONT_CENTER |
AUDIO_CHANNEL_OUT_LOW_FREQUENCY |
AUDIO_CHANNEL_OUT_BACK_LEFT |
AUDIO_CHANNEL_OUT_BACK_RIGHT |
AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER |
AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER |
AUDIO_CHANNEL_OUT_BACK_CENTER |
AUDIO_CHANNEL_OUT_SIDE_LEFT |
AUDIO_CHANNEL_OUT_SIDE_RIGHT |
AUDIO_CHANNEL_OUT_TOP_CENTER |
AUDIO_CHANNEL_OUT_TOP_FRONT_LEFT |
AUDIO_CHANNEL_OUT_TOP_FRONT_CENTER |
AUDIO_CHANNEL_OUT_TOP_FRONT_RIGHT |
AUDIO_CHANNEL_OUT_TOP_BACK_LEFT |
AUDIO_CHANNEL_OUT_TOP_BACK_CENTER |
AUDIO_CHANNEL_OUT_TOP_BACK_RIGHT |
AUDIO_CHANNEL_OUT_TOP_SIDE_LEFT |
AUDIO_CHANNEL_OUT_TOP_SIDE_RIGHT,
AUDIO_CHANNEL_IN_ALL = AUDIO_CHANNEL_IN_LEFT |
AUDIO_CHANNEL_IN_RIGHT |
AUDIO_CHANNEL_IN_FRONT |
AUDIO_CHANNEL_IN_BACK|
AUDIO_CHANNEL_IN_LEFT_PROCESSED |
AUDIO_CHANNEL_IN_RIGHT_PROCESSED |
AUDIO_CHANNEL_IN_FRONT_PROCESSED |
AUDIO_CHANNEL_IN_BACK_PROCESSED|
AUDIO_CHANNEL_IN_PRESSURE |
AUDIO_CHANNEL_IN_X_AXIS |
AUDIO_CHANNEL_IN_Y_AXIS |
AUDIO_CHANNEL_IN_Z_AXIS |
AUDIO_CHANNEL_IN_VOICE_UPLINK |
AUDIO_CHANNEL_IN_VOICE_DNLINK |
AUDIO_CHANNEL_IN_BACK_LEFT |
AUDIO_CHANNEL_IN_BACK_RIGHT |
AUDIO_CHANNEL_IN_CENTER |
AUDIO_CHANNEL_IN_LOW_FREQUENCY |
AUDIO_CHANNEL_IN_TOP_LEFT |
AUDIO_CHANNEL_IN_TOP_RIGHT,
AUDIO_DEVICE_OUT_ALL = AUDIO_DEVICE_OUT_EARPIECE |
AUDIO_DEVICE_OUT_SPEAKER |
AUDIO_DEVICE_OUT_WIRED_HEADSET |
AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
AUDIO_DEVICE_OUT_BLUETOOTH_SCO |
AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT |
AUDIO_DEVICE_OUT_BLUETOOTH_A2DP |
AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER |
AUDIO_DEVICE_OUT_HDMI |
AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET |
AUDIO_DEVICE_OUT_USB_ACCESSORY |
AUDIO_DEVICE_OUT_USB_DEVICE |
AUDIO_DEVICE_OUT_REMOTE_SUBMIX |
AUDIO_DEVICE_OUT_TELEPHONY_TX |
AUDIO_DEVICE_OUT_LINE |
AUDIO_DEVICE_OUT_HDMI_ARC |
AUDIO_DEVICE_OUT_SPDIF |
AUDIO_DEVICE_OUT_FM |
AUDIO_DEVICE_OUT_AUX_LINE |
AUDIO_DEVICE_OUT_SPEAKER_SAFE |
AUDIO_DEVICE_OUT_IP |
AUDIO_DEVICE_OUT_BUS |
AUDIO_DEVICE_OUT_PROXY |
AUDIO_DEVICE_OUT_USB_HEADSET |
AUDIO_DEVICE_OUT_HEARING_AID |
AUDIO_DEVICE_OUT_ECHO_CANCELLER |
AUDIO_DEVICE_OUT_DEFAULT,
AUDIO_DEVICE_OUT_ALL_A2DP = AUDIO_DEVICE_OUT_BLUETOOTH_A2DP |
AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER,
AUDIO_DEVICE_OUT_ALL_SCO = AUDIO_DEVICE_OUT_BLUETOOTH_SCO |
AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT,
AUDIO_DEVICE_OUT_ALL_USB = AUDIO_DEVICE_OUT_USB_ACCESSORY |
AUDIO_DEVICE_OUT_USB_DEVICE |
AUDIO_DEVICE_OUT_USB_HEADSET,
AUDIO_DEVICE_IN_ALL = AUDIO_DEVICE_IN_COMMUNICATION |
AUDIO_DEVICE_IN_AMBIENT |
AUDIO_DEVICE_IN_BUILTIN_MIC |
AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET |
AUDIO_DEVICE_IN_WIRED_HEADSET |
AUDIO_DEVICE_IN_HDMI |
AUDIO_DEVICE_IN_TELEPHONY_RX |
AUDIO_DEVICE_IN_BACK_MIC |
AUDIO_DEVICE_IN_REMOTE_SUBMIX |
AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET |
AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET |
AUDIO_DEVICE_IN_USB_ACCESSORY |
AUDIO_DEVICE_IN_USB_DEVICE |
AUDIO_DEVICE_IN_FM_TUNER |
AUDIO_DEVICE_IN_TV_TUNER |
AUDIO_DEVICE_IN_LINE |
AUDIO_DEVICE_IN_SPDIF |
AUDIO_DEVICE_IN_BLUETOOTH_A2DP |
AUDIO_DEVICE_IN_LOOPBACK |
AUDIO_DEVICE_IN_IP |
AUDIO_DEVICE_IN_BUS |
AUDIO_DEVICE_IN_PROXY |
AUDIO_DEVICE_IN_USB_HEADSET |
AUDIO_DEVICE_IN_BLUETOOTH_BLE |
AUDIO_DEVICE_IN_DEFAULT,
AUDIO_DEVICE_IN_ALL_SCO = AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET,
AUDIO_DEVICE_IN_ALL_USB = AUDIO_DEVICE_IN_USB_ACCESSORY |
AUDIO_DEVICE_IN_USB_DEVICE |
AUDIO_DEVICE_IN_USB_HEADSET,
AUDIO_USAGE_MAX = AUDIO_USAGE_ASSISTANT,
AUDIO_USAGE_CNT = AUDIO_USAGE_ASSISTANT + 1,
AUDIO_PORT_CONFIG_ALL = AUDIO_PORT_CONFIG_SAMPLE_RATE |
AUDIO_PORT_CONFIG_CHANNEL_MASK |
AUDIO_PORT_CONFIG_FORMAT |
AUDIO_PORT_CONFIG_GAIN,
}; // enum

View File

@ -133,13 +133,7 @@ ViPER::~ViPER() {
}
}
// TODO: Return int
void ViPER::processBuffer(float *buffer, uint32_t size) {
if (size == 0) {
VIPER_LOGD("Buffer size is 0, skip processing");
return;
}
void ViPER::process(std::vector<float>& buffer, uint32_t size) {
if (this->updateProcessTime) {
auto now = std::chrono::system_clock::now();
auto now_ms = std::chrono::time_point_cast<std::chrono::milliseconds>(now);
@ -153,7 +147,7 @@ void ViPER::processBuffer(float *buffer, uint32_t size) {
if (this->convolver->GetEnabled() || this->vhe->GetEnabled()) {
// VIPER_LOGD("Convolver or VHE is enable, use wave buffer");
if (!this->waveBuffer->PushSamples(buffer, size)) {
if (!this->waveBuffer->PushSamples(buffer.data(), size)) {
this->waveBuffer->Reset();
return;
}
@ -178,7 +172,7 @@ void ViPER::processBuffer(float *buffer, uint32_t size) {
} else {
// VIPER_LOGD("Convolver and VHE are disabled, use adaptive buffer");
if (this->adaptiveBuffer->PushFrames(buffer, size)) {
if (this->adaptiveBuffer->PushFrames(buffer.data(), size)) {
this->adaptiveBuffer->SetBufferOffset(size);
tmpBuf = this->adaptiveBuffer->GetBuffer();
@ -220,7 +214,7 @@ void ViPER::processBuffer(float *buffer, uint32_t size) {
tmpBuf[i + 1] = this->softwareLimiters[1]->Process(tmpBuf[i + 1]);
}
if (!this->adaptiveBuffer->PopFrames(buffer, tmpBufSize)) {
if (!this->adaptiveBuffer->PopFrames(buffer.data(), tmpBufSize)) {
this->adaptiveBuffer->FlushBuffer();
return;
}
@ -230,8 +224,8 @@ void ViPER::processBuffer(float *buffer, uint32_t size) {
}
}
memmove(buffer + (size - tmpBufSize) * 2, buffer, tmpBufSize * sizeof(float));
memset(buffer, 0, (size - tmpBufSize) * sizeof(float));
memmove(buffer.data() + (size - tmpBufSize) * 2, buffer.data(), tmpBufSize * sizeof(float));
memset(buffer.data(), 0, (size - tmpBufSize) * sizeof(float));
}
void ViPER::DispatchCommand(int param, int val1, int val2, int val3, int val4, uint32_t arrSize,
@ -243,7 +237,7 @@ void ViPER::DispatchCommand(int param, int val1, int val2, int val3, int val4, u
break;
}
case PARAM_SET_RESET_STATUS: {
this->ResetAllEffects();
this->resetAllEffects();
break;
}
case PARAM_CONVOLUTION_ENABLE: {
@ -541,7 +535,7 @@ void ViPER::DispatchCommand(int param, int val1, int val2, int val3, int val4, u
}
}
void ViPER::ResetAllEffects() {
void ViPER::resetAllEffects() {
if (this->adaptiveBuffer != nullptr) {
this->adaptiveBuffer->FlushBuffer();
}

View File

@ -27,10 +27,10 @@ public:
ViPER();
~ViPER();
void processBuffer(float *buffer, uint32_t size);
void process(std::vector<float>& buffer, uint32_t size);
// TODO: Parameter types/names
void DispatchCommand(int param, int val1, int val2, int val3, int val4, uint32_t arrSize, signed char *arr);
void ResetAllEffects();
void resetAllEffects();
//private:
bool updateProcessTime;