Loading media/libeffects/lvm/tests/reverb_test.cpp +6 −17 Original line number Diff line number Diff line Loading @@ -312,9 +312,6 @@ int main(int argc, const char* argv[]) { config.inputCfg.samplingRate = config.outputCfg.samplingRate = revConfigParams.sampleRate; config.inputCfg.channels = config.outputCfg.channels = revConfigParams.chMask; config.inputCfg.format = config.outputCfg.format = AUDIO_FORMAT_PCM_FLOAT; if (AUDIO_CHANNEL_OUT_MONO == revConfigParams.chMask) { config.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO; } if (int status = reverbCreateEffect(&effectHandle, &config, sessionId, ioId, revConfigParams.auxiliary); status != 0) { Loading Loading @@ -346,19 +343,11 @@ int main(int argc, const char* argv[]) { const int ioChannelCount = revConfigParams.fChannels; const int ioFrameSize = ioChannelCount * sizeof(short); const int maxChannelCount = std::max(channelCount, ioChannelCount); /* * Mono input will be converted to 2 channels internally in the process call * by copying the same data into the second channel. * Hence when channelCount is 1, output buffer should be allocated for * 2 channels. The outChannelCount takes care of allocation of sufficient * memory for the output buffer. */ const int outChannelCount = (channelCount == 1 ? 2 : channelCount); std::vector<short> in(frameLength * maxChannelCount); std::vector<short> out(frameLength * outChannelCount); std::vector<short> out(frameLength * maxChannelCount); std::vector<float> floatIn(frameLength * channelCount); std::vector<float> floatOut(frameLength * outChannelCount); std::vector<float> floatOut(frameLength * channelCount); int frameCounter = 0; Loading Loading @@ -392,11 +381,11 @@ int main(int argc, const char* argv[]) { #else memcpy(floatOut.data(), floatIn.data(), frameLength * frameSize); #endif memcpy_to_i16_from_float(out.data(), floatOut.data(), frameLength * outChannelCount); memcpy_to_i16_from_float(out.data(), floatOut.data(), frameLength * channelCount); if (ioChannelCount != outChannelCount) { adjust_channels(out.data(), outChannelCount, out.data(), ioChannelCount, sizeof(short), frameLength * outChannelCount * sizeof(short)); if (ioChannelCount != channelCount) { adjust_channels(out.data(), channelCount, out.data(), ioChannelCount, sizeof(short), frameLength * channelCount * sizeof(short)); } (void)fwrite(out.data(), ioFrameSize, frameLength, outputFp.get()); frameCounter += frameLength; Loading media/libeffects/lvm/wrapper/Reverb/EffectReverb.cpp +30 −12 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ typedef float LVM_FLOAT; #include "EffectReverb.h" // from Reverb/lib #include "LVREV.h" #include "VectorArithmetic.h" // effect_handle_t interface implementation for reverb extern "C" const struct effect_interface_s gReverbInterface; Loading Loading @@ -332,6 +333,7 @@ extern "C" int EffectGetDescriptor(const effect_uuid_t* uuid, effect_descriptor_ //---------------------------------------------------------------------------- int process(effect_buffer_t* pIn, effect_buffer_t* pOut, int frameCount, ReverbContext* pContext) { int channels = audio_channel_count_from_out_mask(pContext->config.inputCfg.channels); int outChannels = audio_channel_count_from_out_mask(pContext->config.outputCfg.channels); LVREV_ReturnStatus_en LvmStatus = LVREV_SUCCESS; /* Function call status */ // Reverb only effects the stereo channels in multichannel source. Loading Loading @@ -454,33 +456,49 @@ int process(effect_buffer_t* pIn, effect_buffer_t* pOut, int frameCount, ReverbC } } if (channels > 2) { if (outChannels > 2) { // Accumulate if required if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE) { for (int i = 0; i < frameCount; i++) { pOut[channels * i] += pContext->OutFrames[FCC_2 * i]; pOut[channels * i + 1] += pContext->OutFrames[FCC_2 * i + 1]; pOut[outChannels * i] += pContext->OutFrames[FCC_2 * i]; pOut[outChannels * i + 1] += pContext->OutFrames[FCC_2 * i + 1]; } } else { for (int i = 0; i < frameCount; i++) { pOut[channels * i] = pContext->OutFrames[FCC_2 * i]; pOut[channels * i + 1] = pContext->OutFrames[FCC_2 * i + 1]; pOut[outChannels * i] = pContext->OutFrames[FCC_2 * i]; pOut[outChannels * i + 1] = pContext->OutFrames[FCC_2 * i + 1]; } } if (!pContext->auxiliary) { for (int i = 0; i < frameCount; i++) { for (int j = FCC_2; j < channels; j++) { pOut[channels * i + j] = pIn[channels * i + j]; // channels and outChannels are expected to be same. for (int j = FCC_2; j < outChannels; j++) { pOut[outChannels * i + j] = pIn[outChannels * i + j]; } } } } else { if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE) { if (outChannels == FCC_1) { for (int i = 0; i < frameCount; i++) { pOut[i] += ((pContext->OutFrames[i * FCC_2] + pContext->OutFrames[i * FCC_2 + 1]) * 0.5f); } } else { for (int i = 0; i < frameCount * FCC_2; i++) { pOut[i] += pContext->OutFrames[i]; } } } else { if (outChannels == FCC_1) { From2iToMono_Float((const process_buffer_t*)pContext->OutFrames, pOut, frameCount); } else { memcpy(pOut, pContext->OutFrames, frameCount * sizeof(*pOut) * FCC_2); } } } return 0; } /* end process */ Loading Loading @@ -549,7 +567,7 @@ int Reverb_setConfig(ReverbContext* pContext, effect_config_t* pConfig) { CHECK_ARG((pContext->auxiliary && pConfig->inputCfg.channels == AUDIO_CHANNEL_OUT_MONO) || ((!pContext->auxiliary) && (inputChannels <= LVM_MAX_CHANNELS))); int outputChannels = audio_channel_count_from_out_mask(pConfig->outputCfg.channels); CHECK_ARG(outputChannels >= FCC_2 && outputChannels <= LVM_MAX_CHANNELS); CHECK_ARG(outputChannels <= LVM_MAX_CHANNELS); CHECK_ARG(pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_WRITE || pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE); CHECK_ARG(pConfig->inputCfg.format == EFFECT_BUFFER_FORMAT); Loading Loading
media/libeffects/lvm/tests/reverb_test.cpp +6 −17 Original line number Diff line number Diff line Loading @@ -312,9 +312,6 @@ int main(int argc, const char* argv[]) { config.inputCfg.samplingRate = config.outputCfg.samplingRate = revConfigParams.sampleRate; config.inputCfg.channels = config.outputCfg.channels = revConfigParams.chMask; config.inputCfg.format = config.outputCfg.format = AUDIO_FORMAT_PCM_FLOAT; if (AUDIO_CHANNEL_OUT_MONO == revConfigParams.chMask) { config.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO; } if (int status = reverbCreateEffect(&effectHandle, &config, sessionId, ioId, revConfigParams.auxiliary); status != 0) { Loading Loading @@ -346,19 +343,11 @@ int main(int argc, const char* argv[]) { const int ioChannelCount = revConfigParams.fChannels; const int ioFrameSize = ioChannelCount * sizeof(short); const int maxChannelCount = std::max(channelCount, ioChannelCount); /* * Mono input will be converted to 2 channels internally in the process call * by copying the same data into the second channel. * Hence when channelCount is 1, output buffer should be allocated for * 2 channels. The outChannelCount takes care of allocation of sufficient * memory for the output buffer. */ const int outChannelCount = (channelCount == 1 ? 2 : channelCount); std::vector<short> in(frameLength * maxChannelCount); std::vector<short> out(frameLength * outChannelCount); std::vector<short> out(frameLength * maxChannelCount); std::vector<float> floatIn(frameLength * channelCount); std::vector<float> floatOut(frameLength * outChannelCount); std::vector<float> floatOut(frameLength * channelCount); int frameCounter = 0; Loading Loading @@ -392,11 +381,11 @@ int main(int argc, const char* argv[]) { #else memcpy(floatOut.data(), floatIn.data(), frameLength * frameSize); #endif memcpy_to_i16_from_float(out.data(), floatOut.data(), frameLength * outChannelCount); memcpy_to_i16_from_float(out.data(), floatOut.data(), frameLength * channelCount); if (ioChannelCount != outChannelCount) { adjust_channels(out.data(), outChannelCount, out.data(), ioChannelCount, sizeof(short), frameLength * outChannelCount * sizeof(short)); if (ioChannelCount != channelCount) { adjust_channels(out.data(), channelCount, out.data(), ioChannelCount, sizeof(short), frameLength * channelCount * sizeof(short)); } (void)fwrite(out.data(), ioFrameSize, frameLength, outputFp.get()); frameCounter += frameLength; Loading
media/libeffects/lvm/wrapper/Reverb/EffectReverb.cpp +30 −12 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ typedef float LVM_FLOAT; #include "EffectReverb.h" // from Reverb/lib #include "LVREV.h" #include "VectorArithmetic.h" // effect_handle_t interface implementation for reverb extern "C" const struct effect_interface_s gReverbInterface; Loading Loading @@ -332,6 +333,7 @@ extern "C" int EffectGetDescriptor(const effect_uuid_t* uuid, effect_descriptor_ //---------------------------------------------------------------------------- int process(effect_buffer_t* pIn, effect_buffer_t* pOut, int frameCount, ReverbContext* pContext) { int channels = audio_channel_count_from_out_mask(pContext->config.inputCfg.channels); int outChannels = audio_channel_count_from_out_mask(pContext->config.outputCfg.channels); LVREV_ReturnStatus_en LvmStatus = LVREV_SUCCESS; /* Function call status */ // Reverb only effects the stereo channels in multichannel source. Loading Loading @@ -454,33 +456,49 @@ int process(effect_buffer_t* pIn, effect_buffer_t* pOut, int frameCount, ReverbC } } if (channels > 2) { if (outChannels > 2) { // Accumulate if required if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE) { for (int i = 0; i < frameCount; i++) { pOut[channels * i] += pContext->OutFrames[FCC_2 * i]; pOut[channels * i + 1] += pContext->OutFrames[FCC_2 * i + 1]; pOut[outChannels * i] += pContext->OutFrames[FCC_2 * i]; pOut[outChannels * i + 1] += pContext->OutFrames[FCC_2 * i + 1]; } } else { for (int i = 0; i < frameCount; i++) { pOut[channels * i] = pContext->OutFrames[FCC_2 * i]; pOut[channels * i + 1] = pContext->OutFrames[FCC_2 * i + 1]; pOut[outChannels * i] = pContext->OutFrames[FCC_2 * i]; pOut[outChannels * i + 1] = pContext->OutFrames[FCC_2 * i + 1]; } } if (!pContext->auxiliary) { for (int i = 0; i < frameCount; i++) { for (int j = FCC_2; j < channels; j++) { pOut[channels * i + j] = pIn[channels * i + j]; // channels and outChannels are expected to be same. for (int j = FCC_2; j < outChannels; j++) { pOut[outChannels * i + j] = pIn[outChannels * i + j]; } } } } else { if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE) { if (outChannels == FCC_1) { for (int i = 0; i < frameCount; i++) { pOut[i] += ((pContext->OutFrames[i * FCC_2] + pContext->OutFrames[i * FCC_2 + 1]) * 0.5f); } } else { for (int i = 0; i < frameCount * FCC_2; i++) { pOut[i] += pContext->OutFrames[i]; } } } else { if (outChannels == FCC_1) { From2iToMono_Float((const process_buffer_t*)pContext->OutFrames, pOut, frameCount); } else { memcpy(pOut, pContext->OutFrames, frameCount * sizeof(*pOut) * FCC_2); } } } return 0; } /* end process */ Loading Loading @@ -549,7 +567,7 @@ int Reverb_setConfig(ReverbContext* pContext, effect_config_t* pConfig) { CHECK_ARG((pContext->auxiliary && pConfig->inputCfg.channels == AUDIO_CHANNEL_OUT_MONO) || ((!pContext->auxiliary) && (inputChannels <= LVM_MAX_CHANNELS))); int outputChannels = audio_channel_count_from_out_mask(pConfig->outputCfg.channels); CHECK_ARG(outputChannels >= FCC_2 && outputChannels <= LVM_MAX_CHANNELS); CHECK_ARG(outputChannels <= LVM_MAX_CHANNELS); CHECK_ARG(pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_WRITE || pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE); CHECK_ARG(pConfig->inputCfg.format == EFFECT_BUFFER_FORMAT); Loading