diff options
-rw-r--r-- | include/xas/bank.h | 4 | ||||
-rw-r--r-- | src/bank.c | 32 |
2 files changed, 36 insertions, 0 deletions
diff --git a/include/xas/bank.h b/include/xas/bank.h index be623f0..33be492 100644 --- a/include/xas/bank.h +++ b/include/xas/bank.h @@ -42,6 +42,10 @@ ssize_t xas_bank_record(xas_bank *bank, size_t entry_index, size_t count); +ssize_t xas_bank_load_file(xas_bank *bank, + size_t entry_index, + const char *path); + xas_bank_player *xas_bank_player_new(xas_bank *bank); void xas_bank_player_destroy(xas_bank_player *player); @@ -1,6 +1,9 @@ #include <stdlib.h> #include <string.h> +#include <fcntl.h> +#include <errno.h> +#include <xas/riff.h> #include <xas/bank.h> xas_bank *xas_bank_new(xas_audio_format format, @@ -86,6 +89,35 @@ error_invalid_format: return -1; } +ssize_t xas_bank_load_file(xas_bank *bank, + size_t entry_index, + const char *path) { + ssize_t ret; + + xas_audio_stream *riff; + + if ((riff = xas_riff_open_file(path, O_RDONLY)) == NULL) { + goto error_riff_open_file; + } + + if ((ret = xas_bank_record(bank, + riff, + entry_index, + bank->entry_size)) < 0) { + goto error_record; + } + + xas_audio_stream_destroy(riff); + + return ret; + +error_record: + xas_audio_stream_destroy(riff); + +error_riff_open_file: + return -1; +} + xas_bank_player *xas_bank_player_new(xas_bank *bank) { xas_bank_player *player; |