From 5f2b64b0c667f754131bce652339f401324d72ca Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Mon, 7 Mar 2022 13:10:03 -0500 Subject: Implement entry_by_index() in src/bank.c Implement entry_by_index() in src/bank.c to provide a single means of obtaining a pointer to a xas_bank_entry object --- src/bank.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/bank.c b/src/bank.c index 20a4569..d2c7de9 100644 --- a/src/bank.c +++ b/src/bank.c @@ -40,11 +40,19 @@ void xas_bank_destroy(xas_bank *bank) { free(bank); } +static inline xas_bank_entry *entry_by_index(xas_bank *bank, + size_t index) { + size_t size = sizeof(xas_bank_entry) + sizeof(int16_t) * bank->entry_size, + offset = size * index; + + return (xas_bank_entry *)(((uint8_t *)(bank + 1)) + offset); +} + ssize_t xas_bank_record(xas_bank *bank, xas_audio_stream *input, size_t entry_index, size_t count) { - xas_bank_entry *entry = &((xas_bank_entry *)(bank + 1))[entry_index]; + xas_bank_entry *entry = entry_by_index(bank, entry_index); size_t left = count, index_o = 0; @@ -217,8 +225,7 @@ static ssize_t stream_fill(xas_bank_player *player, while (left) { if (player->status == XAS_BANK_PLAYER_PLAYING) { - xas_bank_entry *entry = - &((xas_bank_entry *)(bank + 1))[player->entry]; + xas_bank_entry *entry = entry_by_index(bank, player->entry); int16_t *src = (int16_t *)(entry + 1); -- cgit v1.2.3