Fix voice ending in the middle of a buffer.
This commit is contained in:
parent
2ec7f98c90
commit
8587d8edf0
@ -244,21 +244,20 @@ audioio_get_buffer_result_t audioio_mixer_get_buffer(audioio_mixer_obj_t* self,
|
|||||||
bool voices_active = false;
|
bool voices_active = false;
|
||||||
for (int32_t v = 0; v < self->voice_count; v++) {
|
for (int32_t v = 0; v < self->voice_count; v++) {
|
||||||
audioio_mixer_voice_t* voice = &self->voice[v];
|
audioio_mixer_voice_t* voice = &self->voice[v];
|
||||||
if (voice->sample == NULL) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t j = 0;
|
uint32_t j = 0;
|
||||||
|
bool voice_done = voice->sample == NULL;
|
||||||
for (uint32_t i = 0; i < self->len / sizeof(uint32_t); i++) {
|
for (uint32_t i = 0; i < self->len / sizeof(uint32_t); i++) {
|
||||||
if (j >= voice->buffer_length) {
|
if (!voice_done && j >= voice->buffer_length) {
|
||||||
if (!voice->more_data) {
|
if (!voice->more_data) {
|
||||||
if (voice->loop) {
|
if (voice->loop) {
|
||||||
audiosample_reset_buffer(voice->sample, false, 0);
|
audiosample_reset_buffer(voice->sample, false, 0);
|
||||||
} else {
|
} else {
|
||||||
voice->sample = NULL;
|
voice->sample = NULL;
|
||||||
break;
|
voice_done = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!voice_done) {
|
||||||
// Load another buffer
|
// Load another buffer
|
||||||
audioio_get_buffer_result_t result = audiosample_get_buffer(voice->sample, false, 0, (uint8_t**) &voice->remaining_buffer, &voice->buffer_length);
|
audioio_get_buffer_result_t result = audiosample_get_buffer(voice->sample, false, 0, (uint8_t**) &voice->remaining_buffer, &voice->buffer_length);
|
||||||
// Track length in terms of words.
|
// Track length in terms of words.
|
||||||
@ -266,8 +265,26 @@ audioio_get_buffer_result_t audioio_mixer_get_buffer(audioio_mixer_obj_t* self,
|
|||||||
voice->more_data = result == GET_BUFFER_MORE_DATA;
|
voice->more_data = result == GET_BUFFER_MORE_DATA;
|
||||||
j = 0;
|
j = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// First active voice gets copied over verbatim.
|
// First active voice gets copied over verbatim.
|
||||||
uint32_t sample_value = voice->remaining_buffer[j];
|
uint32_t sample_value;
|
||||||
|
if (voice_done) {
|
||||||
|
// Exit early if another voice already set all samples once.
|
||||||
|
if (voices_active) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
sample_value = 0;
|
||||||
|
if (!self->samples_signed) {
|
||||||
|
if (self->bits_per_sample == 8) {
|
||||||
|
sample_value = 0x7f7f7f7f;
|
||||||
|
} else {
|
||||||
|
sample_value = 0x7fff7fff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sample_value = voice->remaining_buffer[j];
|
||||||
|
}
|
||||||
|
|
||||||
if (!voices_active) {
|
if (!voices_active) {
|
||||||
word_buffer[i] = sample_value;
|
word_buffer[i] = sample_value;
|
||||||
} else {
|
} else {
|
||||||
@ -293,20 +310,6 @@ audioio_get_buffer_result_t audioio_mixer_get_buffer(audioio_mixer_obj_t* self,
|
|||||||
voices_active = true;
|
voices_active = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// No voice is active so zero out the signal.
|
|
||||||
if (!voices_active) {
|
|
||||||
uint32_t zero = 0;
|
|
||||||
if (!self->samples_signed) {
|
|
||||||
if (self->bits_per_sample == 8) {
|
|
||||||
zero = 0x7f7f7f7f;
|
|
||||||
} else {
|
|
||||||
zero = 0x7fff7fff;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (uint32_t i = 0; i < self->len / sizeof(uint32_t); i++) {
|
|
||||||
word_buffer[i] = zero;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self->read_count += 1;
|
self->read_count += 1;
|
||||||
} else if (!self->use_first_buffer) {
|
} else if (!self->use_first_buffer) {
|
||||||
*buffer = (uint8_t*) self->first_buffer;
|
*buffer = (uint8_t*) self->first_buffer;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user