mixer: factor out mix_one_voice
This commit is contained in:
parent
8b61333937
commit
e6869c8983
@ -295,39 +295,12 @@ static inline uint32_t mult16signed(uint32_t val, int32_t mul) {
|
||||
#endif
|
||||
}
|
||||
|
||||
audioio_get_buffer_result_t audiomixer_mixer_get_buffer(audiomixer_mixer_obj_t* self,
|
||||
bool single_channel,
|
||||
uint8_t channel,
|
||||
uint8_t** buffer,
|
||||
uint32_t* buffer_length) {
|
||||
if (!single_channel) {
|
||||
channel = 0;
|
||||
}
|
||||
|
||||
uint32_t channel_read_count = self->left_read_count;
|
||||
if (channel == 1) {
|
||||
channel_read_count = self->right_read_count;
|
||||
}
|
||||
*buffer_length = self->len;
|
||||
|
||||
bool need_more_data = self->read_count == channel_read_count;
|
||||
if (need_more_data) {
|
||||
uint32_t* word_buffer;
|
||||
if (self->use_first_buffer) {
|
||||
*buffer = (uint8_t*) self->first_buffer;
|
||||
word_buffer = self->first_buffer;
|
||||
} else {
|
||||
*buffer = (uint8_t*) self->second_buffer;
|
||||
word_buffer = self->second_buffer;
|
||||
}
|
||||
self->use_first_buffer = !self->use_first_buffer;
|
||||
bool voices_active = false;
|
||||
for (int32_t v = 0; v < self->voice_count; v++) {
|
||||
audiomixer_mixervoice_obj_t* voice = MP_OBJ_TO_PTR(self->voice[v]);
|
||||
|
||||
static void mix_one_voice(audiomixer_mixer_obj_t* self,
|
||||
audiomixer_mixervoice_obj_t* voice, bool voices_active,
|
||||
uint32_t* word_buffer, uint32_t length) {
|
||||
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 < length; i++) {
|
||||
if (!voice_done && j >= voice->buffer_length) {
|
||||
if (!voice->more_data) {
|
||||
if (voice->loop) {
|
||||
@ -401,7 +374,39 @@ audioio_get_buffer_result_t audiomixer_mixer_get_buffer(audiomixer_mixer_obj_t*
|
||||
}
|
||||
voice->buffer_length -= j;
|
||||
voice->remaining_buffer += j;
|
||||
}
|
||||
|
||||
audioio_get_buffer_result_t audiomixer_mixer_get_buffer(audiomixer_mixer_obj_t* self,
|
||||
bool single_channel,
|
||||
uint8_t channel,
|
||||
uint8_t** buffer,
|
||||
uint32_t* buffer_length) {
|
||||
if (!single_channel) {
|
||||
channel = 0;
|
||||
}
|
||||
|
||||
uint32_t channel_read_count = self->left_read_count;
|
||||
if (channel == 1) {
|
||||
channel_read_count = self->right_read_count;
|
||||
}
|
||||
*buffer_length = self->len;
|
||||
|
||||
bool need_more_data = self->read_count == channel_read_count;
|
||||
if (need_more_data) {
|
||||
uint32_t* word_buffer;
|
||||
if (self->use_first_buffer) {
|
||||
*buffer = (uint8_t*) self->first_buffer;
|
||||
word_buffer = self->first_buffer;
|
||||
} else {
|
||||
*buffer = (uint8_t*) self->second_buffer;
|
||||
word_buffer = self->second_buffer;
|
||||
}
|
||||
self->use_first_buffer = !self->use_first_buffer;
|
||||
bool voices_active = false;
|
||||
for (int32_t v = 0; v < self->voice_count; v++) {
|
||||
audiomixer_mixervoice_obj_t* voice = MP_OBJ_TO_PTR(self->voice[v]);
|
||||
|
||||
mix_one_voice(self, voice, voices_active, word_buffer, self->len / sizeof(uint32_t));
|
||||
voices_active = true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user