Code: Select all

```
#include <emmintrin.h>
void ProcessBlock_new(int voiceIndex, int remainingVoiceSamples)
{
for (int envelopeIndex = 0; envelopeIndex < 10; envelopeIndex++)
{
Envelope &envelope = *pEnvelope[envelopeIndex];
EnvelopeVoiceData &envelopeVoiceData = envelope.mEnvelopeVoicesData[voiceIndex];
// load values to MMX reigsters
const double h = 0.5;
__m128d half = _mm_load1_pd(&h);
__m128d rate = _mm_load1_pd(&envelope.mRate);
__m128d blockstart = _mm_load1_pd(&envelopeVoiceData.mBlockStartAmp);
__m128d blockdelta = _mm_load1_pd(&envelopeVoiceData.mBlockDeltaAmp);
__m128d blockstep = _mm_load1_pd(&envelopeVoiceData.mBlockStep);
// run the loop
if (envelope.mIsBipolar)
{
for (int sample = 0; sample < remainingVoiceSamples; sample++)
{
// value = envelopeVoiceData.mBlockStartAmp + (envelopeVoiceData.mBlockStep * envelopeVoiceData.mBlockDeltaAmp);
__m128d value = _mm_add_pd(blockstart, _mm_mul_pd(blockstep, blockdelta));
// value = (0.5 * value + 0.5);
value = _mm_add_pd(_mm_mul_pd(half, value), half);
// envelope.mValue[voiceIndex] = value;
_mm_storel_pd(&envelope.mValue[voiceIndex], value);
// blockstep += rate;
blockstep = _mm_add_pd(blockstep, rate);
}
// envelopeVoiceData.mBlockStep = blockstep;
_mm_storel_pd(&envelopeVoiceData.mBlockStep, blockstep);
}
else
{
for (int sample = 0; sample < remainingVoiceSamples; sample++)
{
// value = envelopeVoiceData.mBlockStartAmp + (envelopeVoiceData.mBlockStep * envelopeVoiceData.mBlockDeltaAmp);
_mm_storel_pd(&envelope.mValue[voiceIndex], _mm_add_pd(blockstart, _mm_mul_pd(blockstep, blockdelta)));
// blockstep += rate;
blockstep = _mm_add_pd(blockstep, rate);
}
// envelopeVoiceData.mBlockStep = blockstep;
_mm_storel_pd(&envelopeVoiceData.mBlockStep, blockstep);
}
}
}
```

Code: Select all

```
void ProcessBlock_old(int voiceIndex, int remainingVoiceSamples) {
for (int envelopeIndex = 0; envelopeIndex < 10; envelopeIndex++) {
Envelope &envelope = *pEnvelope[envelopeIndex];
EnvelopeVoiceData &envelopeVoiceData = envelope.mEnvelopeVoicesData[voiceIndex];
double bp0 = (1 + envelope.mIsBipolar) * 0.5;
double bp1 = (1 - envelope.mIsBipolar) * 0.5;
// process block
for (int sample = 0; sample < remainingVoiceSamples; sample++) {
// update output value
double value = envelopeVoiceData.mBlockStartAmp + (envelopeVoiceData.mBlockStep * envelopeVoiceData.mBlockDeltaAmp);
envelope.mValue[voiceIndex] = (bp0 * value + bp1);
// next phase
envelopeVoiceData.mBlockStep += envelope.mRate;
}
}
}
```

Code: Select all

```
Start...
NEW: 100000 runs in 1031ms
OLD: 100000 runs in 2188ms
```