diff options
author | XANTRONIX Development | 2022-03-07 13:10:03 -0500 |
---|---|---|
committer | XANTRONIX Development | 2022-03-07 13:10:03 -0500 |
commit | 5f2b64b0c667f754131bce652339f401324d72ca (patch) | |
tree | 52717d596cca11cbc2d0968bca1bb6fbd23fa7d3 | |
parent | 1689abc83e9a23c44d25b68f991ee776ee746ef0 (diff) | |
download | xas-5f2b64b0c667f754131bce652339f401324d72ca.tar.gz xas-5f2b64b0c667f754131bce652339f401324d72ca.tar.bz2 xas-5f2b64b0c667f754131bce652339f401324d72ca.zip |
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
-rw-r--r-- | src/bank.c | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -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); |