Don't check for buffer wrap unless necessary this cycle.
parent
14441af2c4
commit
2a421ff619
|
@ -24,8 +24,9 @@ struct PTap
|
|||
|
||||
Tap tap[TAPS + CHANNELS];
|
||||
|
||||
float *buffers[TAPS]; ///< Tap audio buffers
|
||||
float *wp[TAPS]; ///< Write pointers
|
||||
float *buffers[TAPS]; ///< Tap audio buffers
|
||||
const float *buffers_end[TAPS]; ///< Audio buffer end points
|
||||
float *wp[TAPS]; ///< Write pointers
|
||||
|
||||
float *in_l;
|
||||
float *in_r;
|
||||
|
@ -57,6 +58,7 @@ static LV2_Handle ptap_instantiate(
|
|||
return NULL;
|
||||
}
|
||||
|
||||
ptap->buffers_end[i] = ptap->buffers[i] + ptap->buffer_max;
|
||||
ptap->wp[i] = ptap->buffers[i];
|
||||
}
|
||||
|
||||
|
@ -109,6 +111,7 @@ static void ptap_run(LV2_Handle lv2instance, uint32_t sample_count)
|
|||
|
||||
const float *readp[TAPS + CHANNELS];
|
||||
float gain[TAPS + CHANNELS];
|
||||
bool check_overflow = false;
|
||||
|
||||
/* Position read pointers behind write pointers */
|
||||
for (int i = 0; i < TAPS; i++) {
|
||||
|
@ -119,6 +122,8 @@ static void ptap_run(LV2_Handle lv2instance, uint32_t sample_count)
|
|||
if (readp[i] < ptap->buffers[i]) {
|
||||
readp[i] += ptap->buffer_max;
|
||||
}
|
||||
if (ptap->wp[i] + sample_count >= ptap->buffers_end[i]) check_overflow = true;
|
||||
if (readp[i] + sample_count >= ptap->buffers_end[i]) check_overflow = true;
|
||||
gain[i] = *ptap->tap[i].gain;
|
||||
}
|
||||
|
||||
|
@ -134,35 +139,28 @@ static void ptap_run(LV2_Handle lv2instance, uint32_t sample_count)
|
|||
float rp[TAPS + CHANNELS];
|
||||
float wp[TAPS + CHANNELS];
|
||||
|
||||
for (int i = 0; i < TAPS + CHANNELS; i++) {
|
||||
rp[i] = *readp[i]++;
|
||||
}
|
||||
/* Read input to local buffers */
|
||||
for (int i = 0; i < TAPS + CHANNELS; i++) rp[i] = *readp[i]++;
|
||||
|
||||
/* Process delays */
|
||||
for (int i = 0; i < TAPS + CHANNELS; i++) {
|
||||
const Tap *tap = &ptap->tap[i];
|
||||
|
||||
float sample = 0;
|
||||
for (int j = 0; j < TAPS + CHANNELS; j++) {
|
||||
sample += rp[j] * *tap->t_gain[j];
|
||||
}
|
||||
for (int j = 0; j < TAPS + CHANNELS; j++) sample += rp[j] * *tap->t_gain[j];
|
||||
wp[i] = sample * gain[i];
|
||||
}
|
||||
|
||||
for (int i = 0; i < TAPS; i++) {
|
||||
*ptap->wp[i]++ = wp[i];
|
||||
}
|
||||
|
||||
/* Write outputs */
|
||||
for (int i = 0; i < TAPS; i++) *ptap->wp[i]++ = wp[i];
|
||||
*out_l++ = wp[TAPS];
|
||||
*out_r++ = wp[TAPS + 1];
|
||||
|
||||
/* Progress read pointers */
|
||||
for (int i = 0; i < TAPS; i++) {
|
||||
if (ptap->wp[i] >= ptap->buffers[i] + ptap->buffer_max) {
|
||||
ptap->wp[i] = ptap->buffers[i];
|
||||
}
|
||||
|
||||
if (readp[i] >= ptap->buffers[i] + ptap->buffer_max) {
|
||||
readp[i] = ptap->buffers[i];
|
||||
/* Check read/write pointers */
|
||||
if (check_overflow) {
|
||||
for (int i = 0; i < TAPS; i++) {
|
||||
if (ptap->wp[i] >= ptap->buffers_end[i]) ptap->wp[i] = ptap->buffers[i];
|
||||
if (readp[i] >= ptap->buffers_end[i]) readp[i] = ptap->buffers[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue