Skip to content

Commit

Permalink
Bump version to 0.7.0-alpha1
Browse files Browse the repository at this point in the history
  • Loading branch information
iscle committed Mar 13, 2024
1 parent eb65772 commit df53254
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 111 deletions.
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ set(CMAKE_CXX_COMPILER_VERSION 20)
#add_compile_definitions(ANDROID_PLATFORM=android-24)

project("ViPER4Android")
add_compile_definitions(VERSION_CODE=20231210)
add_compile_definitions(VERSION_NAME="0.6.1")
add_compile_definitions(VIPER_VERSION=20240314)

# FFTS
#add_subdirectory(src/viper/ffts)
Expand Down
20 changes: 8 additions & 12 deletions src/ViPER4Android.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@ extern "C" {
#define COMMAND_CODE_GET 0x01
#define COMMAND_CODE_SET 0x02

// Param get
#define PARAM_GET_ENABLED 1
#define PARAM_GET_CONFIGURE 2
#define PARAM_GET_STREAMING 3
#define PARAM_GET_SAMPLING_RATE 4
#define PARAM_GET_CONVOLUTION_KERNEL_ID 5
#define PARAM_GET_DRIVER_VERSION_CODE 6
#define PARAM_GET_DRIVER_VERSION_NAME 7
#define PARAM_GET_DISABLE_REASON 8
#define PARAM_GET_DISABLE_REASON_MESSAGE 9
#define PARAM_GET_CONFIG 10
#define PARAM_GET_ARCHITECTURE 11
typedef enum {
PARAM_GET_ENABLED = 0,
PARAM_GET_FRAME_COUNT,
PARAM_GET_VERSION,
PARAM_GET_DISABLE_REASON,
PARAM_GET_CONFIG,
PARAM_GET_ARCHITECTURE,
} param_get_t;

// Param set
#define PARAM_SET_UPDATE_STATUS 0x9002
Expand Down
88 changes: 17 additions & 71 deletions src/ViperContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ void ViperContext::handleSetConfig(effect_config_t *newConfig) {
if (config.inputCfg.buffer.frameCount != config.outputCfg.buffer.frameCount) {
VIPER_LOGE("ViPER4Android disabled, reason [in.FC = %zu, out.FC = %zu]",
config.inputCfg.buffer.frameCount, config.outputCfg.buffer.frameCount);
setDisableReason(DisableReason::INVALID_FRAME_COUNT, "Input and output frame count mismatch");
setDisableReason(DisableReason::INVALID_FRAME_COUNT);
return;
}

if (config.inputCfg.samplingRate != config.outputCfg.samplingRate) {
VIPER_LOGE("ViPER4Android disabled, reason [in.SR = %d, out.SR = %d]",
config.inputCfg.samplingRate, config.outputCfg.samplingRate);
setDisableReason(DisableReason::INVALID_SAMPLING_RATE, "Input and output sampling rate mismatch");
setDisableReason(DisableReason::INVALID_SAMPLING_RATE);
return;
}

Expand All @@ -89,13 +89,13 @@ void ViperContext::handleSetConfig(effect_config_t *newConfig) {
if (config.inputCfg.channels != config.outputCfg.channels) {
VIPER_LOGE("ViPER4Android disabled, reason [in.CH = %d, out.CH = %d]",
config.inputCfg.channels, config.outputCfg.channels);
setDisableReason(DisableReason::INVALID_CHANNEL_COUNT, "Input and output channel count mismatch");
setDisableReason(DisableReason::INVALID_CHANNEL_COUNT);
return;
}

if (config.inputCfg.channels != AUDIO_CHANNEL_OUT_STEREO) {
VIPER_LOGE("ViPER4Android disabled, reason [CH != 2]");
setDisableReason(DisableReason::INVALID_CHANNEL_COUNT, "Invalid channel count: " + std::to_string(config.inputCfg.channels));
setDisableReason(DisableReason::INVALID_CHANNEL_COUNT);
return;
}

Expand All @@ -104,7 +104,7 @@ void ViperContext::handleSetConfig(effect_config_t *newConfig) {
config.inputCfg.format != AUDIO_FORMAT_PCM_FLOAT) {
VIPER_LOGE("ViPER4Android disabled, reason [in.FMT = %d]", config.inputCfg.format);
VIPER_LOGE("We only accept AUDIO_FORMAT_PCM_16_BIT, AUDIO_FORMAT_PCM_32_BIT and AUDIO_FORMAT_PCM_FLOAT input format!");
setDisableReason(DisableReason::INVALID_FORMAT, "Invalid input format: " + std::to_string(config.inputCfg.format));
setDisableReason(DisableReason::INVALID_FORMAT);
return;
}

Expand All @@ -113,7 +113,7 @@ void ViperContext::handleSetConfig(effect_config_t *newConfig) {
config.outputCfg.format != AUDIO_FORMAT_PCM_FLOAT) {
VIPER_LOGE("ViPER4Android disabled, reason [out.FMT = %d]", config.outputCfg.format);
VIPER_LOGE("We only accept AUDIO_FORMAT_PCM_16_BIT, AUDIO_FORMAT_PCM_32_BIT and AUDIO_FORMAT_PCM_FLOAT output format!");
setDisableReason(DisableReason::INVALID_FORMAT, "Invalid output format: " + std::to_string(config.outputCfg.format));
setDisableReason(DisableReason::INVALID_FORMAT);
return;
}

Expand Down Expand Up @@ -187,63 +187,22 @@ int32_t ViperContext::handleGetParam(effect_param_t *pCmdParam, effect_param_t *
switch (*(uint32_t *) pCmdParam->data) {
case PARAM_GET_ENABLED: {
pReplyParam->status = 0;
pReplyParam->vsize = sizeof(int32_t);
*(int32_t *) (pReplyParam->data + vOffset) = enabled;
pReplyParam->vsize = sizeof(uint8_t);
*(uint8_t *) (pReplyParam->data + vOffset) = enabled;
*pReplySize = sizeof(effect_param_t) + pReplyParam->psize + vOffset + pReplyParam->vsize;
return 0;
}
case PARAM_GET_CONFIGURE: {
case PARAM_GET_FRAME_COUNT: {
pReplyParam->status = 0;
pReplyParam->vsize = sizeof(int32_t);
*(int32_t *) (pReplyParam->data + vOffset) = disableReason == DisableReason::NONE;
*pReplySize = sizeof(effect_param_t) + pReplyParam->psize + vOffset + pReplyParam->vsize;
return 0;
}
case PARAM_GET_STREAMING: { // Is processing
auto now = std::chrono::system_clock::now();
auto now_ms = std::chrono::time_point_cast<std::chrono::milliseconds>(now);

uint64_t currentMs = now_ms.time_since_epoch().count();
uint64_t lastProcessTime = viper.processTimeMs;

bool isProcessing;
if (currentMs >= lastProcessTime) {
isProcessing = currentMs - lastProcessTime < 5000;
} else {
isProcessing = false;
}

pReplyParam->status = 0;
pReplyParam->vsize = sizeof(int32_t);
*(int32_t *) (pReplyParam->data + vOffset) = isProcessing;
pReplyParam->vsize = sizeof(uint64_t);
*(uint64_t *) (pReplyParam->data + vOffset) = viper.frameCount;
*pReplySize = sizeof(effect_param_t) + pReplyParam->psize + vOffset + pReplyParam->vsize;
return 0;
}
case PARAM_GET_SAMPLING_RATE: {
case PARAM_GET_VERSION: {
pReplyParam->status = 0;
pReplyParam->vsize = sizeof(uint32_t);
*(uint32_t *) (pReplyParam->data + vOffset) = viper.samplingRate;
*pReplySize = sizeof(effect_param_t) + pReplyParam->psize + vOffset + pReplyParam->vsize;
return 0;
}
case PARAM_GET_CONVOLUTION_KERNEL_ID: {
pReplyParam->status = 0;
pReplyParam->vsize = sizeof(uint32_t);
*(uint32_t *) (pReplyParam->data + vOffset) = viper.convolver.GetKernelID();
*pReplySize = sizeof(effect_param_t) + pReplyParam->psize + vOffset + pReplyParam->vsize;
return 0;
}
case PARAM_GET_DRIVER_VERSION_CODE: {
pReplyParam->status = 0;
pReplyParam->vsize = sizeof(uint32_t);
*(int32_t *) (pReplyParam->data + vOffset) = VERSION_CODE;
*pReplySize = sizeof(effect_param_t) + pReplyParam->psize + vOffset + pReplyParam->vsize;
return 0;
}
case PARAM_GET_DRIVER_VERSION_NAME: {
pReplyParam->status = 0;
pReplyParam->vsize = strlen(VERSION_NAME);
memcpy(pReplyParam->data + vOffset, VERSION_NAME, pReplyParam->vsize);
*(uint32_t *) (pReplyParam->data + vOffset) = VIPER_VERSION;
*pReplySize = sizeof(effect_param_t) + pReplyParam->psize + vOffset + pReplyParam->vsize;
return 0;
}
Expand All @@ -254,13 +213,6 @@ int32_t ViperContext::handleGetParam(effect_param_t *pCmdParam, effect_param_t *
*pReplySize = sizeof(effect_param_t) + pReplyParam->psize + vOffset + pReplyParam->vsize;
return 0;
}
case PARAM_GET_DISABLE_REASON_MESSAGE: {
pReplyParam->status = 0;
pReplyParam->vsize = disableReasonMessage.size();
memcpy(pReplyParam->data + vOffset, disableReasonMessage.c_str(), pReplyParam->vsize);
*pReplySize = sizeof(effect_param_t) + pReplyParam->psize + vOffset + pReplyParam->vsize;
return 0;
}
case PARAM_GET_CONFIG: {
pReplyParam->status = 0;
pReplyParam->vsize = 40;
Expand All @@ -283,15 +235,14 @@ int32_t ViperContext::handleGetParam(effect_param_t *pCmdParam, effect_param_t *
}
case PARAM_GET_ARCHITECTURE: {
pReplyParam->status = 0;
pReplyParam->vsize = sizeof(VIPER_ARCHITECTURE) - 1; // Exclude null terminator
memcpy(pReplyParam->data + vOffset, VIPER_ARCHITECTURE, pReplyParam->vsize);
pReplyParam->vsize = sizeof(uint8_t);
*(uint8_t *) (pReplyParam->data + vOffset) = VIPER_ARCHITECTURE;
*pReplySize = sizeof(effect_param_t) + pReplyParam->psize + vOffset + pReplyParam->vsize;
return 0;
}
default: {
return -EINVAL;
}
}

return -EINVAL;
}

int32_t ViperContext::handleCommand(uint32_t cmdCode, uint32_t cmdSize, void *pCmdData, uint32_t *pReplySize, void *pReplyData) {
Expand Down Expand Up @@ -476,10 +427,5 @@ int32_t ViperContext::process(audio_buffer_t *inBuffer, audio_buffer_t *outBuffe
}

void ViperContext::setDisableReason(DisableReason reason) {
setDisableReason(reason, "");
}

void ViperContext::setDisableReason(DisableReason reason, std::string message) {
this->disableReason = reason;
this->disableReasonMessage = std::move(message);
}
2 changes: 0 additions & 2 deletions src/ViperContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class ViperContext {
private:
effect_config_t config;
DisableReason disableReason;
std::string disableReasonMessage;

// Processing buffer
std::vector<float> buffer;
Expand All @@ -41,5 +40,4 @@ class ViperContext {
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);
};
18 changes: 4 additions & 14 deletions src/viper/ViPER.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
#include "constants.h"

ViPER::ViPER() :
updateProcessTime(false),
processTimeMs(0),
frameCount(0),
samplingRate(VIPER_DEFAULT_SAMPLING_RATE),
adaptiveBuffer(AdaptiveBuffer(2, 4096)),
waveBuffer(WaveBuffer(2, 4096)),
iirFilter(IIRFilter(10)) {
VIPER_LOGI("Welcome to ViPER FX");
VIPER_LOGI("Current version is %s (%d)", VERSION_NAME, VERSION_CODE);
VIPER_LOGI("Current version is %d", VIPER_VERSION);

this->convolver.SetEnable(false);
this->convolver.SetSamplingRate(this->samplingRate);
Expand Down Expand Up @@ -87,16 +86,11 @@ ViPER::ViPER() :
this->frameScale = 1.0;
this->leftPan = 1.0;
this->rightPan = 1.0;
this->updateProcessTime = false;
this->processTimeMs = 0;
this->frameCount = 0;
}

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);
this->processTimeMs = now_ms.time_since_epoch().count();
}
this->frameCount += size;

uint32_t ret;
float *tmpBuf;
Expand Down Expand Up @@ -190,10 +184,6 @@ void ViPER::DispatchCommand(int param, int val1, int val2, int val3, int val4, u
signed char *arr) {
VIPER_LOGD("Dispatch command: %d, %d, %d, %d, %d, %d, %p", param, val1, val2, val3, val4, arrSize, arr);
switch (param) {
case PARAM_SET_UPDATE_STATUS: {
this->updateProcessTime = val1 != 0;
break;
}
case PARAM_SET_RESET_STATUS: {
this->resetAllEffects();
break;
Expand Down
3 changes: 1 addition & 2 deletions src/viper/ViPER.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ class ViPER {
void resetAllEffects();

//private:
bool updateProcessTime;
uint64_t processTimeMs;
uint64_t frameCount;
uint32_t samplingRate;

// Effects
Expand Down
28 changes: 20 additions & 8 deletions src/viper/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,31 @@

#include "../log.h" // TODO: Remove this dependency

typedef enum {
ARCH_UNKNOWN = 0,
ARCH_ARM,
ARCH_ARM64,
ARCH_X86,
ARCH_X86_64,
} arch_t;

#if defined(__arm__)
#define VIPER_ARCHITECTURE "ARM"
#define VIPER_ARCHITECTURE ARCH_ARM
#elif defined(__aarch64__)
#define VIPER_ARCHITECTURE "ARM64"
#define VIPER_ARCHITECTURE ARCH_ARM64
#elif defined(__i386__)
#define VIPER_ARCHITECTURE "x86"
#define VIPER_ARCHITECTURE ARCH_X86
#elif defined(__x86_64__)
#define VIPER_ARCHITECTURE "x86_64"
#define VIPER_ARCHITECTURE ARCH_X86_64
#else
#error "Unknown architecture"
// Note from the developer:
// There's no architecture dependent code in ViPER4Android, this is just for debugging purposes.
// Feel free to add your architecture if it's not listed here.
#warning "Unknown architecture"
#define VIPER_ARCHITECTURE ARCH_UNKNOWN
/*
* Note from the developer:
*
* There's no architecture dependent code in ViPER4Android, this is just for debugging purposes.
* Feel free to add your architecture if it's not listed here
*/
#endif

#define VIPER_NAME "ViPER4Android"
Expand Down

0 comments on commit df53254

Please sign in to comment.