From 8a197be597ea6ffd1463e417394b14804e5fcc01 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Wed, 23 Feb 2022 20:21:57 -0500 Subject: Implement xas_bank_load_file() Implement xas_bank_load_file() to load a sample from a RIFF file on disk into a sample bank --- src/bank.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src') diff --git a/src/bank.c b/src/bank.c index 9cb276a..1623834 100644 --- a/src/bank.c +++ b/src/bank.c @@ -1,6 +1,9 @@ #include #include +#include +#include +#include #include 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; -- cgit v1.2.3