From 52b99333c5e8cf3b757cd6e88fca13d420b54979 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Wed, 23 Feb 2022 00:21:38 -0500 Subject: Implement xas_bank_player type Changes: * Implement xas_bank_player type to decouple player state from sample storage, to allow multiple concurrent players against a single sample bank * Refactor examples/say.c to use xas_bank_player --- include/xas/bank.h | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'include') diff --git a/include/xas/bank.h b/include/xas/bank.h index 9f877d0..be623f0 100644 --- a/include/xas/bank.h +++ b/include/xas/bank.h @@ -5,8 +5,10 @@ #include -#define XAS_BANK_IDLE 0 -#define XAS_BANK_ACTIVE (1 << 0) +enum xas_bank_player_status { + XAS_BANK_PLAYER_STOPPED, + XAS_BANK_PLAYER_PLAYING, +}; typedef struct _xas_bank_entry { size_t duration; @@ -17,13 +19,17 @@ typedef struct _xas_bank { size_t entry_size, entry_count; +} xas_bank; + +typedef struct _xas_bank_player { + xas_bank *bank; + enum xas_bank_player_status status; - int flags; float gain; size_t entry, index; -} xas_bank; +} xas_bank_player; xas_bank *xas_bank_new(xas_audio_format format, size_t entry_size, @@ -31,17 +37,23 @@ xas_bank *xas_bank_new(xas_audio_format format, void xas_bank_destroy(xas_bank *bank); -int xas_bank_play(xas_bank *bank, size_t entry, float gain); - -void xas_bank_stop(xas_bank *bank); - -int xas_bank_active(xas_bank *bank); - ssize_t xas_bank_record(xas_bank *bank, xas_audio_stream *input, size_t entry_index, size_t count); -xas_audio_stream *xas_bank_stream_new(xas_bank *bank); +xas_bank_player *xas_bank_player_new(xas_bank *bank); + +void xas_bank_player_destroy(xas_bank_player *player); + +int xas_bank_player_start(xas_bank_player *player, + size_t entry, + float gain); + +int xas_bank_player_stop(xas_bank_player *player); + +int xas_bank_player_playing(xas_bank_player *player); + +xas_audio_stream *xas_bank_player_stream_new(xas_bank_player *player); #endif /* _XAS_BANK_H */ -- cgit v1.2.3