mirror of https://github.com/AxioDL/amuse.git
Cleanups, fixes in effects
This commit is contained in:
parent
4353113649
commit
ae624795be
|
@ -13,43 +13,29 @@ namespace amuse
|
|||
template <typename T>
|
||||
class EffectChorus : public EffectBase<T>
|
||||
{
|
||||
T* x0_lastLeft[AMUSE_CHORUS_NUM_BLOCKS];
|
||||
T* xc_lastRight[AMUSE_CHORUS_NUM_BLOCKS];
|
||||
T* x18_lastRearLeft[AMUSE_CHORUS_NUM_BLOCKS];
|
||||
T* x18_lastRearRight[AMUSE_CHORUS_NUM_BLOCKS];
|
||||
T* x18_lastCenter[AMUSE_CHORUS_NUM_BLOCKS];
|
||||
T* x18_lastLFE[AMUSE_CHORUS_NUM_BLOCKS];
|
||||
T* x18_lastSideLeft[AMUSE_CHORUS_NUM_BLOCKS];
|
||||
T* x18_lastSideRight[AMUSE_CHORUS_NUM_BLOCKS];
|
||||
T* x0_lastChans[8][AMUSE_CHORUS_NUM_BLOCKS]; /**< Evenly-allocated pointer-table for each channel's delay */
|
||||
|
||||
uint8_t x24_currentLast = 1;
|
||||
T x28_oldLeft[4] = {};
|
||||
T x38_oldRight[4] = {};
|
||||
T x48_oldRearLeft[4] = {};
|
||||
T x48_oldRearRight[4] = {};
|
||||
T x48_oldCenter[4] = {};
|
||||
T x48_oldLFE[4] = {};
|
||||
T x48_oldSideLeft[4] = {};
|
||||
T x48_oldSideRight[4] = {};
|
||||
uint8_t x24_currentLast = 1; /**< Last 5ms block-idx to be processed */
|
||||
T x28_oldChans[8][4] = {}; /**< Unprocessed history of previous 4 samples */
|
||||
|
||||
uint32_t x58_currentPosLo = 0;
|
||||
uint32_t x5c_currentPosHi = 0;
|
||||
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 */
|
||||
|
||||
int32_t x60_pitchOffset;
|
||||
uint32_t x64_pitchOffsetPeriodCount;
|
||||
uint32_t x68_pitchOffsetPeriod;
|
||||
int32_t x60_pitchOffset; /**< packed 16.16 fixed-point value of pitchHi and pitchLo quantities */
|
||||
uint32_t x64_pitchOffsetPeriodCount; /**< trigger value for flipping SRC state */
|
||||
uint32_t x68_pitchOffsetPeriod; /**< intermediate block window quantity for calculating SRC state */
|
||||
|
||||
struct SrcInfo
|
||||
{
|
||||
T* x6c_dest;
|
||||
T* x70_smpBase;
|
||||
T* x74_old;
|
||||
uint32_t x78_posLo;
|
||||
uint32_t x7c_posHi;
|
||||
uint32_t x80_pitchLo;
|
||||
uint32_t x84_pitchHi;
|
||||
uint32_t x88_trigger;
|
||||
uint32_t x8c_target = 0;
|
||||
T* x6c_dest; /**< selected channel's live buffer */
|
||||
T* x70_smpBase; /**< selected channel's delay buffer */
|
||||
T* x74_old; /**< selected channel's 4-sample history buffer */
|
||||
uint32_t x78_posLo; /**< 16.7 fixed-point low-part of sample index */
|
||||
uint32_t x7c_posHi; /**< 16.7 fixed-point high-part of sample index */
|
||||
uint32_t x80_pitchLo; /**< 16.7 fixed-point low-part of sample-rate conversion differential */
|
||||
uint32_t x84_pitchHi; /**< 16.7 fixed-point low-part of sample-rate conversion differential */
|
||||
uint32_t x88_trigger; /**< total count of samples per channel across all blocks */
|
||||
uint32_t x8c_target = 0; /**< value to reset to when trigger hit */
|
||||
|
||||
void doSrc1(size_t blockSamples, size_t chanCount);
|
||||
void doSrc2(size_t blockSamples, size_t chanCount);
|
||||
|
@ -59,9 +45,9 @@ class EffectChorus : public EffectBase<T>
|
|||
uint32_t x94_variation; /**< [0, 5] time error (in ms) to set delay within */
|
||||
uint32_t x98_period; /**< [500, 10000] time (in ms) of one delay-shift cycle */
|
||||
|
||||
uint32_t m_sampsPerMs;
|
||||
uint32_t m_blockSamples;
|
||||
bool m_dirty = true;
|
||||
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 */
|
||||
bool m_dirty = true; /**< needs update of internal parameter data */
|
||||
|
||||
void _update();
|
||||
|
||||
|
|
|
@ -12,10 +12,10 @@ namespace amuse
|
|||
template <typename T>
|
||||
class EffectDelay : public EffectBase<T>
|
||||
{
|
||||
uint32_t x0_currentSize[8];
|
||||
uint32_t xc_currentPos[8];
|
||||
uint32_t x18_currentFeedback[8];
|
||||
uint32_t x24_currentOutput[8];
|
||||
uint32_t x0_currentSize[8]; /**< per-channel delay-line buffer sizes */
|
||||
uint32_t xc_currentPos[8]; /**< per-channel block-index */
|
||||
uint32_t x18_currentFeedback[8]; /**< [0, 128] feedback attenuator */
|
||||
uint32_t x24_currentOutput[8]; /**< [0, 128] total attenuator */
|
||||
|
||||
std::unique_ptr<T[]> x30_chanLines[8];
|
||||
|
||||
|
@ -23,9 +23,9 @@ class EffectDelay : public EffectBase<T>
|
|||
uint32_t x48_feedback[8]; /**< [0, 100] percent to mix delayed signal with input signal */
|
||||
uint32_t x54_output[8]; /**< [0, 100] total output percent */
|
||||
|
||||
uint32_t m_sampsPerMs;
|
||||
uint32_t m_blockSamples;
|
||||
bool m_dirty = true;
|
||||
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 */
|
||||
bool m_dirty = true; /**< needs update of internal parameter data */
|
||||
void _update();
|
||||
public:
|
||||
EffectDelay(uint32_t initDelay, uint32_t initFeedback, uint32_t initOutput, double sampleRate);
|
||||
|
|
|
@ -144,36 +144,16 @@ EffectChorus<T>::EffectChorus(uint32_t baseDelay, uint32_t variation,
|
|||
: x90_baseDelay(clamp(5u, baseDelay, 15u)),
|
||||
x94_variation(clamp(0u, variation, 5u)),
|
||||
x98_period(clamp(500u, period, 10000u)),
|
||||
m_sampsPerMs(sampleRate / 1000.0),
|
||||
m_blockSamples(m_sampsPerMs * 160 / 32)
|
||||
m_sampsPerMs(std::ceil(sampleRate / 1000.0)),
|
||||
m_blockSamples(m_sampsPerMs * 5)
|
||||
{
|
||||
T* buf = new T[m_blockSamples * AMUSE_CHORUS_NUM_BLOCKS * 8];
|
||||
memset(buf, 0, m_blockSamples * AMUSE_CHORUS_NUM_BLOCKS * 8 * sizeof(T));
|
||||
size_t chanPitch = m_blockSamples * AMUSE_CHORUS_NUM_BLOCKS;
|
||||
|
||||
for (int i=0 ; i<AMUSE_CHORUS_NUM_BLOCKS ; ++i)
|
||||
x0_lastLeft[i] = buf + m_blockSamples * i;
|
||||
|
||||
for (int i=0 ; i<AMUSE_CHORUS_NUM_BLOCKS ; ++i)
|
||||
xc_lastRight[i] = buf + chanPitch + m_blockSamples * i;
|
||||
|
||||
for (int i=0 ; i<AMUSE_CHORUS_NUM_BLOCKS ; ++i)
|
||||
x18_lastRearLeft[i] = buf + chanPitch * 2 + m_blockSamples * i;
|
||||
|
||||
for (int i=0 ; i<AMUSE_CHORUS_NUM_BLOCKS ; ++i)
|
||||
x18_lastRearRight[i] = buf + chanPitch * 3 + m_blockSamples * i;
|
||||
|
||||
for (int i=0 ; i<AMUSE_CHORUS_NUM_BLOCKS ; ++i)
|
||||
x18_lastCenter[i] = buf + chanPitch * 4 + m_blockSamples * i;
|
||||
|
||||
for (int i=0 ; i<AMUSE_CHORUS_NUM_BLOCKS ; ++i)
|
||||
x18_lastLFE[i] = buf + chanPitch * 5 + m_blockSamples * i;
|
||||
|
||||
for (int i=0 ; i<AMUSE_CHORUS_NUM_BLOCKS ; ++i)
|
||||
x18_lastSideLeft[i] = buf + chanPitch * 6 + m_blockSamples * i;
|
||||
|
||||
for (int i=0 ; i<AMUSE_CHORUS_NUM_BLOCKS ; ++i)
|
||||
x18_lastSideRight[i] = buf + chanPitch * 7 + m_blockSamples * i;
|
||||
for (int c=0 ; c<8 ; ++c)
|
||||
for (int i=0 ; i<AMUSE_CHORUS_NUM_BLOCKS ; ++i)
|
||||
x0_lastChans[c][i] = buf + chanPitch * c + m_blockSamples * i;
|
||||
|
||||
x6c_src.x88_trigger = chanPitch;
|
||||
}
|
||||
|
@ -189,7 +169,7 @@ void EffectChorus<T>::_update()
|
|||
uint32_t temp = (x5c_currentPosHi + (x24_currentLast - 1) * m_blockSamples);
|
||||
x5c_currentPosHi = temp % (chanPitch / fifteenSamps * fifteenSamps);
|
||||
|
||||
x68_pitchOffsetPeriod = (x98_period * 2 / 10 + 1) & ~1;
|
||||
x68_pitchOffsetPeriod = (x98_period / 5 + 1) & ~1;
|
||||
x64_pitchOffsetPeriodCount = x68_pitchOffsetPeriod / 2;
|
||||
x60_pitchOffset = x94_variation * 2048 / x68_pitchOffsetPeriod;
|
||||
|
||||
|
@ -199,7 +179,7 @@ void EffectChorus<T>::_update()
|
|||
template <typename T>
|
||||
EffectChorus<T>::~EffectChorus()
|
||||
{
|
||||
delete[] x0_lastLeft[0];
|
||||
delete[] x0_lastChans[0][0];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
@ -313,52 +293,22 @@ void EffectChorus<T>::applyEffect(T* audio, size_t frameCount, const ChannelMap&
|
|||
{
|
||||
uint8_t next = x24_currentLast + 1;
|
||||
uint8_t buf = next % 3;
|
||||
T* leftBuf = x0_lastLeft[buf];
|
||||
T* rightBuf = xc_lastRight[buf];
|
||||
T* rearLeftBuf = x18_lastRearLeft[buf];
|
||||
T* rearRightBuf = x18_lastRearRight[buf];
|
||||
T* centerBuf = x18_lastCenter[buf];
|
||||
T* lfeBuf = x18_lastLFE[buf];
|
||||
T* sideLeftBuf = x18_lastSideLeft[buf];
|
||||
T* sideRightBuf = x18_lastSideRight[buf];
|
||||
T* bufs[8] =
|
||||
{
|
||||
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],
|
||||
};
|
||||
|
||||
T* inBuf = audio;
|
||||
for (size_t s=0 ; f<frameCount && s<m_blockSamples ; ++s, ++f)
|
||||
{
|
||||
for (size_t c=0 ; c<chanMap.m_channelCount ; ++c)
|
||||
{
|
||||
switch (chanMap.m_channels[c])
|
||||
{
|
||||
case AudioChannel::FrontLeft:
|
||||
*leftBuf++ = *inBuf++;
|
||||
break;
|
||||
case AudioChannel::FrontRight:
|
||||
*rightBuf++ = *inBuf++;
|
||||
break;
|
||||
case AudioChannel::RearLeft:
|
||||
*rearLeftBuf++ = *inBuf++;
|
||||
break;
|
||||
case AudioChannel::RearRight:
|
||||
*rearRightBuf++ = *inBuf++;
|
||||
break;
|
||||
case AudioChannel::FrontCenter:
|
||||
*centerBuf++ = *inBuf++;
|
||||
break;
|
||||
case AudioChannel::LFE:
|
||||
*lfeBuf++ = *inBuf++;
|
||||
break;
|
||||
case AudioChannel::SideLeft:
|
||||
*sideLeftBuf++ = *inBuf++;
|
||||
break;
|
||||
case AudioChannel::SideRight:
|
||||
*sideRightBuf++ = *inBuf++;
|
||||
break;
|
||||
default:
|
||||
inBuf++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (size_t c=0 ; c<chanMap.m_channelCount && c<8 ; ++c)
|
||||
*bufs[c]++ = *inBuf++;
|
||||
|
||||
x6c_src.x84_pitchHi = (x60_pitchOffset >> 16) + 1;
|
||||
x6c_src.x80_pitchLo = (x60_pitchOffset << 16);
|
||||
|
@ -372,48 +322,14 @@ void EffectChorus<T>::applyEffect(T* audio, size_t frameCount, const ChannelMap&
|
|||
|
||||
T* outBuf = audio;
|
||||
size_t bs = std::min(remFrames, size_t(m_blockSamples));
|
||||
for (size_t c=0 ; c<chanMap.m_channelCount ; ++c)
|
||||
for (size_t c=0 ; c<chanMap.m_channelCount && c<8 ; ++c)
|
||||
{
|
||||
x6c_src.x7c_posHi = x5c_currentPosHi;
|
||||
x6c_src.x78_posLo = x58_currentPosLo;
|
||||
|
||||
x6c_src.x6c_dest = outBuf++;
|
||||
switch (chanMap.m_channels[c])
|
||||
{
|
||||
case AudioChannel::FrontLeft:
|
||||
x6c_src.x70_smpBase = x0_lastLeft[0];
|
||||
x6c_src.x74_old = x28_oldLeft;
|
||||
break;
|
||||
case AudioChannel::FrontRight:
|
||||
x6c_src.x70_smpBase = xc_lastRight[0];
|
||||
x6c_src.x74_old = x38_oldRight;
|
||||
break;
|
||||
case AudioChannel::RearLeft:
|
||||
x6c_src.x70_smpBase = x18_lastRearLeft[0];
|
||||
x6c_src.x74_old = x48_oldRearLeft;
|
||||
break;
|
||||
case AudioChannel::RearRight:
|
||||
x6c_src.x70_smpBase = x18_lastRearRight[0];
|
||||
x6c_src.x74_old = x48_oldRearRight;
|
||||
break;
|
||||
case AudioChannel::FrontCenter:
|
||||
x6c_src.x70_smpBase = x18_lastCenter[0];
|
||||
x6c_src.x74_old = x48_oldCenter;
|
||||
break;
|
||||
case AudioChannel::LFE:
|
||||
x6c_src.x70_smpBase = x18_lastLFE[0];
|
||||
x6c_src.x74_old = x48_oldLFE;
|
||||
break;
|
||||
case AudioChannel::SideLeft:
|
||||
x6c_src.x70_smpBase = x18_lastSideLeft[0];
|
||||
x6c_src.x74_old = x48_oldSideLeft;
|
||||
break;
|
||||
case AudioChannel::SideRight:
|
||||
x6c_src.x70_smpBase = x18_lastSideRight[0];
|
||||
x6c_src.x74_old = x48_oldSideRight;
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
x6c_src.x70_smpBase = x0_lastChans[c][0];
|
||||
x6c_src.x74_old = x28_oldChans[c];
|
||||
|
||||
switch (x6c_src.x84_pitchHi)
|
||||
{
|
||||
|
|
|
@ -9,8 +9,8 @@ namespace amuse
|
|||
template <typename T>
|
||||
EffectDelay<T>::EffectDelay(uint32_t initDelay, uint32_t initFeedback,
|
||||
uint32_t initOutput, double sampleRate)
|
||||
: m_sampsPerMs(sampleRate / 1000.0),
|
||||
m_blockSamples(m_sampsPerMs * 160 / 32)
|
||||
: m_sampsPerMs(std::ceil(sampleRate / 1000.0)),
|
||||
m_blockSamples(m_sampsPerMs * 5)
|
||||
{
|
||||
initDelay = clamp(10u, initDelay, 5000u);
|
||||
initFeedback = clamp(0u, initFeedback, 100u);
|
||||
|
@ -50,14 +50,17 @@ void EffectDelay<T>::applyEffect(T* audio, size_t frameCount, const ChannelMap&
|
|||
{
|
||||
for (int c=0 ; c<chanMap.m_channelCount ; ++c)
|
||||
{
|
||||
T* chanAud = audio + c;
|
||||
for (int i=0 ; i<m_blockSamples && f<frameCount ; ++i, ++f)
|
||||
{
|
||||
T& liveSamp = chanAud[chanMap.m_channelCount * i];
|
||||
T& samp = x30_chanLines[c][xc_currentPos[c] * m_blockSamples + i];
|
||||
samp = samp * x18_currentFeedback[c] / 128 + *audio;
|
||||
*audio++ = samp * x24_currentOutput[c] / 128;
|
||||
samp = ClampFull<T>(samp * x18_currentFeedback[c] / 128 + liveSamp);
|
||||
liveSamp = samp * x24_currentOutput[c] / 128;
|
||||
}
|
||||
xc_currentPos = (xc_currentPos[c] + 1) % x0_currentSize[c];
|
||||
}
|
||||
audio += chanMap.m_channelCount * m_blockSamples;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue