Only copy audio effect config based on the mask

This commit is contained in:
Iscle 2023-05-16 18:03:24 +02:00
parent 93d64d9f36
commit d78189693a
2 changed files with 55 additions and 28 deletions

View File

@ -16,9 +16,35 @@ ViperContext::ViperContext() :
VIPER_LOGI("ViperContext created"); VIPER_LOGI("ViperContext created");
} }
void ViperContext::handleSetConfig(effect_config_t *newConfig) { void ViperContext::copyBufferConfig(buffer_config_t *dest, buffer_config_t *src) {
// TODO: Check the mask and set the config accordingly if (src->mask & EFFECT_CONFIG_BUFFER) {
dest->buffer = src->buffer;
}
if (src->mask & EFFECT_CONFIG_SMP_RATE) {
dest->samplingRate = src->samplingRate;
}
if (src->mask & EFFECT_CONFIG_CHANNELS) {
dest->channels = src->channels;
}
if (src->mask & EFFECT_CONFIG_FORMAT) {
dest->format = src->format;
}
if (src->mask & EFFECT_CONFIG_ACC_MODE) {
dest->accessMode = src->accessMode;
}
if (src->mask & EFFECT_CONFIG_PROVIDER) {
dest->bufferProvider = src->bufferProvider;
}
dest->mask |= src->mask;
}
void ViperContext::handleSetConfig(effect_config_t *newConfig) {
VIPER_LOGI("Checking input and output configuration ..."); VIPER_LOGI("Checking input and output configuration ...");
VIPER_LOGI("Input mask: 0x%04X", newConfig->inputCfg.mask); VIPER_LOGI("Input mask: 0x%04X", newConfig->inputCfg.mask);
@ -36,69 +62,69 @@ void ViperContext::handleSetConfig(effect_config_t *newConfig) {
setDisableReason(DisableReason::UNKNOWN); setDisableReason(DisableReason::UNKNOWN);
if (newConfig->inputCfg.buffer.frameCount != newConfig->outputCfg.buffer.frameCount) { copyBufferConfig(&config.inputCfg, &newConfig->inputCfg);
copyBufferConfig(&config.outputCfg, &newConfig->outputCfg);
if (config.inputCfg.buffer.frameCount != config.outputCfg.buffer.frameCount) {
VIPER_LOGE("ViPER4Android disabled, reason [in.FC = %ld, out.FC = %ld]", VIPER_LOGE("ViPER4Android disabled, reason [in.FC = %ld, out.FC = %ld]",
newConfig->inputCfg.buffer.frameCount, newConfig->outputCfg.buffer.frameCount); config.inputCfg.buffer.frameCount, config.outputCfg.buffer.frameCount);
setDisableReason(DisableReason::INVALID_FRAME_COUNT, "Input and output frame count mismatch"); setDisableReason(DisableReason::INVALID_FRAME_COUNT, "Input and output frame count mismatch");
return; return;
} }
if (newConfig->inputCfg.samplingRate != newConfig->outputCfg.samplingRate) { if (config.inputCfg.samplingRate != config.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); config.inputCfg.samplingRate, config.outputCfg.samplingRate);
setDisableReason(DisableReason::INVALID_SAMPLING_RATE, "Input and output sampling rate mismatch"); setDisableReason(DisableReason::INVALID_SAMPLING_RATE, "Input and output sampling rate mismatch");
return; return;
} }
// if (newConfig->inputCfg.samplingRate > 48000) { // if (config.inputCfg.samplingRate > 48000) {
// VIPER_LOGE("ViPER4Android disabled, reason [SR out of range]"); // VIPER_LOGE("ViPER4Android disabled, reason [SR out of range]");
// setDisableReason(DisableReason::INVALID_SAMPLING_RATE, "Sampling rate out of range: " + std::to_string(newConfig->inputCfg.samplingRate)); // setDisableReason(DisableReason::INVALID_SAMPLING_RATE, "Sampling rate out of range: " + std::to_string(config.inputCfg.samplingRate));
// return; // return;
// } // }
if (newConfig->inputCfg.channels != newConfig->outputCfg.channels) { if (config.inputCfg.channels != config.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); config.inputCfg.channels, config.outputCfg.channels);
setDisableReason(DisableReason::INVALID_CHANNEL_COUNT, "Input and output channel count mismatch"); setDisableReason(DisableReason::INVALID_CHANNEL_COUNT, "Input and output channel count mismatch");
return; return;
} }
if (newConfig->inputCfg.channels != AUDIO_CHANNEL_OUT_STEREO) { if (config.inputCfg.channels != AUDIO_CHANNEL_OUT_STEREO) {
VIPER_LOGE("ViPER4Android disabled, reason [CH != 2]"); VIPER_LOGE("ViPER4Android disabled, reason [CH != 2]");
setDisableReason(DisableReason::INVALID_CHANNEL_COUNT, "Invalid channel count: " + std::to_string(newConfig->inputCfg.channels)); setDisableReason(DisableReason::INVALID_CHANNEL_COUNT, "Invalid channel count: " + std::to_string(config.inputCfg.channels));
return; return;
} }
if (newConfig->inputCfg.format != AUDIO_FORMAT_PCM_16_BIT && if (config.inputCfg.format != AUDIO_FORMAT_PCM_16_BIT &&
newConfig->inputCfg.format != AUDIO_FORMAT_PCM_32_BIT && config.inputCfg.format != AUDIO_FORMAT_PCM_32_BIT &&
newConfig->inputCfg.format != AUDIO_FORMAT_PCM_FLOAT) { config.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]", 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!"); 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(newConfig->inputCfg.format)); setDisableReason(DisableReason::INVALID_FORMAT, "Invalid input format: " + std::to_string(config.inputCfg.format));
return; return;
} }
if (newConfig->outputCfg.format != AUDIO_FORMAT_PCM_16_BIT && if (config.outputCfg.format != AUDIO_FORMAT_PCM_16_BIT &&
newConfig->outputCfg.format != AUDIO_FORMAT_PCM_32_BIT && config.outputCfg.format != AUDIO_FORMAT_PCM_32_BIT &&
newConfig->outputCfg.format != AUDIO_FORMAT_PCM_FLOAT) { config.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]", 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!"); 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(newConfig->outputCfg.format)); setDisableReason(DisableReason::INVALID_FORMAT, "Invalid output format: " + std::to_string(config.outputCfg.format));
return; return;
} }
VIPER_LOGI("Input and output configuration checked."); VIPER_LOGI("Input and output configuration checked.");
// Config
config = *newConfig;
setDisableReason(DisableReason::NONE); setDisableReason(DisableReason::NONE);
// Processing buffer // Processing buffer
buffer.resize(newConfig->inputCfg.buffer.frameCount * 2); buffer.resize(config.inputCfg.buffer.frameCount * 2);
bufferFrameCount = newConfig->inputCfg.buffer.frameCount; bufferFrameCount = config.inputCfg.buffer.frameCount;
// ViPER // ViPER
viper.samplingRate = newConfig->inputCfg.samplingRate; viper.samplingRate = config.inputCfg.samplingRate;
viper.resetAllEffects(); viper.resetAllEffects();
} }

View File

@ -35,6 +35,7 @@ private:
bool enabled; bool enabled;
ViPER viper; ViPER viper;
static void copyBufferConfig(buffer_config_t *dest, buffer_config_t *src);
void handleSetConfig(effect_config_t *newConfig); void handleSetConfig(effect_config_t *newConfig);
int32_t handleSetParam(effect_param_t *pCmdParam, void *pReplyData); int32_t handleSetParam(effect_param_t *pCmdParam, void *pReplyData);
int32_t handleGetParam(effect_param_t *pCmdParam, effect_param_t *pReplyParam, uint32_t *pReplySize); int32_t handleGetParam(effect_param_t *pCmdParam, effect_param_t *pReplyParam, uint32_t *pReplySize);