EffectChorus: Make use of std::array where applicable

Same behavior, but with stronger typing.
This commit is contained in:
Lioncash 2020-03-27 16:36:20 -04:00
parent be754a44a4
commit 5b6d736cfb
2 changed files with 21 additions and 16 deletions

View File

@ -1,9 +1,11 @@
#pragma once #pragma once
#include <array>
#include <cstdint> #include <cstdint>
#include "amuse/Common.hpp" #include "amuse/Common.hpp"
#include "amuse/EffectBase.hpp" #include "amuse/EffectBase.hpp"
#include "amuse/IBackendVoice.hpp"
namespace amuse { namespace amuse {
template <typename T> template <typename T>
@ -68,10 +70,11 @@ public:
/** Type-specific implementation of chorus effect */ /** Type-specific implementation of chorus effect */
template <typename T> template <typename T>
class EffectChorusImp : public EffectBase<T>, public EffectChorus { class EffectChorusImp : public EffectBase<T>, public EffectChorus {
T* x0_lastChans[8][AMUSE_CHORUS_NUM_BLOCKS] = {}; /**< Evenly-allocated pointer-table for each channel's delay */ /** Evenly-allocated pointer-table for each channel's delay */
std::array<std::array<T*, AMUSE_CHORUS_NUM_BLOCKS>, NumChannels> x0_lastChans{};
uint8_t x24_currentLast = 1; /**< Last 5ms block-idx to be processed */ uint8_t x24_currentLast = 1; /**< Last 5ms block-idx to be processed */
T x28_oldChans[8][4] = {}; /**< Unprocessed history of previous 4 samples */ std::array<std::array<T, 4>, NumChannels> x28_oldChans{}; /**< Unprocessed history of previous 4 samples */
uint32_t x58_currentPosLo = 0; /**< 16.7 fixed-point low-part of sample index */ uint32_t x58_currentPosLo = 0; /**< 16.7 fixed-point low-part of sample index */
uint32_t x5c_currentPosHi = 0; /**< 16.7 fixed-point high-part of sample index */ uint32_t x5c_currentPosHi = 0; /**< 16.7 fixed-point high-part of sample index */
@ -93,7 +96,8 @@ class EffectChorusImp : public EffectBase<T>, public EffectChorus {
void doSrc1(size_t blockSamples, size_t chanCount); void doSrc1(size_t blockSamples, size_t chanCount);
void doSrc2(size_t blockSamples, size_t chanCount); void doSrc2(size_t blockSamples, size_t chanCount);
} x6c_src; };
SrcInfo x6c_src;
uint32_t m_sampsPerMs; /**< canonical count of samples per ms for the current backend */ uint32_t m_sampsPerMs; /**< canonical count of samples per ms for the current backend */
uint32_t m_blockSamples; /**< count of samples in a 5ms block */ uint32_t m_blockSamples; /**< count of samples in a 5ms block */

View File

@ -1,7 +1,6 @@
#include "amuse/EffectChorus.hpp" #include "amuse/EffectChorus.hpp"
#include <cmath> #include <cmath>
#include <cstring>
#include "amuse/Common.hpp" #include "amuse/Common.hpp"
#include "amuse/IBackendVoice.hpp" #include "amuse/IBackendVoice.hpp"
@ -9,8 +8,7 @@
namespace amuse { namespace amuse {
/* clang-format off */ /* clang-format off */
static const float rsmpTab12khz[] = constexpr std::array rsmpTab12khz{
{
0.097504f, 0.802216f, 0.101593f, -0.000977f, 0.097504f, 0.802216f, 0.101593f, -0.000977f,
0.093506f, 0.802032f, 0.105804f, -0.001038f, 0.093506f, 0.802032f, 0.105804f, -0.001038f,
0.089600f, 0.801697f, 0.110107f, -0.001160f, 0.089600f, 0.801697f, 0.110107f, -0.001160f,
@ -160,13 +158,14 @@ void EffectChorusImp<T>::_setup(double sampleRate) {
delete[] x0_lastChans[0][0]; delete[] x0_lastChans[0][0];
T* buf = new T[m_blockSamples * AMUSE_CHORUS_NUM_BLOCKS * 8]; const size_t chanPitch = m_blockSamples * AMUSE_CHORUS_NUM_BLOCKS;
memset(buf, 0, m_blockSamples * AMUSE_CHORUS_NUM_BLOCKS * 8 * sizeof(T)); T* buf = new T[chanPitch * NumChannels]();
size_t chanPitch = m_blockSamples * AMUSE_CHORUS_NUM_BLOCKS;
for (int c = 0; c < 8; ++c) for (size_t c = 0; c < NumChannels; ++c) {
for (int i = 0; i < AMUSE_CHORUS_NUM_BLOCKS; ++i) for (size_t i = 0; i < AMUSE_CHORUS_NUM_BLOCKS; ++i) {
x0_lastChans[c][i] = buf + chanPitch * c + m_blockSamples * i; x0_lastChans[c][i] = buf + chanPitch * c + m_blockSamples * i;
}
}
x6c_src.x88_trigger = chanPitch; x6c_src.x88_trigger = chanPitch;
@ -294,15 +293,17 @@ void EffectChorusImp<T>::applyEffect(T* audio, size_t frameCount, const ChannelM
for (size_t f = 0; f < frameCount;) { for (size_t f = 0; f < frameCount;) {
uint8_t next = x24_currentLast + 1; uint8_t next = x24_currentLast + 1;
uint8_t buf = next % 3; uint8_t buf = next % 3;
T* bufs[8] = { std::array<T*, 8> bufs{
x0_lastChans[0][buf], x0_lastChans[1][buf], x0_lastChans[2][buf], x0_lastChans[3][buf], x0_lastChans[0][buf], x0_lastChans[1][buf], x0_lastChans[2][buf], x0_lastChans[3][buf],
x0_lastChans[4][buf], x0_lastChans[5][buf], x0_lastChans[6][buf], x0_lastChans[7][buf], x0_lastChans[4][buf], x0_lastChans[5][buf], x0_lastChans[6][buf], x0_lastChans[7][buf],
}; };
T* inBuf = audio; T* inBuf = audio;
for (size_t s = 0; f < frameCount && s < m_blockSamples; ++s, ++f) for (size_t s = 0; f < frameCount && s < m_blockSamples; ++s, ++f) {
for (size_t c = 0; c < chanMap.m_channelCount && c < 8; ++c) for (size_t c = 0; c < chanMap.m_channelCount && c < NumChannels; ++c) {
*bufs[c]++ = *inBuf++; *bufs[c]++ = *inBuf++;
}
}
x6c_src.x84_pitchHi = (x60_pitchOffset >> 16) + 1; x6c_src.x84_pitchHi = (x60_pitchOffset >> 16) + 1;
x6c_src.x80_pitchLo = (x60_pitchOffset << 16); x6c_src.x80_pitchLo = (x60_pitchOffset << 16);
@ -315,13 +316,13 @@ void EffectChorusImp<T>::applyEffect(T* audio, size_t frameCount, const ChannelM
T* outBuf = audio; T* outBuf = audio;
size_t bs = std::min(remFrames, size_t(m_blockSamples)); size_t bs = std::min(remFrames, size_t(m_blockSamples));
for (size_t c = 0; c < chanMap.m_channelCount && c < 8; ++c) { for (size_t c = 0; c < chanMap.m_channelCount && c < NumChannels; ++c) {
x6c_src.x7c_posHi = x5c_currentPosHi; x6c_src.x7c_posHi = x5c_currentPosHi;
x6c_src.x78_posLo = x58_currentPosLo; x6c_src.x78_posLo = x58_currentPosLo;
x6c_src.x6c_dest = outBuf++; x6c_src.x6c_dest = outBuf++;
x6c_src.x70_smpBase = x0_lastChans[c][0]; x6c_src.x70_smpBase = x0_lastChans[c][0];
x6c_src.x74_old = x28_oldChans[c]; x6c_src.x74_old = x28_oldChans[c].data();
switch (x6c_src.x84_pitchHi) { switch (x6c_src.x84_pitchHi) {
case 0: case 0: