Assume 128 buffer size for ildaeil and host audio peaks

Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
falkTX 2022-11-26 00:17:57 +00:00
parent d02a5c6796
commit cd99938fa8
No known key found for this signature in database
GPG key ID: CDBAA37ABC74FBA0
3 changed files with 14 additions and 24 deletions

View file

@ -127,20 +127,13 @@ struct HostAudio2 : HostAudio<2> {
#ifndef HEADLESS #ifndef HEADLESS
// for stereo meter // for stereo meter
uint32_t internalDataFrame = 0; uint32_t internalDataFrame = 0;
float internalDataBuffer[2][128]; float internalDataBufferL[128] = {};
float internalDataBufferR[128] = {};
volatile bool resetMeters = true; volatile bool resetMeters = true;
float gainMeterL = 0.0f; float gainMeterL = 0.0f;
float gainMeterR = 0.0f; float gainMeterR = 0.0f;
#endif #endif
HostAudio2()
: HostAudio<2>()
{
#ifndef HEADLESS
std::memset(internalDataBuffer, 0, sizeof(internalDataBuffer));
#endif
}
#ifndef HEADLESS #ifndef HEADLESS
void onReset() override void onReset() override
{ {
@ -230,8 +223,8 @@ struct HostAudio2 : HostAudio<2> {
} }
const uint32_t j = internalDataFrame++; const uint32_t j = internalDataFrame++;
internalDataBuffer[0][j] = valueL; internalDataBufferL[j] = valueL;
internalDataBuffer[1][j] = valueR; internalDataBufferR[j] = valueR;
if (internalDataFrame == 128) if (internalDataFrame == 128)
{ {
@ -240,10 +233,10 @@ struct HostAudio2 : HostAudio<2> {
if (resetMeters) if (resetMeters)
gainMeterL = gainMeterR = 0.0f; gainMeterL = gainMeterR = 0.0f;
gainMeterL = std::max(gainMeterL, d_findMaxNormalizedFloat(internalDataBuffer[0], 128)); gainMeterL = std::max(gainMeterL, d_findMaxNormalizedFloat128(internalDataBufferL));
if (in2connected) if (in2connected)
gainMeterR = std::max(gainMeterR, d_findMaxNormalizedFloat(internalDataBuffer[1], 128)); gainMeterR = std::max(gainMeterR, d_findMaxNormalizedFloat128(internalDataBufferR));
else else
gainMeterR = gainMeterL; gainMeterR = gainMeterL;

View file

@ -488,16 +488,16 @@ struct IldaeilModule : Module {
if (resetMeterIn) if (resetMeterIn)
meterInL = meterInR = 0.0f; meterInL = meterInR = 0.0f;
meterInL = std::max(meterInL, d_findMaxNormalizedFloat(audioDataIn1, BUFFER_SIZE)); meterInL = std::max(meterInL, d_findMaxNormalizedFloat128(audioDataIn1));
meterInR = std::max(meterInR, d_findMaxNormalizedFloat(audioDataIn2, BUFFER_SIZE)); meterInR = std::max(meterInR, d_findMaxNormalizedFloat128(audioDataIn2));
fCarlaPluginDescriptor->process(fCarlaPluginHandle, ins, outs, BUFFER_SIZE, midiEvents, midiEventCount); fCarlaPluginDescriptor->process(fCarlaPluginHandle, ins, outs, BUFFER_SIZE, midiEvents, midiEventCount);
if (resetMeterOut) if (resetMeterOut)
meterOutL = meterOutR = 0.0f; meterOutL = meterOutR = 0.0f;
meterOutL = std::max(meterOutL, d_findMaxNormalizedFloat(audioDataOut1, BUFFER_SIZE)); meterOutL = std::max(meterOutL, d_findMaxNormalizedFloat128(audioDataOut1));
meterOutR = std::max(meterOutR, d_findMaxNormalizedFloat(audioDataOut2, BUFFER_SIZE)); meterOutR = std::max(meterOutR, d_findMaxNormalizedFloat128(audioDataOut2));
resetMeterIn = resetMeterOut = false; resetMeterIn = resetMeterOut = false;
} }

View file

@ -56,19 +56,16 @@ extern std::vector<Model*> hostTerminalModels;
* Find the highest absolute and normalized value within a float array. * Find the highest absolute and normalized value within a float array.
*/ */
static inline static inline
float d_findMaxNormalizedFloat(const float floats[], const std::size_t count) float d_findMaxNormalizedFloat128(const float floats[128])
{ {
DISTRHO_SAFE_ASSERT_RETURN(floats != nullptr, 0.0f); static constexpr const float kEmptyFloats[128] = {};
DISTRHO_SAFE_ASSERT_RETURN(count > 0, 0.0f);
static constexpr const float kEmptyFloats[8192] = {}; if (std::memcmp(floats, kEmptyFloats, sizeof(float)*128) == 0)
if (count <= 8192 && std::memcmp(floats, kEmptyFloats, count) == 0)
return 0.0f; return 0.0f;
float tmp, maxf2 = std::abs(floats[0]); float tmp, maxf2 = std::abs(floats[0]);
for (std::size_t i=1; i<count; ++i) for (std::size_t i=1; i<128; ++i)
{ {
if (!std::isfinite(floats[i])) if (!std::isfinite(floats[i]))
__builtin_unreachable(); __builtin_unreachable();