Skip to content

Commit 9fbb39d

Browse files
committed
Improve index incrementing.
1 parent ec428b7 commit 9fbb39d

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

shared-module/audiodelays/PitchShift.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -313,20 +313,22 @@ audioio_get_buffer_result_t audiodelays_pitch_shift_get_buffer(audiodelays_pitch
313313
hword_buffer[i] = (uint8_t)mixed ^ 0x80;
314314
}
315315
}
316+
317+
if (self->base.channel_count == 1 || buf_offset) {
318+
// Increment window buffer write pointer
319+
self->window_index++;
320+
if (self->window_index >= window_size) self->window_index = 0;
321+
322+
// Increment overlap buffer pointer
323+
if (overlap_size) {
324+
self->overlap_index++;
325+
if (self->overlap_index >= overlap_size) self->overlap_index = 0;
326+
}
316327

317-
// Increment window buffer write pointer
318-
self->window_index++;
319-
if (self->window_index >= window_size) self->window_index = 0;
320-
321-
// Increment overlap buffer pointer
322-
if (self->overlap_len) {
323-
self->overlap_index++;
324-
if (self->overlap_index >= overlap_size) self->overlap_index = 0;
328+
// Increment window buffer read pointer by rate
329+
self->read_index += self->read_rate;
330+
if (self->read_index >= window_size << PITCH_READ_SHIFT) self->read_index -= window_size << PITCH_READ_SHIFT;
325331
}
326-
327-
// Increment window buffer read pointer by rate
328-
self->read_index += self->read_rate;
329-
if (self->read_index >= window_size << PITCH_READ_SHIFT) self->read_index -= window_size << PITCH_READ_SHIFT;
330332
}
331333

332334
// Update the remaining length and the buffer positions based on how much we wrote into our buffer

0 commit comments

Comments
 (0)