mirror of
https://github.com/AndroidAudioMods/ViPERFX_RE.git
synced 2024-12-22 22:47:25 +08:00
Update
This commit is contained in:
parent
d1c4600366
commit
11952040a3
@ -5,11 +5,11 @@ set(CMAKE_CXX_COMPILER_VERSION 20)
|
||||
#set(ANDROID_ABI arm64-v8a)
|
||||
set(ANDROID_ABI armeabi-v7a)
|
||||
set(ANDROID_ARM_NEON true)
|
||||
set(ANDROID_PLATFORM android-21)
|
||||
set(ANDROID_PLATFORM android-24)
|
||||
|
||||
project("ViPER4Android")
|
||||
add_compile_definitions(VERSION_CODE=1)
|
||||
add_compile_definitions(VERSION_NAME="1.0.0")
|
||||
add_compile_definitions(VERSION_CODE=20221231)
|
||||
add_compile_definitions(VERSION_NAME="0.1.0")
|
||||
|
||||
## KISS FFT
|
||||
#set(KISSFFT_PKGCONFIG OFF)
|
||||
@ -78,7 +78,7 @@ message(${CMAKE_BUILD_TYPE})
|
||||
|
||||
add_library(
|
||||
# Sets the name of the library.
|
||||
v4afx_r
|
||||
v4a_re
|
||||
|
||||
# Sets the library as a shared library.
|
||||
SHARED
|
||||
@ -86,5 +86,5 @@ add_library(
|
||||
# Provides a relative path to your source file(s).
|
||||
${FILES})
|
||||
|
||||
target_link_libraries(v4afx_r log) # kissfft)
|
||||
target_compile_options(v4afx_r PRIVATE -Wall -Wextra -Wno-unused-parameter)
|
||||
target_link_libraries(v4a_re log) # kissfft)
|
||||
#target_compile_options(v4afx_r PRIVATE -O2 -DNDEBUG -Wall -Wsign-conversion -Wno-unused-result -Wno-unneeded-internal-declaration -fstrict-aliasing -fvisibility=hidden -Wextra -Wno-unused-parameter)
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <cstdlib>
|
||||
#include "viper/ViPER.h"
|
||||
#include "essential.h"
|
||||
#include "log.h"
|
||||
@ -9,10 +10,7 @@
|
||||
|
||||
static effect_descriptor_t viper_descriptor = {
|
||||
.type = EFFECT_UUID_INITIALIZER,
|
||||
// 41d3c987-e6cf-11e3-a88a-11aba5d5c51b
|
||||
// Original: {0x41d3c987, 0xe6cf, 0x11e3, 0xa88a, {0x11, 0xab, 0xa5, 0xd5, 0xc5, 0x1b}}
|
||||
// New: {0x90380da3, 0x8536, 0x4744, 0xa6a3, {0x57, 0x31, 0x97, 0x0e, 0x64, 0x0f}}
|
||||
.uuid = {0x41d3c987, 0xe6cf, 0x11e3, 0xa88a, {0x11, 0xab, 0xa5, 0xd5, 0xc5, 0x1b}},
|
||||
.uuid = {0x90380da3, 0x8536, 0x4744, 0xa6a3, {0x57, 0x31, 0x97, 0x0e, 0x64, 0x0f}},
|
||||
.apiVersion = EFFECT_CONTROL_API_VERSION,
|
||||
.flags = EFFECT_FLAG_OUTPUT_DIRECT | EFFECT_FLAG_INPUT_DIRECT | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_TYPE_INSERT,
|
||||
.cpuLoad = 8, // In 0.1 MIPS units as estimated on an ARM9E core (ARMv5TE) with 0 WS
|
||||
@ -29,6 +27,34 @@ struct ViperContext {
|
||||
ViPER *viper;
|
||||
};
|
||||
|
||||
static void pcm16ToFloat(float *dst, const int16_t *src, size_t frameCount) {
|
||||
for (size_t i = 0; i < frameCount * 2; i++) {
|
||||
dst[i] = (float) src[i] / (float) (1 << 15);
|
||||
}
|
||||
}
|
||||
|
||||
static void pcm32ToFloat(float *dst, const int32_t *src, size_t frameCount) {
|
||||
for (size_t i = 0; i < frameCount * 2; i++) {
|
||||
dst[i] = (float) src[i] / (float) (1 << 31);
|
||||
}
|
||||
}
|
||||
|
||||
static void floatToFloat(float *dst, const float *src, size_t frameCount) {
|
||||
memcpy(dst, src, frameCount * 2 * sizeof(float));
|
||||
}
|
||||
|
||||
static void floatToPcm16(int16_t *dst, const float *src, size_t frameCount) {
|
||||
for (size_t i = 0; i < frameCount * 2; i++) {
|
||||
dst[i] = (int16_t) round(src[i] * (float) (1 << 15));
|
||||
}
|
||||
}
|
||||
|
||||
static void floatToPcm32(int32_t *dst, const float *src, size_t frameCount) {
|
||||
for (size_t i = 0; i < frameCount * 2; i++) {
|
||||
dst[i] = (int32_t) round(src[i] * (float) (1 << 31));
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t Viper_IProcess(effect_handle_t self, audio_buffer_t *inBuffer, audio_buffer_t *outBuffer) {
|
||||
auto pContext = reinterpret_cast<ViperContext *>(self);
|
||||
|
||||
@ -40,27 +66,57 @@ static int32_t Viper_IProcess(effect_handle_t self, audio_buffer_t *inBuffer, au
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
float *inBufferPtr = inBuffer->f32;
|
||||
float *outBufferPtr = outBuffer->f32;
|
||||
float *buffer;
|
||||
size_t frameCount = outBuffer->frameCount;
|
||||
|
||||
if (inBufferPtr != outBufferPtr) {
|
||||
memcpy(outBufferPtr, inBufferPtr, outBuffer->frameCount * 2 * sizeof(float));
|
||||
switch (pContext->config.inputCfg.format) {
|
||||
case AUDIO_FORMAT_PCM_16_BIT:
|
||||
buffer = new float[outBuffer->frameCount * 2];
|
||||
pcm16ToFloat(buffer, inBuffer->s16, frameCount);
|
||||
break;
|
||||
case AUDIO_FORMAT_PCM_32_BIT:
|
||||
buffer = new float[outBuffer->frameCount * 2];
|
||||
pcm32ToFloat(buffer, inBuffer->s32, frameCount);
|
||||
break;
|
||||
case AUDIO_FORMAT_PCM_FLOAT:
|
||||
buffer = outBuffer->f32;
|
||||
floatToFloat(buffer, inBuffer->f32, frameCount);
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
pContext->viper->processBuffer(buffer, frameCount);
|
||||
|
||||
switch (pContext->config.outputCfg.format) {
|
||||
case AUDIO_FORMAT_PCM_16_BIT:
|
||||
floatToPcm16(outBuffer->s16, buffer, frameCount);
|
||||
delete[] buffer;
|
||||
break;
|
||||
case AUDIO_FORMAT_PCM_32_BIT:
|
||||
floatToPcm32(outBuffer->s32, buffer, frameCount);
|
||||
delete[] buffer;
|
||||
break;
|
||||
case AUDIO_FORMAT_PCM_FLOAT:
|
||||
floatToFloat(outBuffer->f32, buffer, frameCount);
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
pContext->viper->processBuffer(outBufferPtr, outBuffer->frameCount);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int handleSetConfig(ViperContext *pContext, effect_config_t *newConfig) {
|
||||
VIPER_LOGI("Begin handleSetConfig ...");
|
||||
VIPER_LOGD("Begin handleSetConfig ...");
|
||||
VIPER_LOGI("Checking input and output configuration ...");
|
||||
|
||||
VIPER_LOGD("Input sampling rate: %d", newConfig->inputCfg.samplingRate);
|
||||
VIPER_LOGD("Input channels: %d", newConfig->inputCfg.channels);
|
||||
VIPER_LOGD("Input format: %d", newConfig->inputCfg.format);
|
||||
VIPER_LOGD("Output sampling rate: %d", newConfig->outputCfg.samplingRate);
|
||||
VIPER_LOGD("Output channels: %d", newConfig->outputCfg.channels);
|
||||
VIPER_LOGD("Output format: %d", newConfig->outputCfg.format);
|
||||
VIPER_LOGI("Input sampling rate: %d", newConfig->inputCfg.samplingRate);
|
||||
VIPER_LOGI("Input channels: %d", newConfig->inputCfg.channels);
|
||||
VIPER_LOGI("Input format: %d", newConfig->inputCfg.format);
|
||||
VIPER_LOGI("Output sampling rate: %d", newConfig->outputCfg.samplingRate);
|
||||
VIPER_LOGI("Output channels: %d", newConfig->outputCfg.channels);
|
||||
VIPER_LOGI("Output format: %d", newConfig->outputCfg.format);
|
||||
|
||||
pContext->isConfigValid = false;
|
||||
|
||||
@ -86,17 +142,19 @@ static int handleSetConfig(ViperContext *pContext, effect_config_t *newConfig) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
// AUDIO_FORMAT_PCM_16_BIT
|
||||
if (newConfig->inputCfg.format != AUDIO_FORMAT_PCM_FLOAT) {
|
||||
if (newConfig->inputCfg.format != AUDIO_FORMAT_PCM_16_BIT &&
|
||||
newConfig->inputCfg.format != AUDIO_FORMAT_PCM_32_BIT &&
|
||||
newConfig->inputCfg.format != AUDIO_FORMAT_PCM_FLOAT) {
|
||||
VIPER_LOGE("ViPER4Android disabled, reason [in.FMT = %d]", newConfig->inputCfg.format);
|
||||
VIPER_LOGE("We only accept f32 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;
|
||||
}
|
||||
|
||||
// AUDIO_FORMAT_PCM_16_BIT
|
||||
if (newConfig->outputCfg.format != AUDIO_FORMAT_PCM_FLOAT) {
|
||||
if (newConfig->outputCfg.format != AUDIO_FORMAT_PCM_16_BIT &&
|
||||
newConfig->outputCfg.format != AUDIO_FORMAT_PCM_32_BIT &&
|
||||
newConfig->outputCfg.format != AUDIO_FORMAT_PCM_FLOAT) {
|
||||
VIPER_LOGE("ViPER4Android disabled, reason [out.FMT = %d]", newConfig->outputCfg.format);
|
||||
VIPER_LOGE("We only accept f32 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;
|
||||
}
|
||||
|
||||
@ -107,7 +165,7 @@ static int handleSetConfig(ViperContext *pContext, effect_config_t *newConfig) {
|
||||
pContext->viper->ResetAllEffects();
|
||||
pContext->isConfigValid = true;
|
||||
|
||||
VIPER_LOGI("Audio handleSetConfig finished");
|
||||
VIPER_LOGD("Audio handleSetConfig finished");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user